Exemplo n.º 1
0
    def test_first_move_by_black_is_a_white_flat(self):
        self.board.do_move(PlayerType.WHITE, parse_move("b1"))

        move = parse_move("a1")
        self.board.do_move(PlayerType.BLACK, move)
        stack = self.board.get_stack(*move.get_xy())
        assert stack == [Stone(PlayerType.WHITE, StoneType.FLAT)]
Exemplo n.º 2
0
 def init_board(self):
     self.board = Board(tak_config, 4)
     self.board.do_move(PlayerType.WHITE, parse_move("b1"))
     self.board.do_move(PlayerType.BLACK, parse_move("a1"))
     self.board.do_move(PlayerType.WHITE, parse_move("Sa2"))
     self.board.do_move(PlayerType.BLACK, parse_move("Sb2"))
     self.board.do_move(PlayerType.WHITE, parse_move("Ca3"))
     self.board.do_move(PlayerType.BLACK, parse_move("Cb3"))
Exemplo n.º 3
0
 def test_move_less_than_carry_limit(self, carry):
     stack = [
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
     ]
     board = Board(tak_config, board_size=6)
     board.initial_moves = False
     board.get_stack(0, 0).extend(stack)
     board.do_move(PlayerType.WHITE, parse_move(f"{carry}a1>{carry}"))
     assert board.get_stack(0, 0) == stack[:-carry]  # except last n
     assert board.get_stack(1, 0) == stack[-carry:]  # last n
Exemplo n.º 4
0
 def test_move_more_than_carry_limit_fails(self, board_size):
     board = Board(tak_config, board_size=board_size)
     board.get_stack(0, 0).extend([
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
     ])
     with pytest.raises(InvalidMoveError):
         board.do_move(PlayerType.WHITE,
                       parse_move(f"{board_size+1}a1>1{board_size}"))
Exemplo n.º 5
0
 def test_move_works_as_expected(self):
     board = Board(tak_config, board_size=6)
     board.initial_moves = False
     board.get_stack(0, 0).extend([
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.CAPSTONE),
     ])
     board.get_stack(0, 1).extend([Stone(PlayerType.BLACK, StoneType.FLAT)])
     board.get_stack(0, 2).extend([Stone(PlayerType.WHITE, StoneType.FLAT)])
     board.get_stack(0, 3).extend([
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT)
     ])
     board.get_stack(0, 4).extend([
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.STANDING)
     ])
     board.do_move(PlayerType.WHITE, parse_move(f"6a1+2211"))
     assert board.get_stack(0,
                            0) == [Stone(PlayerType.BLACK, StoneType.FLAT)]
     assert board.get_stack(0, 1) == [
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT)
     ]
     assert board.get_stack(0, 2) == [
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT)
     ]
     assert board.get_stack(0, 3) == [
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.BLACK, StoneType.FLAT)
     ]
     assert board.get_stack(0, 4) == [
         Stone(PlayerType.BLACK, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.FLAT),
         Stone(PlayerType.WHITE, StoneType.CAPSTONE)
     ]
Exemplo n.º 6
0
 def test_illegal_second_moves(self, player: PlayerType, move: str):
     self.board.do_move(PlayerType.WHITE, parse_move("b1"))
     with pytest.raises(InvalidMoveError):
         self.board.do_move(player, parse_move(move))
Exemplo n.º 7
0
 def test_illegal_first_moves(self, player: PlayerType, move: str):
     with pytest.raises(InvalidMoveError):
         self.board.do_move(player, parse_move(move))
Exemplo n.º 8
0
 def test_black_cant_play_twice(self):
     with pytest.raises(InvalidMoveError):
         self.board.do_move(PlayerType.BLACK, parse_move("c1"))
Exemplo n.º 9
0
 def test_white_cant_play_twice(self):
     self.board.do_move(PlayerType.WHITE, parse_move("c1"))
     with pytest.raises(InvalidMoveError):
         self.board.do_move(PlayerType.WHITE, parse_move("c2"))
Exemplo n.º 10
0
 def test_placing_outside_the_board_fails(self, player: PlayerType,
                                          move: str):
     if player == PlayerType.BLACK:
         self.board.do_move(PlayerType.WHITE, parse_move("a4"))
     with pytest.raises(InvalidMoveError):
         self.board.do_move(player, parse_move(move))
Exemplo n.º 11
0
 def test_placing_on_empty_fields_is_valid(self, player: PlayerType,
                                           move: str):
     if player == PlayerType.BLACK:
         self.board.do_move(PlayerType.WHITE, parse_move("a4"))
     self.board.do_move(player, parse_move(move))