-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputGUI.vb
90 lines (73 loc) · 2.79 KB
/
InputGUI.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Imports System.Threading
Public Class InputGUI
Private sim As Simulator
Private numSteps As Integer
Private Sub runButton_Click(sender As Object, e As EventArgs) Handles runButton.Click
Dim simThread As Thread = New Thread(AddressOf RunSimWork)
simThread.IsBackground = True
runButton.Enabled = False
simThread.Start()
End Sub
Private Sub RunSimWork()
Dim progress, oldProgress As Integer
Try
numSteps = Convert.ToInt32(numMoves.Text)
If numSteps < 1 Then Throw New ArgumentOutOfRangeException("Numsteps must be greater than 0")
Catch ex As Exception
MsgBox("Bad input value: " + ex.ToString())
End Try
sim = New Simulator()
oldProgress = -1
progress = 0
While sim.StepCount < numSteps
sim.StepSim()
progress = CInt(sim.StepCount * 100 / numSteps)
If progress > oldProgress Then
oldProgress = progress
Me.Invoke(Sub() UpdateProgress(progress))
End If
If RealTimeUpdates.Checked Then
System.Threading.Thread.Sleep(1)
End If
If sim.StepCount Mod 100 = 0 Then
Me.Invoke(Sub() UpdateTextBoxes())
End If
End While
Me.Invoke(Sub() UpdateTextBoxes())
Me.Invoke(Sub() enableRunBtn(True))
End Sub
Private Sub UpdateProgress(percent As Integer)
simProgress.Value = percent
End Sub
Private Sub InputGUI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
sim = New Simulator()
numMoves.Text = "10000"
UpdateTextBoxes()
simProgress.Maximum = 100
End Sub
Private Sub UpdateTextBoxes()
'get the index values
Dim hitCounts As New List(Of Integer)
For Each tile In sim.board
hitCounts.Add(tile.NumHits)
Next
hitCounts.Sort()
Dim controlString As String
Dim myControlToFind As Label
For i As Integer = 0 To 39
controlString = "lab" + i.ToString()
myControlToFind = Me.Controls.Find(controlString, True).FirstOrDefault()
myControlToFind.Text = i.ToString() + Environment.NewLine + (sim.board.ElementAt(i).NumHits * 100 / sim.StepCount).ToString("0.00") + "%"
If sim.board.ElementAt(i).NumHits < hitCounts(8) Then
myControlToFind.BackColor = Color.Red
ElseIf sim.board.ElementAt(i).NumHits < hitCounts(32) Then
myControlToFind.BackColor = Color.Yellow
Else
myControlToFind.BackColor = Color.Chartreuse
End If
Next
End Sub
Private Sub enableRunBtn(enabled As Boolean)
runButton.Enabled = enabled
End Sub
End Class