Beispiel #1
0
def test_azul_is_end_of_game():
    game = Azul()
    #Test moves that should not result in end of game
    game.import_JSON(script_dir + "/resources/game_end_of_round_2.json")
    assert not game.is_end_of_game()
    game.move(0, 4, 1)
    game.next_player()
    game.move(0, 0, 3)
    game.count_score()
    assert not game.is_end_of_game()
    #Test moves that should result in end of game after score has been counted
    game.import_JSON(script_dir + "/resources/game_end_of_round_2.json")
    game.move(0, 0, 1)
    game.next_player()
    game.move(0, 4, 1)
    game.count_score()
    assert game.is_end_of_game()
Beispiel #2
0
def test_azul_count_score():
    game = Azul()
    #Check that the players get the correct score when no bonuses are applied and that the pattern lines and well end up in the right state
    game.import_JSON(script_dir + "/resources/game_end_of_round_1.json")
    prev_score = np.copy(game.score)
    game.count_score()
    assert np.array_equal(
        game.score, prev_score + np.array([5 + 5 + 1 - 2, 4 + 2 + 3 - 8]))
    #Check that the floor has been emptied
    assert np.array_equal(game.floors, np.zeros(2))
    #Check that full pattern lines have been emptied
    assert np.array_equal(
        game.pattern_lines[0],
        np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 2, 0, 0],
                  [0, 0, 0, 0, 0], [0, 0, 3, 0, 0]]))
    assert np.array_equal(
        game.pattern_lines[1],
        np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                  [2, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))
    #Check that walls have gotten their corresponding tiles
    assert np.array_equal(
        game.walls[0],
        np.array([[1, 1, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0],
                  [0, 1, 0, 0, 1], [0, 0, 0, 0, 0]]))
    assert np.array_equal(
        game.walls[1],
        np.array([[1, 1, 1, 1, 0], [0, 0, 0, 0, 1], [0, 0, 1, 0, 0],
                  [0, 1, 0, 0, 0], [1, 1, 0, 0, 0]]))
    #Check that the algorithm works when a wall tile is added in the same round
    game.import_JSON(script_dir + "/resources/game_end_of_round_1.json")
    prev_score = np.copy(game.score)
    game.move(0, 3, 3)
    game.count_score()
    assert np.array_equal(
        game.score, prev_score + np.array([5 + 5 + 1 - 2, 4 + 2 + 3 + 3 - 8]))
    #Check that algorithm can gives score for color and column combos
    game.import_JSON(script_dir + "/resources/game_end_of_round_2.json")
    prev_score = np.copy(game.score)
    game.move(0, 4, 1)
    game.next_player()
    game.move(0, 0, 3)
    game.count_score()
    assert np.array_equal(game.score,
                          prev_score + np.array([5 + 7 + 10, 5 + 7]))
    #Check that algorithm can gives score for rows
    game.import_JSON(script_dir + "/resources/game_end_of_round_2.json")
    prev_score = np.copy(game.score)
    game.move(0, 0, 1)
    game.next_player()
    game.move(0, 4, 1)
    game.count_score()
    assert np.array_equal(game.score, prev_score + np.array([2 - 2, 5 + 2]))
    #Check that you can't go below 0 points
    game.import_JSON(script_dir + "/resources/game_end_of_round_2.json")
    game.move(0, 0, 0)
    game.next_player()
    game.move(0, 4, 0)
    game.count_score()
    assert np.array_equal(game.score, np.array([0, 0]))
Beispiel #3
0
def test_azul_next_player():
    #In a two player game, the order of the first round goes 1,2,1
    game = Azul()
    game.new_round()
    assert game.current_player == 1
    game.next_player()
    assert game.current_player == 2
    game.next_player()
    assert game.current_player == 1
    #In a four player game, the order of the first round goes 1,2,1
    game = Azul(players=4)
    game.new_round()
    assert game.current_player == 1
    game.next_player()
    assert game.current_player == 2
    game.next_player()
    assert game.current_player == 3
    game.next_player()
    assert game.current_player == 4
    game.next_player()
    assert game.current_player == 1