Пример #1
0
def test_skip_or_finish():
    # test when game is not finished
    othello = Othello(400, 4, "Name", "black")
    othello.update_legal_move()
    othello.skip_or_finish()
    assert not othello.gc.is_finished

    # test when skipping this turn
    othello.board.take_off(1, 1)
    othello.board.take_off(1, 2)
    othello.board.take_off(2, 1)
    othello.board.take_off(2, 2)
    for i in range(4):
        othello.is_black = False
        othello.put_tile_on(0, i)
        if i > 0:
            othello.is_black = True
            othello.put_tile_on(1, i)
    othello.update_legal_move()
    othello.skip_or_finish()
    assert othello.gc.is_skip
    assert not othello.is_black

    othello.control(2, 0)
    othello.update_legal_move()
    othello.skip_or_finish()
    assert not othello.gc.is_skip

    # test whether no empty grids will finish the game
    othello = Othello(400, 2, "Name", "black")
    othello.skip_or_finish()
    assert othello.gc.is_finished

    # test whether no legal moves will finish the game
    othello.board.take_off(0, 0)
    othello.skip_or_finish()
    assert othello.gc.is_finished

    # test whether all tiles are in one color will finish the game
    othello.board.take_off(1, 1)
    othello.skip_or_finish()
    assert othello.gc.is_finished
Пример #2
0
def test_control():
    othello = Othello(400, 4, "Name", "black")

    # test if I can make an illegal move
    othello.update_info()
    othello.control(0, 0)
    assert not othello.board.grids[0][0]
    assert othello.is_black
    assert not othello.is_control

    # test if I can make a legal move
    othello.update_info()
    othello.control(0, 1)
    assert not othello.is_black
    assert othello.is_control

    assert isinstance(othello.board.grids[0][1], Tile)
    assert othello.board.grids[0][1].is_black

    assert isinstance(othello.board.grids[1][1], Tile)
    assert othello.board.grids[1][1].is_black