class TestImportPosition(unittest.TestCase): def setUp(self): self.state = State(c.DEFAULT_POSITION) self.state.board = [['empty' for _ in range(8)] for _ in range(8)] self.state.pieces = { piece: set() for piece in c.WHITE_PIECES + c.BLACK_PIECES } def test__get_piece(self): self.assertEqual(self.state._get_piece('n'), 'black_knight') def test__add_piece(self): state, pieces = self.state._add_piece('black_queen', self.state.board, self.state.pieces, 1, 2) self.assertEqual(state[1][2], 'black_queen') self.assertEqual(pieces['black_queen'], {(1, 2)}) def test_import_caste_rights(self): self.assertDictEqual( self.state._import_castle_rights('Kq'), { 'white_king_side': True, 'white_queen_side': False, 'black_king_side': False, 'black_queen_side': True }) self.assertDictEqual( self.state._import_castle_rights('-'), { 'white_king_side': False, 'white_queen_side': False, 'black_king_side': False, 'black_queen_side': False })
def setUp(self): self.state = State(c.DEFAULT_POSITION) self.state.board = [['empty' for _ in range(8)] for _ in range(8)] self.state.pieces = { piece: set() for piece in c.WHITE_PIECES + c.BLACK_PIECES }
def test_repetition(self): old_state = State(c.DEFAULT_POSITION) new_state = State(c.DEFAULT_POSITION) Game._add_repetition(new_state, old_state) old_state = copy.deepcopy(new_state) Game._add_repetition(new_state, old_state) old_state = copy.deepcopy(new_state) Game._add_repetition(new_state, old_state) print(new_state.repetition_counter) self.assertEqual(new_state.winner, 'draw')
def setUp(self): self.game = Game() self.state = State(c.EMPTY_BOARD) self.state.board[1][2] = 'white_knight' self.state.board[5][7] = 'black_knight' self.state.board[3][3] = 'white_pawn' self.state.board[3][4] = 'black_king' self.state.pieces['white_knight'].add((1, 2)) self.state.pieces['black_knight'].add((5, 7)) self.state.pieces['white_pawn'].add((3, 3)) self.state.pieces['black_king'].add((3, 4))
def setUp(self): self.game = Game() self.state = State(c.EMPTY_BOARD) self.state.castle_rights = { 'white_king_side': True, 'white_queen_side': True, 'black_king_side': True, 'black_queen_side': True } self.state.board[1][3] = 'white_pawn' self.state.board[7][6] = 'white_pawn' self.state.board[2][3] = 'black_queen' self.state.board[7][7] = 'white_rook' self.state.board[1][2] = 'black_pawn' self.state.board[7][4] = 'white_king' self.state.pieces['white_pawn'].add((1, 3)) self.state.pieces['white_pawn'].add((7, 6)) self.state.pieces['black_queen'].add((2, 3)) self.state.pieces['white_rook'].add((7, 7)) self.state.pieces['black_pawn'].add((1, 2)) self.state.pieces['white_king'].add((7, 4))
def test_prediction(self): nn = NNet() state = State(c.DEFAULT_POSITION) self.assertIsInstance(nn.prediction(state), tuple)
def test_policy1(self): state = State(c.DEFAULT_POSITION) move = ((6, 2), (4, 2)) self.assertEqual( NNet._get_policy(NNet._to_policy_vector(move, 'white'), state)[move], 1)