def test_player_token_locations(): player_id = 'hello' player = MockPlayer(player_id) board = Board() board.board[1][1] = player_id board.board[2][1] = player_id board.board[2][2] = 'not player id' board.board[2][4] = player_id board.board[5][5] = player_id expected = [(1, 1), (2, 1), (2, 4), (5, 5)] assert expected == list(util.player_token_locations(board, player))
def __init__(self, player_one, player_two, board_height, board_width, fast_play=False, auto_close=False): self.player_one = player_one self.player_two = player_two self.current_player = self.player_one self.player_one.id = self.PLAYER_ONE_ID self.player_two.id = self.PLAYER_TWO_ID self.board = Board(height=board_height, width=board_width) self.fast_play = fast_play self.exit_on_game_end = auto_close self.metrics = {'num_moves': 0, 'all_moves': []}
def reset(self): self.board = Board(height=self.board.height, width=self.board.width) self.current_player = self.player_one
def test_terminal_on_unfinished_game(self): board = Board() assert not board.terminal() board.board[1][1] = 1 assert not board.terminal()
def test__num_of_winning_zones(self): board = Board() expected = 69 assert expected == board._num_of_winning_zones(num_to_connect=4)
def test__build_winning_zones_map(self): board = Board() zones_map = board._build_winning_zones_map() default_seven_by_size_zones_map = [ [ [0, 24, 45], [4, 24, 25, 49], [8, 24, 25, 26, 53], [12, 24, 25, 26, 60], [16, 25, 26, 64], [20, 26, 68], ], [ [0, 1, 27, 46], [4, 5, 27, 28, 45, 50], [8, 9, 27, 28, 29, 49, 54, 60], [12, 13, 27, 28, 29, 53, 59, 64], [16, 17, 28, 29, 63, 68], [20, 21, 29, 67], ], [ [0, 1, 2, 30, 47], [4, 5, 6, 30, 31, 46, 51, 60], [8, 9, 10, 30, 31, 32, 45, 50, 55, 59, 64], [12, 13, 14, 30, 31, 32, 49, 54, 58, 63, 68], [16, 17, 18, 31, 32, 53, 62, 67], [20, 21, 22, 32, 66], ], [ [0, 1, 2, 3, 33, 48, 60], [4, 5, 6, 7, 33, 34, 47, 52, 59, 64], [8, 9, 10, 11, 33, 34, 35, 46, 51, 56, 58, 63, 68], [12, 13, 14, 15, 33, 34, 35, 45, 50, 55, 57, 62, 67], [16, 17, 18, 19, 34, 35, 49, 54, 61, 66], [20, 21, 22, 23, 35, 53, 65], ], [ [1, 2, 3, 36, 59], [5, 6, 7, 36, 37, 48, 58, 63], [9, 10, 11, 36, 37, 38, 47, 52, 57, 62, 67], [13, 14, 15, 36, 37, 38, 46, 51, 56, 61, 66], [17, 18, 19, 37, 38, 50, 55, 65], [21, 22, 23, 38, 54], ], [ [2, 3, 39, 58], [6, 7, 39, 40, 57, 62], [10, 11, 39, 40, 41, 48, 61, 66], [14, 15, 39, 40, 41, 47, 52, 65], [18, 19, 40, 41, 51, 56], [22, 23, 41, 55], ], [ [3, 42, 57], [7, 42, 43, 61], [11, 42, 43, 44, 65], [15, 42, 43, 44, 48], [19, 43, 44, 52], [23, 44, 56], ], ] assert zones_map == default_seven_by_size_zones_map
from connectfour.agents.agent_student import StudentAgent from connectfour.board import Board import numpy as np agent_student = StudentAgent("Sample Name") agent_student.id = 1 agent_student2 = StudentAgent("Agent 2") agent_student2.id = 2 simple_board = Board() # for j in range(1): # for i in range(2): # simple_board = simple_board.next_state(agent_student.id, i) # simple_board = simple_board.next_state(agent_student.id, 3) # simple_board = simple_board.next_state(agent_student.id, 2) # # simple_board = simple_board.next_state(agent_student.id % 2 + 1, 3) # simple_board = simple_board.next_state(agent_student.id % 2 + 1, 2) # simple_board = simple_board.next_state(agent_student.id, 3) # simple_board = simple_board.next_state(agent_student.id, 3) simple_board.board = [[0, 0, 1, 1, 2, 0, 2], [0, 0, 2, 1, 2, 0, 1], [0, 1, 2, 2, 1, 0, 2], [1, 2, 1, 1, 1, 0, 1], [2, 1, 2, 1, 2, 0, 2], [2, 2, 2, 1, 2, 1, 1]] print(np.matrix(simple_board.board)) print("Player 1:") #print(agent_student.evaluateBoardState(simple_board))