• R/O
  • SSH
  • HTTPS

shoginextmove: コミット


コミットメタ情報

リビジョン58 (tree)
日時2014-09-16 11:08:48
作者bellyoshi

ログメッセージ

打つときの誤った手を打てないように

変更サマリ

差分

--- ShogiNextMove.Test/KomaUtilTest.vb (revision 57)
+++ ShogiNextMove.Test/KomaUtilTest.vb (revision 58)
@@ -59,11 +59,11 @@
5959 '''</summary>
6060 <TestMethod()> _
6161 Public Sub PromateKomaValueTest()
62- Assert.AreEqual(SENTE_TOKIN, KomaUtil.PromateKomaValue(SENTE_FU))
63- Assert.AreEqual(SENTE_NARI_KYO, KomaUtil.PromateKomaValue(SENTE_KYO))
64- Assert.AreEqual(GOTE_NARI_GIN, KomaUtil.PromateKomaValue(GOTE_GIN))
65- Assert.AreEqual(GOTE_UMA, KomaUtil.PromateKomaValue(GOTE_KAKU))
66- Assert.AreEqual(GOTE_RYU, KomaUtil.PromateKomaValue(GOTE_HISYA))
62+ Assert.AreEqual(SENTE_TOKIN, KomaUtil.PromoteKomaValue(SENTE_FU))
63+ Assert.AreEqual(SENTE_NARI_KYO, KomaUtil.PromoteKomaValue(SENTE_KYO))
64+ Assert.AreEqual(GOTE_NARI_GIN, KomaUtil.PromoteKomaValue(GOTE_GIN))
65+ Assert.AreEqual(GOTE_UMA, KomaUtil.PromoteKomaValue(GOTE_KAKU))
66+ Assert.AreEqual(GOTE_RYU, KomaUtil.PromoteKomaValue(GOTE_HISYA))
6767
6868 End Sub
6969
--- ShogiNextMove/frmMain.vb (revision 57)
+++ ShogiNextMove/frmMain.vb (revision 58)
@@ -47,7 +47,10 @@
4747 If Not e.MovingValue.ToLocation.IsMasu Then
4848 e.Cancel = True
4949 End If
50- 'todo:動ける場所以外はCancel
50+
51+ If Not Board.KomaMoveValidater.GetInstance.IsValidate(Viewer.kyokumen, e.MovingValue) Then
52+ e.Cancel = True
53+ End If
5154 If e.MouseRightClicked Then
5255 e.Cancel = True
5356 End If
--- ShogiNextMove/Control/Board/BoardViewer.vb (revision 57)
+++ ShogiNextMove/Control/Board/BoardViewer.vb (revision 58)
@@ -432,6 +432,9 @@
432432 End If
433433 Dim editingeventArgs As New EditingEventArgs
434434 editingeventArgs.MovingValue = te
435+ If te.MustPromote Then
436+ te.Promote = True
437+ End If
435438 RaiseEvent Editing(sender, editingeventArgs)
436439
437440 If editingeventArgs.Cancel Then
@@ -469,13 +472,18 @@
469472 Dim koma As Koma = kyokumen.GetMasu(l)
470473 Dim toggleKoma As Koma = New Koma(koma.Value)
471474 toggleKoma.Toggle()
472- Dim te As Te = New Te(l, l, toggleKoma.Value, False)
475+
476+ Dim te As Te = New Te(l, l, toggleKoma.Value, toggleKoma.IsPromoted)
473477 If te.MustPromote Then
474478 te.Piece.Toggle()
479+ te.Promote = te.Piece.IsPromoted
475480 End If
476481
477482 Dim eventArgs As New EditingEventArgs
478483 eventArgs.MovingValue = te
484+ If te.MustPromote Then
485+ te.Promote = True
486+ End If
479487 eventArgs.MouseRightClicked = True
480488 RaiseEvent Editing(sender, eventArgs)
481489
--- ShogiNextMove/Control/Board/EditingEventArgs.vb (revision 57)
+++ ShogiNextMove/Control/Board/EditingEventArgs.vb (revision 58)
@@ -3,20 +3,8 @@
33 Public Class EditingEventArgs
44 Inherits System.ComponentModel.CancelEventArgs
55
6- Private _movingValue As ShogiNextMove.Board.Te
76 Public Property MovingValue As ShogiNextMove.Board.Te
8- Get
9- Return _movingValue
10- End Get
11- Set(value As ShogiNextMove.Board.Te)
12- If value.MustPromote Then
13- value.Piece.Promate()
14- End If
15- _movingValue = value
167
17- End Set
18- End Property
19-
208 Public Property MouseRightClicked As Boolean = False
219
2210 Public Property IsMove As Boolean = False
--- ShogiNextMove/frmPromote.vb (revision 57)
+++ ShogiNextMove/frmPromote.vb (revision 58)
@@ -14,7 +14,7 @@
1414
1515 Public Sub New(normalKomaValue As Byte, x As Integer, y As Integer)
1616 Me.InitializeComponent()
17- Dim promoteKomaValue As Byte = Board.KomaUtil.PromateKomaValue(normalKomaValue)
17+ Dim promoteKomaValue As Byte = Board.KomaUtil.PromoteKomaValue(normalKomaValue)
1818
1919 Me.boardBitmap = _imageLoader.BoardBitmap
2020 Me.promoteKomaBitmap = _imageLoader.GetKomaImage(promoteKomaValue)
--- ShogiNextMove/Board/KyokumenUtil.vb (revision 57)
+++ ShogiNextMove/Board/KyokumenUtil.vb (revision 58)
@@ -60,18 +60,27 @@
6060 ''' <returns>True:二歩 false:正常</returns>
6161 ''' <remarks></remarks>
6262 Private Shared Function IsNifuInCol(ByVal kyokumen As Kyokumen, col As Integer, which As Byte) As Boolean
63- Dim sentefuExist As Boolean = False
63+ Return 2 <= CountFuInCol(kyokumen, col, which)
64+ End Function
65+
66+ ''' <summary>
67+ ''' 一列に歩が何枚あるか?
68+ ''' </summary>
69+ ''' <param name="kyokumen"></param>
70+ ''' <param name="col"></param>
71+ ''' <param name="which"></param>
72+ ''' <returns></returns>
73+ ''' <remarks></remarks>
74+ Public Shared Function CountFuInCol(ByVal kyokumen As Kyokumen, col As Integer, which As Byte) As Integer
75+ Dim count As Integer = 0
6476 For row As Integer = 1 To 9
6577 Dim l As New KomaLocation(col, row)
6678 Dim koma As Koma = kyokumen.GetMasu(l)
6779 If koma.Value = which Then
68- If sentefuExist Then
69- Return True
70- End If
71- sentefuExist = True
80+ count += 1
7281 End If
7382 Next
74- Return False
83+ Return count
7584 End Function
7685
7786 End Class
--- ShogiNextMove/Board/KomaUtil.vb (revision 57)
+++ ShogiNextMove/Board/KomaUtil.vb (revision 58)
@@ -71,7 +71,7 @@
7171 End If
7272 End Function
7373
74- Public Shared Function PromateKomaValue(ByVal komaValue As Byte) As Byte
74+ Public Shared Function PromoteKomaValue(ByVal komaValue As Byte) As Byte
7575 Debug.Assert(SENTE_FU <= komaValue AndAlso komaValue <= promoteKoma.Length - 1)
7676 Dim pvalue As Byte = promoteKoma(komaValue)
7777 Debug.Assert(pvalue <> 0)
--- ShogiNextMove/Board/Koma.vb (revision 57)
+++ ShogiNextMove/Board/Koma.vb (revision 58)
@@ -85,8 +85,8 @@
8585 Return KomaUtil.CanPromote(Value)
8686 End Function
8787
88- Public Sub Promate()
89- Me.Value = KomaUtil.PromateKomaValue(Value)
88+ Public Sub Promote()
89+ Me.Value = KomaUtil.PromoteKomaValue(Value)
9090 End Sub
9191
9292 Public Function IsSente() As Boolean
@@ -120,7 +120,7 @@
120120 Public Sub Toggle()
121121
122122 If Not IsPromoted() AndAlso CanPromote() Then
123- Promate()
123+ Promote()
124124 Else
125125 Value = CapturedKomaKind() + KomaUtil.OppositeKoma(Which)
126126 End If
--- ShogiNextMove/Board/Te.vb (revision 57)
+++ ShogiNextMove/Board/Te.vb (revision 58)
@@ -15,8 +15,8 @@
1515 End Get
1616 Set(value As Boolean)
1717 _promote = value
18- If value = True Then
19- Piece.Promate()
18+ If value = True AndAlso Not Piece.IsPromoted Then
19+ Piece.Promote()
2020 End If
2121 End Set
2222 End Property
--- ShogiNextMove/Board/KomaMoveValidater.vb (nonexistent)
+++ ShogiNextMove/Board/KomaMoveValidater.vb (revision 58)
@@ -0,0 +1,41 @@
1+Namespace Board
2+
3+ Public Class KomaMoveValidater
4+
5+ Private Shared _instance As New KomaMoveValidater
6+ Public Shared Function GetInstance() As KomaMoveValidater
7+ Return _instance
8+ End Function
9+
10+ Private Sub New()
11+ End Sub
12+
13+ Public Function IsValidate(ByVal kyokumen As Kyokumen, ByVal te As Te) As Boolean
14+ If te.FromLocation.IsMochigoma Then
15+ Return IsValidatePut(kyokumen, te)
16+ End If
17+ Return True
18+ End Function
19+
20+ Private Function IsValidatePut(ByVal kyokumen As Kyokumen, ByVal te As Te) As Boolean
21+ Dim tolocation As KomaLocation = te.ToLocation
22+ If Not kyokumen.GetMasu(tolocation).IsEmpty Then
23+ Return False
24+ End If
25+ If te.MustPromote Then
26+ Return False
27+ End If
28+ If te.Promote Then
29+ Return False
30+ End If
31+ If te.KomaKind = Koma.C_FU Then
32+ If 1 <= KyokumenUtil.CountFuInCol(kyokumen, tolocation.Col, te.Piece.Value) Then
33+ Return False
34+ End If
35+ End If
36+ Return True
37+ End Function
38+
39+ End Class
40+
41+End Namespace
旧リポジトリブラウザで表示