Search Apps Documentation Source Content File Folder Download Copy Actions Download

zobrist_test.gno

1.14 Kb ยท 55 lines
 1package zobrist
 2
 3import (
 4	"testing"
 5)
 6
 7// piece character to internal piece
 8var p = [256]Piece{
 9	'P': PiecePawn,
10	'R': PieceRook,
11	'N': PieceKnight,
12	'B': PieceBishop,
13	'Q': PieceQueen,
14	'K': PieceKing,
15
16	'p': PieceBlack | PiecePawn,
17	'r': PieceBlack | PieceRook,
18	'n': PieceBlack | PieceKnight,
19	'b': PieceBlack | PieceBishop,
20	'q': PieceBlack | PieceQueen,
21	'k': PieceBlack | PieceKing,
22}
23
24// NewBoard returns a Board normally set up at the initial position for standard
25// chess.
26func NewBoard() Board {
27	return Board{
28		// row 1
29		p['R'], p['N'], p['B'], p['Q'],
30		p['K'], p['B'], p['N'], p['R'],
31		// row 2
32		p['P'], p['P'], p['P'], p['P'],
33		p['P'], p['P'], p['P'], p['P'],
34
35		// rows 3, 4, 5, 6
36		0, 0, 0, 0, 0, 0, 0, 0,
37		0, 0, 0, 0, 0, 0, 0, 0,
38		0, 0, 0, 0, 0, 0, 0, 0,
39		0, 0, 0, 0, 0, 0, 0, 0,
40
41		// row 7
42		p['p'], p['p'], p['p'], p['p'],
43		p['p'], p['p'], p['p'], p['p'],
44		// row 8
45		p['r'], p['n'], p['b'], p['q'],
46		p['k'], p['b'], p['n'], p['r'],
47	}
48}
49
50func TestInitialPosition(t *testing.T) {
51	h := Hash(NewBoard(), false, 0, 255)
52	if h != InitialPosition {
53		t.Fatalf("InitialPosition is invalid: set to %d, should be %d", InitialPosition, h)
54	}
55}