-
Notifications
You must be signed in to change notification settings - Fork 0
/
human.go
36 lines (32 loc) · 823 Bytes
/
human.go
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
package gothello
import (
"bufio"
"fmt"
"os"
)
type HumanController struct {
reader *bufio.Reader
}
func NewHumanController() *HumanController {
return &HumanController{bufio.NewReader(os.Stdin)}
}
func (h *HumanController) Move(g *Game) Bitboard {
allowed := g.LegalMoves()
if allowed == Bitboard(0) {
return Bitboard(0)
}
fmt.Println(g)
fmt.Printf("Legal moves: %s\n", allowed)
fmt.Print("Enter the location of your move: ")
movestr, _ := h.reader.ReadString('\n')
if len(movestr) >= 2 {
r := uint(movestr[0] - 'A')
c := uint(movestr[1] - '1')
move := RC2Mask(r, c)
if move&allowed != 0 {
return move
}
}
fmt.Println("Sorry, your input was not a legal move. Please retry.")
return h.Move(g)
}