Ejemplo n.º 1
0
def test_move2():
    board = SpaijiState("""\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 . . B . 1
  A C E G
>W(1E)
""")
    expected_board = """\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 . W B . 1
  A C E G
>B
"""
    board2 = board.make_move(31)

    assert board2.display() == expected_board
Ejemplo n.º 2
0
def test_group_with_covered_pieces():
    board = SpaijiState('''\
  A C E G
7 W W B W 7

5 B B W B 5

3 B W B W 3

1 W B B W 1
  A C E G
   B D F
 6 W W B 6

 4 B B W 4

 2 B W B 2
   B D F
    C E
  5 B W 5

  3 W W 3
    C E
>W(5E)
''')

    black_count = board.get_piece_count(board.BLACK)

    assert black_count == 9
Ejemplo n.º 3
0
def test_is_win():
    board = SpaijiState("""\
  A C E G
7 B B B B 7

5 W W W W 5

3 W W W W 3

1 B B B B 1
  A C E G
   B D F
 6 B B W 6

 4 W W W 4

 2 B B B 2
   B D F
    C E
  5 B W 5

  3 W B 3
    C E
     D
   4 W 4
     D
>B
""")

    assert board.is_win(board.WHITE)
    assert not board.is_win(board.BLACK)
Ejemplo n.º 4
0
def test_display_move():
    board = SpaijiState()

    black_move = board.display_move(2)
    white_move = board.display_move(32)

    assert black_move == 'B1E'
    assert white_move == 'W1E'
Ejemplo n.º 5
0
def test_get_index():
    board = SpaijiState()

    black_move = board.get_index(0, 0, 2, board.BLACK)
    white_move = board.get_index(0, 0, 2, board.WHITE)

    assert black_move == 2
    assert white_move == 32
Ejemplo n.º 6
0
    def __init__(self):
        display = SpaijiDisplay()
        display.update_board(
            SpaijiState('''\
  A C E G
7 B W W W 7

5 B R R B 5

3 W R R B 3

1 B B W B 1
  A C E G
   B D F
 6 W W B 6

 4 B R W 4

 2 W B W 2
   B D F
    C E
  5 W B 5

  3 B B 3
    C E
     D
   4 W 4
     D
>B
'''))
        display.resize(300, 224)
        super().__init__(display)
Ejemplo n.º 7
0
def test_start():
    board = SpaijiState()
    expected_board = """\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 . . . . 1
  A C E G
>W
"""

    assert board.display() == expected_board
Ejemplo n.º 8
0
def test_active_player():
    board1 = SpaijiState('''\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 . . W B 1
  A C E G
>B
''')
    board2 = board1.make_move(15)

    assert board2.get_active_player() == board1.BLACK
Ejemplo n.º 9
0
def test_valid_first_moves(start: int, end: int, expected_valid: bool,
                           reason: str):
    board = SpaijiState("""\
  A C E G
7 . . . . 7

5 . . . . 5

3 B W B W 3

1 B W B W 1
  A C E G
>W
""")
    valid_moves = board.get_valid_moves()
    for move in range(start, end):
        assert valid_moves[move] == expected_valid
Ejemplo n.º 10
0
def test_first_move_no_neighbours():
    """ Can't pick a first move with no neighbours. """
    board = SpaijiState('''\
  A C E G
7 . . . . 7

5 . . . . 5

3 W W . . 3

1 B B . . 1
  A C E G
>W
''')

    valid_moves = board.get_valid_moves()

    assert not valid_moves[16]
Ejemplo n.º 11
0
def test_piece_count():
    board = SpaijiState('''\
  A C E G
7 . . . . 7

5 . . . W 5

3 . . . B 3

1 . . W B 1
  A C E G
>W
''')

    black_count = board.get_piece_count(board.BLACK)
    white_count = board.get_piece_count(board.WHITE)

    assert black_count == 2
    assert white_count == 1
Ejemplo n.º 12
0
def test_early_end():
    """ End game when there are no valid moves. """
    board = SpaijiState('''\
  A C E G
7 B W B W 7

5 W B W B 5

3 B W B W 3

1 W B W B 1
  A C E G
   B D F
 6 . W . 6

 4 B . B 4

 2 . W . 2
   B D F
>W
''')

    assert board.get_piece_count(board.WHITE) == 3
    assert board.get_piece_count(board.BLACK) == 3
    assert board.is_ended()
    # Tie goes to black
    assert not board.is_win(board.WHITE)
    assert board.is_win(board.BLACK)
Ejemplo n.º 13
0
def test_count_group():
    board = SpaijiState('''\
  A C E G
7 . . . . 7

5 . . . B 5

3 . W W W 3

1 . . B B 1
  A C E G
   B D F
 6 . . . 6

 4 . . . 4

 2 . . W 2
   B D F
>B(3C)
''')

    white_count = board.get_piece_count(board.WHITE)

    assert white_count == 4
Ejemplo n.º 14
0
 def __init__(self):
     super().__init__(SpaijiState())
     self.visible_counts = (self.start_state.BLACK, self.start_state.WHITE)
     self.visible_move_types = (MoveType.BLACK, MoveType.WHITE)