Esempio n. 1
0
def test_random_player_generate_move() -> None:
    """ Test the RandomPlayer class' generate_move method. """
    goal = BlobGoal((0, 0, 0))
    player1 = RandomPlayer(1, goal)
    player1._proceed = True
    b1 = Block((0, 0), 1000, (0, 0, 0), 0, 2)

    move1 = player1.generate_move(b1)

    assert isinstance(move1, tuple) and isinstance(move1[0], str) and \
           (isinstance(move1[1], int) or move1[1] is None) and \
           isinstance(move1[2], Block)

    if move1[0:2] == ('rotate', 1):
        assert move1[2].rotate(1)
    elif move1[0:2] == ('rotate', 3):
        assert move1[2].rotate(3)
    elif move1[0:2] == ('swap', 0):
        assert move1[2].swap(0)
    elif move1[0:2] == ('swap', 1):
        assert move1[2].swap(1)
    elif move1[0:2] == ('smash', None):
        assert move1[2].smash()
    elif move1[0:2] == ('paint', None):
        assert move1[2].paint(self.goal.colour)
    elif move1[0:2] == ('combine', None):
        assert move1[2].combine()
    else:
        assert False
Esempio n. 2
0
def test_depth_5_board(renderer):
    random.seed(1002)
    board = generate_board(5, BOARD_SIZE)
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_ref.png')
    renderer.clear()
    goal1 = BlobGoal(COLOUR_LIST[0])  # blue
    goal2 = BlobGoal(COLOUR_LIST[1])  # red
    player1 = RandomPlayer(1, goal1)
    player2 = RandomPlayer(2, goal2)
    player1._proceed = True
    move1 = player1.generate_move(board)
    move1_block = move1[2]
    to_do = _get_block(board, move1_block.position, move1_block.level)
    assert move1[0] == "swap" and move1[1] == 0
    assert to_do.swap(0)
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_move1.png')
    renderer.clear()
    afterfirst1 = goal1.score(board)
    afterfirst2 = goal2.score(board)
    player2._proceed = True
    move2 = player2.generate_move(board)
    move2_block = move2[2]
    to_do_2 = _get_block(board, move2_block.position, move2_block.level)
    assert move2[0] == "smash"
    assert to_do_2.smash()
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_move2.png')
    renderer.clear()
    aftersecond1 = goal1.score(board)
    aftersecond2 = goal2.score(board)
    player1._proceed = True
    move3 = player1.generate_move(board)
    move3_block = move3[2]
    to_do_3 = _get_block(board, move3_block.position, move3_block.level)
    assert move3[0] == "rotate" and move3[1] == 3
    assert to_do_3.rotate(3)
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_move3.png')
    renderer.clear()
    afterthird1 = goal1.score(board)
    afterthird2 = goal2.score(board)
 def test_smart_player(self, board_16x16) -> None:
     goal_smart = PerimeterGoal(COLOUR_LIST[1])
     player_smart = SmartPlayer(1, goal_smart, 1)
     print(player_smart.difficulty)
     goal_random = PerimeterGoal(COLOUR_LIST[0])
     player_random = RandomPlayer(10, goal_random)
     random_move = player_random.generate_move(board_16x16)
     #player_smart._proceed = True
     #x = player_smart.generate_move(board_16x16)
     assert 1
Esempio n. 4
0
def test_player(game_board2):
    random.seed(1)
    goal = BlobGoal(COLOUR_LIST[1])
    player = RandomPlayer(1, goal)
    player._proceed = True
    move = player.generate_move(game_board2)
    print(move)
    player2 = SmartPlayer(1, goal, 100)
    player2._proceed = True
    move2 = player2.generate_move(game_board2)
    print(move2)
Esempio n. 5
0
def test_unit_board():
    random.seed(1)
    board = generate_board(1, BOARD_SIZE)
    goal = BlobGoal(COLOUR_LIST[1])
    player = RandomPlayer(1, goal)
    player._proceed = True
    move = player.generate_move(board)
    print(move)
    player2 = SmartPlayer(1, goal, 1)
    player2._proceed = True
    move2 = player2.generate_move(board)
    print(move2)
Esempio n. 6
0
def test_generate_move_random_player() -> None:
    b2 = generate_board(3, 750)
    P = RandomPlayer(2, PerimeterGoal(COLOUR_LIST[2]))
    P._proceed = True
    assert P.generate_move(b2)[0] in ['swap', 'rotate',
                                      'paint', 'combine', 'smash']