どうぶつしょうぎの完全解析をするGUI
@@ -43,7 +43,7 @@ | ||
43 | 43 | ''' <remarks></remarks> |
44 | 44 | Public Property ToPos As Position |
45 | 45 | ''' <summary> |
46 | - ''' 駒の種類 | |
46 | + ''' 移動した駒の種類 | |
47 | 47 | ''' </summary> |
48 | 48 | ''' <value></value> |
49 | 49 | ''' <returns></returns> |
@@ -51,6 +51,14 @@ | ||
51 | 51 | Public Property Koma As Koma |
52 | 52 | |
53 | 53 | ''' <summary> |
54 | + ''' 取った駒の種類 | |
55 | + ''' </summary> | |
56 | + ''' <value></value> | |
57 | + ''' <returns></returns> | |
58 | + ''' <remarks></remarks> | |
59 | + Public Property CapturedPiece As Koma = Form.Koma.Empty | |
60 | + | |
61 | + ''' <summary> | |
54 | 62 | ''' なりごまとなるか(ヒヨコがニワトリになるか) |
55 | 63 | ''' </summary> |
56 | 64 | ''' <returns></returns> |
@@ -72,5 +80,10 @@ | ||
72 | 80 | Return False |
73 | 81 | End Function |
74 | 82 | |
75 | - | |
83 | + Public Shared Operator =(ByVal op1 As Move, ByVal op2 As Move) | |
84 | + Return op1.ToString = op2.ToString | |
85 | + End Operator | |
86 | + Public Shared Operator <>(ByVal op1 As Move, ByVal op2 As Move) | |
87 | + Return Not (op1 = op2) | |
88 | + End Operator | |
76 | 89 | End Class |
@@ -15,8 +15,24 @@ | ||
15 | 15 | ''' <remarks></remarks> |
16 | 16 | Private _Capured(5) As Integer |
17 | 17 | |
18 | - Private _turn As Side | |
18 | + ''' <summary> | |
19 | + ''' 手番 | |
20 | + ''' </summary> | |
21 | + ''' <remarks></remarks> | |
22 | + Private _side As Side | |
19 | 23 | |
24 | + ''' <summary> | |
25 | + ''' 手数 | |
26 | + ''' </summary> | |
27 | + ''' <remarks></remarks> | |
28 | + Private _turnCount As Integer | |
29 | + | |
30 | + ''' <summary> | |
31 | + ''' 棋譜ログ | |
32 | + ''' </summary> | |
33 | + ''' <remarks></remarks> | |
34 | + Private _logs As New List(Of Move) | |
35 | + | |
20 | 36 | Public Function GetCells(ByVal pos As Position) As Koma |
21 | 37 | Return GetCells(pos.X, pos.Y) |
22 | 38 | End Function |
@@ -61,7 +77,8 @@ | ||
61 | 77 | For Each c As Integer In _Capured |
62 | 78 | c = 0 |
63 | 79 | Next |
64 | - Me._turn = Side.sente | |
80 | + Me._side = Side.sente | |
81 | + Me._turnCount = 0 | |
65 | 82 | End Sub |
66 | 83 | |
67 | 84 | ''' <summary> |
@@ -78,7 +95,11 @@ | ||
78 | 95 | For i As Integer = 0 To Me._Capured.Count - 1 |
79 | 96 | Me._Capured(i) = source._Capured(i) |
80 | 97 | Next |
81 | - Me._turn = source._turn | |
98 | + Me._side = source._side | |
99 | + Me._turnCount = source._turnCount | |
100 | + For Each log As Move In source._logs | |
101 | + _logs.Add(log) | |
102 | + Next | |
82 | 103 | End Sub |
83 | 104 | |
84 | 105 | ''' <summary> |
@@ -101,7 +122,7 @@ | ||
101 | 122 | s.Append(_Capured(i)) |
102 | 123 | Next |
103 | 124 | s.AppendLine() |
104 | - s.AppendLine(SideUtil.ToCode(_turn)) | |
125 | + s.AppendLine(SideUtil.ToCode(_side)) | |
105 | 126 | Return s.ToString |
106 | 127 | End Function |
107 | 128 |
@@ -145,9 +166,61 @@ | ||
145 | 166 | Public Sub DoMove(ByVal move As Move) |
146 | 167 | Debug.Assert(CanMove(move)) |
147 | 168 | DoEdit(move) |
148 | - _turn = DirectCast(-_turn, Side) | |
169 | + AddLog(move) | |
170 | + _side = DirectCast(-_side, Side) | |
149 | 171 | End Sub |
150 | 172 | |
173 | + ''' <summary> | |
174 | + ''' 一手進める | |
175 | + ''' </summary> | |
176 | + ''' <remarks></remarks> | |
177 | + Public Sub DoNext() | |
178 | + If _turnCount >= _logs.Count Then | |
179 | + Exit Sub | |
180 | + End If | |
181 | + Dim move As Move = _logs(_turnCount) | |
182 | + DoMove(move) | |
183 | + End Sub | |
184 | + | |
185 | + Private Sub AddLog(ByVal move As Move) | |
186 | + If _logs.Count = _turnCount Then | |
187 | + _logs.Add(move) | |
188 | + ElseIf _logs.Count > _turnCount Then | |
189 | + If _logs(_turnCount) <> move Then | |
190 | + _logs(_turnCount) = move | |
191 | + End If | |
192 | + For i As Integer = _logs.Count - 1 To _turnCount + 1 | |
193 | + _logs.RemoveAt(i) | |
194 | + Next | |
195 | + End If | |
196 | + _turnCount += 1 | |
197 | + Debug.Assert(_turnCount <= _logs.Count) | |
198 | + End Sub | |
199 | + | |
200 | + ''' <summary> | |
201 | + ''' 一手戻す。 | |
202 | + ''' </summary> | |
203 | + ''' <remarks></remarks> | |
204 | + Public Sub Undo() | |
205 | + If _turnCount <= 0 Then | |
206 | + Exit Sub | |
207 | + End If | |
208 | + _turnCount -= 1 | |
209 | + Dim move As Move = _logs(_turnCount) | |
210 | + If move.FromPos.IsCaptured Then | |
211 | + _Capured(CapuredKomaIndex(move.Koma)) += 1 | |
212 | + SetCells(move.ToPos, Koma.Empty) | |
213 | + Else | |
214 | + If move.CapturedPiece <> Koma.Empty Then | |
215 | + Dim capturedPiece As Koma = KomaUtil.CaputringKoma(move.CapturedPiece) | |
216 | + _Capured(CapuredKomaIndex(capturedPiece)) -= 1 | |
217 | + End If | |
218 | + SetCells(move.ToPos, move.CapturedPiece) | |
219 | + SetCells(move.FromPos, move.Koma) | |
220 | + End If | |
221 | + _side = -_side | |
222 | + End Sub | |
223 | + | |
151 | 224 | Public Sub DoEdit(ByVal move As Move) |
152 | 225 | If move.FromPos.IsCaptured Then |
153 | 226 | _Capured(CapuredKomaIndex(move.Koma)) -= 1 |
@@ -158,6 +231,7 @@ | ||
158 | 231 | If capturedPiece <> Koma.GoteLI AndAlso |
159 | 232 | capturedPiece <> Koma.SenteLI Then |
160 | 233 | _Capured(CapuredKomaIndex(capturedPiece)) += 1 |
234 | + move.CapturedPiece = GetCells(move.ToPos) | |
161 | 235 | End If |
162 | 236 | End If |
163 | 237 | SetCells(move.ToPos, GetCells(move.FromPos)) |
@@ -172,7 +246,7 @@ | ||
172 | 246 | ''' <returns></returns> |
173 | 247 | ''' <remarks></remarks> |
174 | 248 | Public Function CanMove(ByVal move As Move) As Boolean |
175 | - If Not _turn = KomaUtil.KomaSide(move.Koma) Then | |
249 | + If Not _side = KomaUtil.KomaSide(move.Koma) Then | |
176 | 250 | Return False |
177 | 251 | End If |
178 | 252 | Dim fromPos As Position = move.FromPos |
@@ -25,7 +25,10 @@ | ||
25 | 25 | Dim Board1 As doubutu.UI.Form.Board = New doubutu.UI.Form.Board() |
26 | 26 | Me.btnAnalyze = New System.Windows.Forms.Button() |
27 | 27 | Me.TextBox1 = New System.Windows.Forms.TextBox() |
28 | + Me.btnUndoFirst = New System.Windows.Forms.Button() | |
29 | + Me.btnUndo = New System.Windows.Forms.Button() | |
28 | 30 | Me.BoardViewer1 = New doubutu.UI.Form.Control.Board.BoardViewer() |
31 | + Me.btnNext = New System.Windows.Forms.Button() | |
29 | 32 | Me.SuspendLayout() |
30 | 33 | ' |
31 | 34 | 'btnAnalyze |
@@ -46,20 +49,50 @@ | ||
46 | 49 | Me.TextBox1.Size = New System.Drawing.Size(392, 318) |
47 | 50 | Me.TextBox1.TabIndex = 2 |
48 | 51 | ' |
52 | + 'btnUndoFirst | |
53 | + ' | |
54 | + Me.btnUndoFirst.Location = New System.Drawing.Point(86, 35) | |
55 | + Me.btnUndoFirst.Name = "btnUndoFirst" | |
56 | + Me.btnUndoFirst.Size = New System.Drawing.Size(89, 23) | |
57 | + Me.btnUndoFirst.TabIndex = 4 | |
58 | + Me.btnUndoFirst.Text = "初手に戻す" | |
59 | + Me.btnUndoFirst.UseVisualStyleBackColor = True | |
60 | + ' | |
61 | + 'btnUndo | |
62 | + ' | |
63 | + Me.btnUndo.Location = New System.Drawing.Point(181, 35) | |
64 | + Me.btnUndo.Name = "btnUndo" | |
65 | + Me.btnUndo.Size = New System.Drawing.Size(75, 23) | |
66 | + Me.btnUndo.TabIndex = 4 | |
67 | + Me.btnUndo.Text = "一手戻す" | |
68 | + Me.btnUndo.UseVisualStyleBackColor = True | |
69 | + ' | |
49 | 70 | 'BoardViewer1 |
50 | 71 | ' |
51 | 72 | Me.BoardViewer1.IsBoardViewRotated = False |
52 | 73 | Me.BoardViewer1.kyokumen = Board1 |
53 | - Me.BoardViewer1.Location = New System.Drawing.Point(12, 12) | |
74 | + Me.BoardViewer1.Location = New System.Drawing.Point(12, 92) | |
54 | 75 | Me.BoardViewer1.Name = "BoardViewer1" |
55 | 76 | Me.BoardViewer1.Size = New System.Drawing.Size(774, 544) |
56 | 77 | Me.BoardViewer1.TabIndex = 3 |
57 | 78 | ' |
79 | + 'btnNext | |
80 | + ' | |
81 | + Me.btnNext.Location = New System.Drawing.Point(262, 35) | |
82 | + Me.btnNext.Name = "btnNext" | |
83 | + Me.btnNext.Size = New System.Drawing.Size(75, 23) | |
84 | + Me.btnNext.TabIndex = 5 | |
85 | + Me.btnNext.Text = "一手進める" | |
86 | + Me.btnNext.UseVisualStyleBackColor = True | |
87 | + ' | |
58 | 88 | 'frmMain |
59 | 89 | ' |
60 | 90 | Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!) |
61 | 91 | Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font |
62 | - Me.ClientSize = New System.Drawing.Size(1272, 554) | |
92 | + Me.ClientSize = New System.Drawing.Size(1272, 672) | |
93 | + Me.Controls.Add(Me.btnNext) | |
94 | + Me.Controls.Add(Me.btnUndo) | |
95 | + Me.Controls.Add(Me.btnUndoFirst) | |
63 | 96 | Me.Controls.Add(Me.BoardViewer1) |
64 | 97 | Me.Controls.Add(Me.TextBox1) |
65 | 98 | Me.Controls.Add(Me.btnAnalyze) |
@@ -72,5 +105,8 @@ | ||
72 | 105 | Friend WithEvents btnAnalyze As System.Windows.Forms.Button |
73 | 106 | Friend WithEvents TextBox1 As System.Windows.Forms.TextBox |
74 | 107 | Friend WithEvents BoardViewer1 As doubutu.UI.Form.Control.Board.BoardViewer |
108 | + Friend WithEvents btnUndoFirst As System.Windows.Forms.Button | |
109 | + Friend WithEvents btnUndo As System.Windows.Forms.Button | |
110 | + Friend WithEvents btnNext As System.Windows.Forms.Button | |
75 | 111 | |
76 | 112 | End Class |
@@ -34,4 +34,19 @@ | ||
34 | 34 | e.Cancel = True |
35 | 35 | End If |
36 | 36 | End Sub |
37 | + | |
38 | + Private Sub btnUndoFirst_Click(sender As System.Object, e As System.EventArgs) Handles btnUndoFirst.Click | |
39 | + BoardViewer1.kyokumen = New Board() | |
40 | + BoardViewer1.DrawCurrentBitmap() | |
41 | + End Sub | |
42 | + | |
43 | + Private Sub btnUndo_Click(sender As System.Object, e As System.EventArgs) Handles btnUndo.Click | |
44 | + BoardViewer1.kyokumen.Undo() | |
45 | + BoardViewer1.DrawCurrentBitmap() | |
46 | + End Sub | |
47 | + | |
48 | + Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles btnNext.Click | |
49 | + BoardViewer1.kyokumen.DoNext() | |
50 | + BoardViewer1.DrawCurrentBitmap() | |
51 | + End Sub | |
37 | 52 | End Class |