コード例 #1
0
def test_valid_colours():
    state = SpireState()
    expected_colours = (state.BLACK, state.RED)

    colours = state.get_valid_colours()

    assert colours == expected_colours
コード例 #2
0
def test_get_coordinates():
    state = SpireState()

    height, row, column = state.get_coordinates(31)

    assert height == 0
    assert row == 0
    assert column == 1
コード例 #3
0
def test_display_move():
    state1 = SpireState()

    move1_display = state1.display_move(2)
    move2_display = state1.display_move(32)

    state2 = state1.make_move(1)
    move3_display = state2.display_move(2)

    assert move1_display == 'B1E'
    assert move2_display == 'R1E'
    assert move3_display == 'W1E'
コード例 #4
0
def test_upper_rows(start: int, end: int, expected_valid: bool, reason: str):
    board = SpireState("""\
  A C E G
7 W W R W 7

5 B B R B 5

3 . . . . 3

1 . . . . 1
  A C E G
>B,R
""")
    valid_moves = board.get_valid_moves()
    for move in range(start, end):
        assert valid_moves[move] == expected_valid, move
コード例 #5
0
def test_lower_rows(start: int, end: int, expected_valid: bool, reason: str):
    board = SpireState("""\
  A C E G
7 . . . . 7

5 . . . . 5

3 B B R B 3

1 W W R W 1
  A C E G
>B,R
""")
    valid_moves = board.get_valid_moves()
    for move in range(start, end):
        assert valid_moves[move] == expected_valid, move
コード例 #6
0
def test_get_index():
    state = SpireState()

    black_move = state.get_index(height=0,
                                 row=0,
                                 column=0,
                                 move_type=state.BLACK)
    red_move = state.get_index(height=0, row=0, column=0, move_type=state.RED)
    white_move = state.get_index(height=0,
                                 row=0,
                                 column=0,
                                 move_type=state.WHITE)

    assert black_move == 0
    assert red_move == 30
    assert white_move == 0
コード例 #7
0
def test_valid_colours_no_red():
    state = SpireState("""\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 R . . . 1
  A C E G
>B
""")
    expected_colours = (state.BLACK, )

    colours = state.get_valid_colours()

    assert colours == expected_colours
コード例 #8
0
def test_move_red():
    expected_display2 = """\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 R . . . 1
  A C E G
>B
"""
    state1 = SpireState()

    state2 = state1.make_move(30)
    display2 = state2.display()

    assert display2 == expected_display2
コード例 #9
0
def test_move_black():
    expected_display2 = """\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 B . . . 1
  A C E G
>W,R
"""
    state1 = SpireState()

    state2 = state1.make_move(0)
    display2 = state2.display()

    assert display2 == expected_display2
コード例 #10
0
def test_start():
    expected_display = """\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 . . . . 1
  A C E G
>B,R
"""
    state = SpireState()

    display = state.display()
    active_player = state.get_active_player()

    assert display == expected_display
    assert active_player == state.BLACK
コード例 #11
0
def test_winner():
    text = """\
  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 . . . 6

 4 . R . 4

 2 . . . 2
   B D F
>B
"""
    state = SpireState(text)

    assert state.is_ended()
    assert state.get_winner() == state.WHITE
    assert state.is_win(state.WHITE)
    assert not state.is_win(state.BLACK)
コード例 #12
0
def test_higher_level(start: int, end: int, expected_valid: bool, reason: str):
    board = SpireState("""\
  A C E G
7 B W B R 7

5 W R R W 5

3 B W B R 3

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

 4 . . . 4

 2 B B R 2
   B D F
>B,R
""")
    valid_moves = board.get_valid_moves()
    for move in range(start, end):
        assert valid_moves[move] == expected_valid, move
コード例 #13
0
 def __init__(self):
     start_state = SpireState()
     super().__init__(start_state)
     self.visible_move_types = (start_state.BLACK, start_state.RED,
                                start_state.WHITE)