• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonbathyscaphephpgamewindowsguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

オセロのゲーム


コミットメタ情報

リビジョン61 (tree)
日時2015-07-06 12:55:12
作者bellyoshi

ログメッセージ

定石

変更サマリ

差分

--- VisualBasic/ReversiGame2/ReversiGame/Board.vb (revision 60)
+++ VisualBasic/ReversiGame2/ReversiGame/Board.vb (revision 61)
@@ -180,10 +180,10 @@
180180 Me.DiscsCount(DiscColor.WHITE) = source.DiscsCount(DiscColor.WHITE)
181181 Me.DiscsCount(DiscColor.EMPTY) = source.DiscsCount(DiscColor.EMPTY)
182182
183- For t As Integer = 0 To _turns
183+ For t As Integer = 0 To source._turns
184184 For x As Integer = 1 To SIZE_X
185185 For y As Integer = 1 To SIZE_Y
186- If _turns <> MAX_TURNS Then
186+ If source._turns <> MAX_TURNS Then
187187 Debug.Assert(source._movableDir(t, x, y) IsNot Nothing)
188188 Me._movableDir(t, x, y) = New Direction(source._movableDir(t, x, y))
189189 End If
@@ -191,7 +191,7 @@
191191 Next
192192 Next
193193
194- For t As Integer = 0 To _turns
194+ For t As Integer = 0 To source._turns
195195 Me._movablePos(t) = New List(Of Point)
196196 For Each pos As Point In source._movablePos(t)
197197 Me._movablePos(t).Add(pos)
@@ -198,6 +198,10 @@
198198 Next
199199 Next
200200
201+ For Each log As ReverseLog In source._updateLogs
202+ Me._updateLogs.Add(log)
203+ Next
204+
201205 End Sub
202206
203207 Public Function CanMoveAny() As Boolean
--- VisualBasic/ReversiGame2/ReversiGame/frmCodes.vb (revision 60)
+++ VisualBasic/ReversiGame2/ReversiGame/frmCodes.vb (revision 61)
@@ -1,4 +1,4 @@
1-Imports System.IO
1+
22
33 Public Class frmCodes
44 Public Property Board As Board
@@ -21,19 +21,6 @@
2121 For Each p As Point In Board.History
2222 codesLine += p.ToString
2323 Next
24- Dim fileName As String = IOUtil.GetExePath + "/reversi.book"
25- Try
26- '書込むファイルを指定する
27- '(2番目の引数をtrueにすることで既存ファイルに追記する)
28- Dim sw As StreamWriter = New StreamWriter _
29- (fileName, True, System.Text.Encoding.Default)
30- 'ファイルに書込む
31- sw.WriteLine(codesLine)
32- sw.Flush()
33- sw.Close()
34- Catch ex As Exception
35- Console.WriteLine("ファイルに書込めません:")
36- Console.WriteLine(ex.Message)
37- End Try
24+ Book.BookManager.WriteLine(codesLine)
3825 End Sub
3926 End Class
\ No newline at end of file
--- VisualBasic/ReversiGame2/ReversiGame/AI/Common/computerPlayer.vb (revision 60)
+++ VisualBasic/ReversiGame2/ReversiGame/AI/Common/computerPlayer.vb (revision 61)
@@ -27,9 +27,11 @@
2727 Dim tempBoard As Board = New Board(nowBoard)
2828 _AI.Initialize(tempBoard)
2929
30+ Dim bookManager As New Book.BookManager
31+ Dim movables As IList(Of Point) = bookManager.Find(tempBoard)
3032 Dim bestPoint As New Point(-1, -1)
3133 Dim bestEvaluation As Integer = -9999
32- For Each discPoint As Point In tempBoard.MovablePostions
34+ For Each discPoint As Point In movables
3335 tempBoard.Move(discPoint)
3436 Dim evaluation As Integer = _AI.EvaluationValue(tempBoard)
3537 tempBoard.Undo()
--- VisualBasic/ReversiGame2/ReversiGame/AI/Level3/Node.vb (revision 60)
+++ VisualBasic/ReversiGame2/ReversiGame/AI/Level3/Node.vb (nonexistent)
@@ -1,10 +0,0 @@
1-Namespace AI.Level3
2-
3- Public Class Node
4- Public Property Child As Node = Nothing
5- Public Property Sibling As Node = Nothing
6- Public Property Point As Point = Nothing
7- End Class
8-
9-End Namespace
10-
--- VisualBasic/ReversiGame2/ReversiGame/AI/Level3/CoordinatesTransFormer.vb (revision 60)
+++ VisualBasic/ReversiGame2/ReversiGame/AI/Level3/CoordinatesTransFormer.vb (nonexistent)
@@ -1,86 +0,0 @@
1-Public Class CoordinatesTransFormer
2-
3- Private _rotate As Integer
4- Private _isMirror As Boolean
5-
6- Sub New(ByVal first As Point)
7- _rotate = 0
8- _isMirror = False
9-
10- If first = New Point("d3") Then
11- _rotate = 1
12- _isMirror = True
13- ElseIf first = New Point("c4") Then
14- _rotate = 2
15- ElseIf first = New Point("e6") Then
16- _rotate = 3
17- _isMirror = True
18- End If
19- End Sub
20-
21- ''' <summary>
22- ''' 座標をf5を開始点とする座標系に正規化する
23- ''' </summary>
24- ''' <param name="p"></param>
25- ''' <returns></returns>
26- ''' <remarks></remarks>
27- Public Function Normalize(ByVal p As Point) As Point
28- Dim newp As Point = RotatePoint(p, _rotate)
29- If _isMirror Then
30- newp = MirrorPoint(newp)
31- End If
32- Return newp
33- End Function
34-
35- ''' <summary>
36- ''' f5を開始点とする座標系を本来の座標に戻す。
37- ''' </summary>
38- ''' <param name="p"></param>
39- ''' <returns></returns>
40- ''' <remarks></remarks>
41- Public Function DeNormalize(ByVal p As Point) As Point
42- Dim newp As Point
43- If _isMirror Then
44- newp = MirrorPoint(p)
45- Else
46- newp = New Point(p.X, p.Y)
47- End If
48- Return RotatePoint(newp, -_rotate)
49- End Function
50-
51- ''' <summary>
52- ''' 座標回転
53- ''' </summary>
54- ''' <param name="oldPoint"></param>
55- ''' <param name="rotate">0:0度、1:90度,2:180度,3:270度</param>
56- ''' <returns></returns>
57- ''' <remarks></remarks>
58- Shared Function RotatePoint(ByVal oldPoint As Point, ByVal rotate As Integer) As Point
59- rotate = rotate Mod 4
60- If rotate < 0 Then
61- rotate += 4
62- End If
63- Dim x As Integer
64- Dim y As Integer
65- Select Case rotate
66- Case 1
67- x = oldPoint.Y
68- y = Board.SIZE_X - oldPoint.X + 1
69- Case 2
70- x = Board.SIZE_X - oldPoint.X + 1
71- y = Board.SIZE_Y - oldPoint.Y + 1
72- Case 3
73- x = Board.SIZE_X - oldPoint.Y + 1
74- y = oldPoint.X
75- Case Else 'case 0
76- x = oldPoint.X
77- y = oldPoint.Y
78- End Select
79- Return New Point(x, y)
80- End Function
81-
82- Shared Function MirrorPoint(ByVal oldPoint As Point) As Point
83- Return New Point(Board.SIZE_X - oldPoint.X + 1, oldPoint.Y)
84- End Function
85-
86-End Class
--- VisualBasic/ReversiGame2/ReversiGame/Book/CoordinatesTransFormer.vb (nonexistent)
+++ VisualBasic/ReversiGame2/ReversiGame/Book/CoordinatesTransFormer.vb (revision 61)
@@ -0,0 +1,89 @@
1+Namespace Book
2+ Public Class CoordinatesTransFormer
3+
4+ Private _rotate As Integer
5+ Private _isMirror As Boolean
6+
7+ Sub New(ByVal first As Point)
8+ _rotate = 0
9+ _isMirror = False
10+
11+ If first = New Point("d3") Then
12+ _rotate = 1
13+ _isMirror = True
14+ ElseIf first = New Point("c4") Then
15+ _rotate = 2
16+ ElseIf first = New Point("e6") Then
17+ _rotate = 3
18+ _isMirror = True
19+ End If
20+ End Sub
21+
22+ ''' <summary>
23+ ''' 座標をf5を開始点とする座標系に正規化する
24+ ''' </summary>
25+ ''' <param name="p"></param>
26+ ''' <returns></returns>
27+ ''' <remarks></remarks>
28+ Public Function Normalize(ByVal p As Point) As Point
29+ Dim newp As Point = RotatePoint(p, _rotate)
30+ If _isMirror Then
31+ newp = MirrorPoint(newp)
32+ End If
33+ Return newp
34+ End Function
35+
36+ ''' <summary>
37+ ''' f5を開始点とする座標系を本来の座標に戻す。
38+ ''' </summary>
39+ ''' <param name="p"></param>
40+ ''' <returns></returns>
41+ ''' <remarks></remarks>
42+ Public Function DeNormalize(ByVal p As Point) As Point
43+ Dim newp As Point
44+ If _isMirror Then
45+ newp = MirrorPoint(p)
46+ Else
47+ newp = New Point(p.X, p.Y)
48+ End If
49+ Return RotatePoint(newp, -_rotate)
50+ End Function
51+
52+ ''' <summary>
53+ ''' 座標回転
54+ ''' </summary>
55+ ''' <param name="oldPoint"></param>
56+ ''' <param name="rotate">0:0度、1:90度,2:180度,3:270度</param>
57+ ''' <returns></returns>
58+ ''' <remarks></remarks>
59+ Shared Function RotatePoint(ByVal oldPoint As Point, ByVal rotate As Integer) As Point
60+ rotate = rotate Mod 4
61+ If rotate < 0 Then
62+ rotate += 4
63+ End If
64+ Dim x As Integer
65+ Dim y As Integer
66+ Select Case rotate
67+ Case 1
68+ x = oldPoint.Y
69+ y = Board.SIZE_X - oldPoint.X + 1
70+ Case 2
71+ x = Board.SIZE_X - oldPoint.X + 1
72+ y = Board.SIZE_Y - oldPoint.Y + 1
73+ Case 3
74+ x = Board.SIZE_X - oldPoint.Y + 1
75+ y = oldPoint.X
76+ Case Else 'case 0
77+ x = oldPoint.X
78+ y = oldPoint.Y
79+ End Select
80+ Return New Point(x, y)
81+ End Function
82+
83+ Shared Function MirrorPoint(ByVal oldPoint As Point) As Point
84+ Return New Point(Board.SIZE_X - oldPoint.X + 1, oldPoint.Y)
85+ End Function
86+
87+ End Class
88+
89+End Namespace
--- VisualBasic/ReversiGame2/ReversiGame/Book/BookManager.vb (nonexistent)
+++ VisualBasic/ReversiGame2/ReversiGame/Book/BookManager.vb (revision 61)
@@ -0,0 +1,138 @@
1+Imports System.IO
2+
3+Namespace Book
4+
5+ Public Class BookManager
6+ Const BOOK_FILE_NAME = "reversi.book"
7+ Private Shared Function GetFullFileName() As String
8+ Return IOUtil.GetExePath & "/" & BOOK_FILE_NAME
9+ End Function
10+
11+ Private _root As Node = Nothing
12+
13+ Public Sub New()
14+ _root = New Node
15+ _root.Point = New Point("f5")
16+ Using sw As StreamReader = New StreamReader(GetFullFileName)
17+ While Not sw.EndOfStream
18+ Dim codesline = sw.ReadLine
19+ Dim book As New List(Of Point)
20+ For i As Integer = 0 To codesline.Length - 2 Step 2
21+ Dim p As Point = New Point(codesline.Substring(i, 2))
22+ book.Add(p)
23+ Next
24+ Add(book)
25+ End While
26+ End Using
27+
28+ End Sub
29+
30+ Public Sub Add(ByVal book As IList(Of Point))
31+ Dim node As Node = _root
32+ For i As Integer = 1 To book.Count - 1
33+ Dim p As Point = book(i)
34+ If node.Child Is Nothing Then
35+ node.Child = New Node
36+ node = node.Child
37+ node.Point = p
38+ Else
39+ node = node.Child
40+ While (True)
41+ If node.Point = p Then
42+ Exit While
43+ End If
44+
45+ If node.Sibling Is Nothing Then
46+ node.Sibling = New Node
47+ node = node.Sibling
48+ node.Point = p
49+ Exit While
50+ End If
51+ node = node.Sibling
52+ End While
53+ End If
54+ Next
55+
56+ End Sub
57+
58+
59+ Public Function Find(ByVal board As Board) As IList(Of Point)
60+ Dim node As Node = _root
61+ Dim history As IList(Of Point) = board.History
62+
63+ If history.Count = 0 Then
64+ Return board.MovablePostions
65+ End If
66+
67+ Dim transformer As New CoordinatesTransFormer(history(0))
68+ Dim normalizedHistory As New List(Of Point)
69+ For Each p As Point In history
70+ Dim normalizedPoint As Point = transformer.Normalize(p)
71+ normalizedHistory.Add(normalizedPoint)
72+ Next
73+
74+ For i As Integer = 1 To normalizedHistory.Count - 1
75+ Dim p As Point = normalizedHistory(i)
76+ node = node.Child
77+ While node IsNot Nothing
78+ If node.Point = p Then
79+ Exit While
80+ End If
81+ node = node.Sibling
82+ End While
83+ If node Is Nothing Then
84+ '定石から外れている。
85+ Return board.MovablePostions
86+ End If
87+ Next
88+ If node.Child Is Nothing Then
89+ '履歴は定石の終わりと一致
90+ Return board.MovablePostions
91+ End If
92+
93+ Dim nextMove As Point = GetNextMove(node)
94+ nextMove = transformer.DeNormalize(nextMove)
95+ Dim points As New List(Of Point)
96+ points.Add(nextMove)
97+ Return points
98+ End Function
99+
100+ Public Function GetNextMove(ByVal node As Node) As Point
101+ Dim candidates As New List(Of Point)
102+ Dim p As Node = node.Child
103+ While p IsNot Nothing
104+ candidates.Add(p.Point)
105+ p = p.Sibling
106+ End While
107+
108+ Dim index As Integer = (New Random).Next Mod candidates.Count
109+ Return candidates(index)
110+
111+ End Function
112+
113+
114+ ''' <summary>
115+ ''' 定石を追加する。
116+ ''' </summary>
117+ ''' <param name="codesLine">f5から始まる定石文字列</param>
118+ ''' <remarks></remarks>
119+ Public Shared Sub WriteLine(ByVal codesLine As String)
120+ Try
121+ '書込むファイルを指定する
122+ '(2番目の引数をtrueにすることで既存ファイルに追記する)
123+ Dim sw As StreamWriter = New StreamWriter _
124+ (GetFullFileName(), True, System.Text.Encoding.Default)
125+ 'ファイルに書込む
126+ sw.WriteLine(codesLine)
127+ sw.Flush()
128+ sw.Close()
129+ Catch ex As Exception
130+ Console.WriteLine("ファイルに書込めません:")
131+ Console.WriteLine(ex.Message)
132+ End Try
133+ End Sub
134+
135+ End Class
136+
137+End Namespace
138+
--- VisualBasic/ReversiGame2/ReversiGame/Book/Node.vb (nonexistent)
+++ VisualBasic/ReversiGame2/ReversiGame/Book/Node.vb (revision 61)
@@ -0,0 +1,10 @@
1+Namespace Book
2+
3+ Public Class Node
4+ Public Property Child As Node = Nothing
5+ Public Property Sibling As Node = Nothing
6+ Public Property Point As Point = Nothing
7+ End Class
8+
9+End Namespace
10+