-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
49 lines (39 loc) · 902 Bytes
/
game.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
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
type Game struct {
currentPos *Position
positions []*Position
}
type Move struct {
startPos int
endPos int
}
func NewMove(startPos int, endPos int) Move {
return Move{
startPos: startPos,
endPos: endPos,
}
}
// type NotationMove struct {
// startPos string
// endPos string
// }
// func (notationMove *NotationMove) ToMove() *Move {
// }
func NewGame() (*Game, error) {
pos, err := fenToPosition("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
if err != nil {
return nil, err
}
return &Game{
currentPos: pos,
positions: []*Position{pos},
}, nil
}
func (game *Game) Move(move Move) {
oldBoard := game.currentPos.board
newBoard := oldBoard
newBoard[Cell(move.endPos)] = oldBoard[Cell(move.startPos)]
newBoard[Cell(move.startPos)] = NoPiece
game.currentPos.board = newBoard
game.positions = append(game.positions, game.currentPos)
}