/
generator.go
48 lines (42 loc) · 2.66 KB
/
generator.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
package move
import (
"github.com/jonnyspicer/boudica/internal/state"
)
const (
fileA state.BitBoard = 0b_0000000100000001000000010000000100000001000000010000000100000001
fileH state.BitBoard = 0b_1000000010000000100000001000000010000000100000001000000010000000
fileAB state.BitBoard = 0b_0000001100000011000000110000001100000011000000110000001100000011
fileGH state.BitBoard = 0b_1100000011000000110000001100000011000000110000001100000011000000
rank1 state.BitBoard = 0b_1111111100000000000000000000000000000000000000000000000000000000
rank4 state.BitBoard = 0b_0000000000000000000000001111111100000000000000000000000000000000
rank5 state.BitBoard = 0b_0000000000000000000000000000000011111111000000000000000000000000
rank8 state.BitBoard = 0b_0000000000000000000000000000000000000000000000000000000011111111
centre state.BitBoard = 0b_0000000000000000000000000001100000011000000000000000000000000000
extendedCentre state.BitBoard = 0b_0000000000000000001111000011110000111100001111000000000000000000
kingSide state.BitBoard = 0b_1111000011110000111100001111000011110000111100001111000011110000
queenSide state.BitBoard = 0b_0000111100001111000011110000111100001111000011110000111100001111
kingB7 state.BitBoard = 0b_0000000000000000000000000000000000000000000001110000010100000111
knightC6 state.BitBoard = 0b_0000000000000000000000000000101000010001000000000001000100001010
)
type Generator struct {
// TODO: should this be refactored to be a Board, and can decouple moveGen and State?
Board state.Board
whiteAvailableSquares state.BitBoard
blackPieces state.BitBoard
emptySquares state.BitBoard
history string
// TODO: there has to be a better way to do this... a move struct? [][x1, y1, x2, y2]? is it worth benchmarking this?
possibilities string
}
func NewGenerator(b state.Board, history string) Generator {
g := Generator{Board: b, history: history}
// All squares that white pieces could conceivably move to, ie ones that aren't occupied by white pieces or the black king
g.whiteAvailableSquares = ^(b.WhitePawns | b.WhiteKnights | b.WhiteBishops | b.WhiteRooks | b.WhiteQueens | b.WhiteKing | b.BlackKing)
// All squares occupied by black pieces, bar the black king
g.blackPieces = b.BlackPawns | b.BlackKnights | b.BlackBishops | b.BlackRooks | b.BlackQueens
g.emptySquares = ^(b.WhitePawns | b.WhiteKnights | b.WhiteBishops | b.WhiteRooks | b.WhiteQueens | b.WhiteKing | b.BlackPawns | b.BlackKnights | b.BlackBishops | b.BlackRooks | b.BlackQueens | b.BlackKing)
return g
}
func (g *Generator) Possible() {
g.WhitePawns()
}