1- // Package game provides a simple Go engine interface and a random-move engine.
2- package game
1+ // Package engine provides a simple Go engine interface and a random-move engine.
2+ package engine
33
44import (
55 "math/rand"
66 "time"
7+
8+ "github.com/RubikNube/GoInGo/cmd/game"
79)
810
911// Engine is an interface for Go engines.
1012type Engine interface {
1113 // Move returns the next move as a Point, or nil if passing.
12- Move (board Board , player FieldState , ko * Point ) * Point
14+ Move (board game. Board , player game. FieldState , ko * game. Point ) * game. Point
1315}
1416
1517// RandomEngine implements Engine by picking a random legal move.
1618type RandomEngine struct {}
1719
18- func (e * RandomEngine ) Move (board Board , player FieldState , ko * Point ) * Point {
19- empty := []Point {}
20+ func (e * RandomEngine ) Move (board game. Board , player game. FieldState , ko * game. Point ) * game. Point {
21+ empty := []game. Point {}
2022 for i := 0 ; i < 9 ; i ++ {
2123 for j := 0 ; j < 9 ; j ++ {
22- if board [i ][j ] == Empty {
23- empty = append (empty , Point {Row : i , Col : j })
24+ if board [i ][j ] == game . Empty {
25+ empty = append (empty , game. Point {Row : i , Col : j })
2426 }
2527 }
2628 }
@@ -32,26 +34,26 @@ func (e *RandomEngine) Move(board Board, player FieldState, ko *Point) *Point {
3234 if ko != nil && pt .Row == ko .Row && pt .Col == ko .Col {
3335 continue
3436 }
35- var nextBoard Board
37+ var nextBoard game. Board
3638 copy (nextBoard [:], board [:])
3739 nextBoard [pt.Row ][pt.Col ] = player
38- opp := Black
39- if player == Black {
40- opp = White
40+ opp := game . Black
41+ if player == game . Black {
42+ opp = game . White
4143 }
42- captured := []Point {}
43- for _ , n := range Neighbors (pt ) {
44+ captured := []game. Point {}
45+ for _ , n := range game . Neighbors (pt ) {
4446 if nextBoard [n.Row ][n.Col ] == opp {
45- group , libs := Group (nextBoard , n )
47+ group , libs := game . Group (nextBoard , n )
4648 if len (libs ) == 0 {
4749 for stonePt := range group {
48- nextBoard [stonePt.Row ][stonePt.Col ] = Empty
50+ nextBoard [stonePt.Row ][stonePt.Col ] = game . Empty
4951 captured = append (captured , stonePt )
5052 }
5153 }
5254 }
5355 }
54- _ , libs := Group (nextBoard , pt )
56+ _ , libs := game . Group (nextBoard , pt )
5557 if len (libs ) == 0 {
5658 continue
5759 }
0 commit comments