From 1e8597dc1bbd26a4fdf654eae28422a4f4195d91 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 8 Mar 2015 17:42:02 -0700 Subject: [PATCH] Add TM Randomizer --- pk3DS/Subforms/TMHM.Designer.cs | 13 +++++++++++++ pk3DS/Subforms/TMHM.cs | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pk3DS/Subforms/TMHM.Designer.cs b/pk3DS/Subforms/TMHM.Designer.cs index 4dc5431..f570ab0 100644 --- a/pk3DS/Subforms/TMHM.Designer.cs +++ b/pk3DS/Subforms/TMHM.Designer.cs @@ -32,6 +32,7 @@ private void InitializeComponent() this.L_TM = new System.Windows.Forms.Label(); this.dgvHM = new System.Windows.Forms.DataGridView(); this.L_HM = new System.Windows.Forms.Label(); + this.B_RTM = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dgvTM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvHM)).BeginInit(); this.SuspendLayout(); @@ -82,11 +83,22 @@ private void InitializeComponent() this.L_HM.TabIndex = 4; this.L_HM.Text = "HM:"; // + // B_RTM + // + this.B_RTM.Location = new System.Drawing.Point(41, 1); + this.B_RTM.Name = "B_RTM"; + this.B_RTM.Size = new System.Drawing.Size(75, 23); + this.B_RTM.TabIndex = 5; + this.B_RTM.Text = "Randomize"; + this.B_RTM.UseVisualStyleBackColor = true; + this.B_RTM.Click += new System.EventHandler(this.B_RandomTM_Click); + // // TMHM // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(504, 332); + this.Controls.Add(this.B_RTM); this.Controls.Add(this.L_HM); this.Controls.Add(this.dgvHM); this.Controls.Add(this.L_TM); @@ -111,5 +123,6 @@ private void InitializeComponent() private System.Windows.Forms.Label L_TM; private System.Windows.Forms.DataGridView dgvHM; private System.Windows.Forms.Label L_HM; + private System.Windows.Forms.Button B_RTM; } } \ No newline at end of file diff --git a/pk3DS/Subforms/TMHM.cs b/pk3DS/Subforms/TMHM.cs index 352e33e..075c2b8 100644 --- a/pk3DS/Subforms/TMHM.cs +++ b/pk3DS/Subforms/TMHM.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Windows.Forms; +using System.Linq; namespace pk3DS { @@ -39,6 +40,7 @@ private void setupDGV() dgvIndex.Width = 45; dgvIndex.ReadOnly = true; dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; + dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable; } DataGridViewComboBoxColumn dgvMove = new DataGridViewComboBoxColumn(); { @@ -49,6 +51,7 @@ private void setupDGV() dgvMove.Width = 133; dgvMove.FlatStyle = FlatStyle.Flat; + dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable; } dgvTM.Columns.Add(dgvIndex); dgvTM.Columns.Add(dgvMove); @@ -126,5 +129,23 @@ private void formClosing(object sender, FormClosingEventArgs e) setList(); File.WriteAllBytes(codebin, data); } + + private void B_RandomTM_Click(object sender, EventArgs e) + { + int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => (int)i).ToArray(); + Util.Shuffle(randomMoves); + + int[] banned = { 15, 19, 57, 70, 127, 249, 291, 148 }; + int ctr = 0; + + for (int i = 0; i < dgvTM.Rows.Count; i++) + { + int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value); + if (banned.Contains(val)) continue; + while (banned.Contains(randomMoves[ctr])) ctr++; + + dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; + } + } } } \ No newline at end of file