Skip to content

Commit

Permalink
fix: 🚧 Board and heuristic agent result tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
oystkva committed Apr 16, 2024
1 parent 0c3a13a commit a4e0959
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
38 changes: 33 additions & 5 deletions test/agents/test_heuristic_agent.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from src.agents.agent_factory import create_agent
from src.agents.heuristic_agent import HeuristicAgent
from src.game.tetris import Action, Tetris
from src.agents.agent import Agent, play_game
from src.agents.heuristic_agent import HeuristicAgent
from src.game.block import Block

def test_result_heuristic_agent():


initBoard = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand All @@ -29,13 +28,42 @@ def test_result_heuristic_agent():
[1, 1, 1, 1, 1, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 0, 1, 1, 1, 1],
]
block=Block(3,0,1)

expected_board = [
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
[1, 1, 1, 1, 1, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 0, 1, 1, 1, 1],
]

block = Block(3,0,1)
board = Tetris(initBoard, block)

agent: Agent = create_agent("heuristic")
agent: HeuristicAgent = create_agent("heuristic")
possible_moves = board.getPossibleBoards()
result = agent.result(board)
for i in range(len(result)-1):
board.doAction(result[i])
print(result)
assert [] == result
for row in board.board:
print(row)
print('\n')
assert (board.board == expected_board)

#end_board = play_game(agent, game, 7)
3 changes: 0 additions & 3 deletions test/game/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ def test_try_to_move_block_out_of_bound_left():

for _ in range(board.COLUMNS + 1):
board.doAction(Action.MOVE_LEFT)
for row in board.board:
print(row)
print('\n')

for board_row, expected_row in zip(board.board, expected_board):
assert board_row == expected_row
Expand Down
8 changes: 5 additions & 3 deletions test/game/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ def test_get_possible_boards_for_line():
i_block = Block(0, 3, 0)
board: Tetris = Tetris(block=i_block)
possible_boards = board.getPossibleBoards()
for board in possible_boards:
board.printBoard()
assert isinstance(possible_boards, list)
for move in possible_boards:
assert isinstance(move, Tetris)

standing_up_right = 9
standing_up_right = 10
laying_down_right = 7
assert len(possible_boards) == standing_up_right + laying_down_right

Expand All @@ -26,7 +28,7 @@ def test_get_possible_moves_for_square():
for move in possible_moves:
assert isinstance(move, Tetris)

assert len(possible_moves) == 8
assert len(possible_moves) == 9


def test_board_equal_for_the_same_object():
Expand Down Expand Up @@ -184,7 +186,7 @@ def test_transition_model_for_no_transition():

actions = transition_model(current_board, target_board)
assert isinstance(actions, list)
assert len(actions) == 0
assert len(actions) == 1


def test_transition_model_x_direction():
Expand Down

0 comments on commit a4e0959

Please sign in to comment.