예제 #1
0
def test_judge_game():
    othello = Othello(400, 4, "Name", "black")

    # assert the draw
    othello.judge_game()
    assert not othello.gc.black_wins
    assert not othello.gc.white_wins
    assert othello.gc.draw
    assert othello.gc.white_num == 2
    assert othello.gc.black_num == 2

    # assert black wins
    othello.put_tile_on(0, 0)
    othello.judge_game()
    assert othello.gc.black_wins
    assert not othello.gc.white_wins
    assert not othello.gc.draw
    assert othello.gc.white_num == 2
    assert othello.gc.black_num == 3

    # assert white wins
    othello = Othello(400, 4, "Name", "black")
    othello.is_black = False
    othello.put_tile_on(0, 0)
    othello.judge_game()
    assert not othello.gc.black_wins
    assert othello.gc.white_wins
    assert not othello.gc.draw
    assert othello.gc.white_num == 3
    assert othello.gc.black_num == 2
예제 #2
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
예제 #3
0
def test_put_tile_on():
    othello = Othello(400, 4, "Name", "black")
    tile = Tile(100)

    othello.put_tile_on(0, 0)
    assert othello.board.grids[0][0] == tile

    othello.is_black = False
    othello.put_tile_on(0, 0)
    tile.flip()
    assert othello.board.grids[0][0] == tile