def __init__(self, xmax, ymax, nb_feux, nb_pompiers): self.board = Board(xmax, ymax, nb_feux) self.pompiers = [ Pompier(i, (random.randint(0, xmax - 1), random.randint(0, xmax - 1)), self.board) for i in range(nb_pompiers) ]
def __init__(self): self.zombies = [Actor.Zombie()] self.plants = [Actor.Plant(), Actor.Plant()] self.Board = Board() #self.plants[0].Position.x = 200 if self.Board.putPlant(0, 1): self.plants[0].setPosition(self.Board.getPosition(0, 1)) if self.Board.putPlant(0, 0): self.plants[1].setPosition(self.Board.getPosition(0, 0))
def default(self): """ input : None function: Create a game environment for default output: None """ self.board = Board(6, 7) self.board.create() self.board_printer = BoardPrinter(self.system, "bringht", "", "white") self.board_printer.load_boar(self.board.column_size)
def test_Check_check_lines_3_in_line_count_3(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', '2', ' ', ' ', ' '], [' ', '1', ' ', '1', ' ', ' ', ' '], [' ', '2', ' ', '2', ' ', ' ', ' '], ['2', '1', ' ', '1', ' ', ' ', ' ']] neighbour_discs = checker.check_lines(board, '2', 3) assert (neighbour_discs == 3)
def test_Block_3_check_verticals_count_Player1_2(): block = Block_3_In_Line_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', '1', ' ', ' ', ' ', ' '], [' ', ' ', '2', ' ', ' ', ' ', '2'], [' ', ' ', '2', ' ', '1', '1', '1'], ['2', '1', '2', '2', '2', '1', '1']] best_move = block.check_verticals_count(board, 4, 4, '1', 2) assert (best_move == True)
def test_check_diagonals_3_in_line_player2(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', '2', '1', ' ', ' ', ' ', ' '], [' ', '1', '2', ' ', ' ', ' ', ' '], ['1', '2', '1', '2', ' ', ' ', ' ']] fout_in_a_row = checker.check_diagonals(board, 0, '2') assert (fout_in_a_row == False)
def test__check_horizontals_6_discs_but_only_1_at_the_right(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', '2', '2', '2', ' ', '2'], ['2', '1', '1', '1', '1', '1', '1']] discs_in_a_row = checker._check_horizontals(board, 5 + 1, 5, '1', True) assert (discs_in_a_row == 1)
def test_minimax_Play_3_in_line(): secuential = Block_3_In_Line(1, '1', '2') board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', '2', ' ', ' '], [' ', '1', '1', '1', '2', ' ', ' ']] best_move = secuential.heuristic(board) assert (best_move == 1200)
def test_minimax_Block3_in_line(): block_3 = Block_3_In_Line(1, '2', '1') board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', '2', '2', '1', ' ']] best_move = block_3.heuristic(board) assert (best_move == 1100)
def test_check_horizontals_count_0_with_2_neighbours_but_search_limit_2(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', '2', ' ', ' ', '2'], ['1', ' ', ' ', '1', ' ', ' ', '1']] neighbour_discs = checker.check_horizontals_count(board, 5, 3, '1', 2) assert (neighbour_discs == 0)
def test_Block_3_check_diagonals_count_3_Player1_only_2_inside_limit(): block = Block_3_In_Line_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', ' ', ' ', ' ', ' ', ' '], ['1', '1', ' ', ' ', ' ', ' ', ' '], ['2', '1', ' ', '1', '2', ' ', ' '], ['1', '2', '1', '1', '2', ' ', ' ']] best_move = block._check_diagonals_count(board, 4, 3, '1', 3, True) assert (best_move == False)
def test__check_diagonals_player2_4_in_diagonal_just_2_up_pos_3_2(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', '2', ' ', ' ', ' ', ' ', ' '], ['1', '1', '2', ' ', ' ', ' ', ' '], ['1', '1', '1', '2', ' ', ' ', ' '], ['2', '1', '2', '1', '2', ' ', ' '], ['2', '2', '2', '1', '2', '1', ' '], ['1', '2', '1', '2', '1', '1', '2']] diagonal_discs = checker._check_diagonals(board, 3 - 1, 2 - 1, '2', True) assert (diagonal_discs == 2)
def test_check_horizontals_count_1_with_0_neighbours(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', '1', ' ', ' ', ' ']] neighbour_discs = checker.check_horizontals_count(board, 5, 3, '1', 0) assert (neighbour_discs == 1)
def test__check_diagonals_player2_4_in_diagonal_just_1_down_pos_3_2(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', '2', ' ', ' ', ' ', ' ', ' '], ['1', '1', '2', ' ', ' ', ' ', ' '], ['1', '1', '1', '2', ' ', ' ', ' '], ['2', '1', '2', '1', '2', ' ', ' '], ['2', '2', '2', '1', '2', '1', ' '], ['1', '2', '1', '2', '1', '1', '2']] diagonal_discs = checker._check_diagonals(board, 3 + 1, 2 + 1, '2', False) assert (diagonal_discs == 1)
def test__check_diagonals_player2_5_in_diagonal_but_not_next_pos_6_5(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', '2', ' ', ' ', ' ', ' ', ' '], ['1', '1', '2', ' ', ' ', ' ', ' '], ['1', '1', '1', '2', ' ', ' ', ' '], ['2', '1', '2', '1', '2', ' ', ' '], ['2', '2', '2', '1', '2', '1', ' '], ['1', '2', '1', '2', '1', '1', '2']] diagonal_discs = checker._check_diagonals(board, 6 - 1, 5 - 1, '2', True) assert (diagonal_discs == 0)
def test_check_diagonals_player1_win_invese_diagonal(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', '1', ' ', ' ', ' ', ' '], ['2', '2', '1', '1', ' ', ' ', ' '], ['2', '1', '2', '1', ' ', ' ', ' '], ['1', '2', '1', '2', ' ', ' ', ' ']] fout_in_a_row = checker.check_diagonals(board, 0, '2') assert (fout_in_a_row == True)
def test_Block_3_check_horizontals_count_3_Player1(): block = Block_3_In_Line_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', '2', ' ', '1', '2', ' ', ' ']] best_move = block.check_horizontals_count(board, 5, 3, '1', 3) assert (best_move == True)
def test_check_diagonals_count_2_with_2_neighbours_search_limit_1_Player2(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', '2', ' ', ' ', ' '], [' ', ' ', '2', '1', ' ', ' ', ' '], [' ', ' ', '1', '2', ' ', ' ', '2'], ['2', '1', '1', '1', ' ', ' ', '1']] neighbour_discs = checker.check_diagonals_count(board, 5, 0, '2', 1) assert (neighbour_discs == 2)
def test_Block_3_check_diagonals_count_2_Player1(): block = Block_3_In_Line_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', '1', '2', ' ', ' '], [' ', '2', ' ', '1', '2', ' ', ' ']] best_move = block._check_diagonals_count(board, 4, 3, '1', 2, True) assert (best_move == True)
def test_check_verticals_count_5_limit_99(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', '1', ' ', ' ', ' ', ' '], ['2', ' ', '2', '1', ' ', ' ', ' '], ['2', '2', '1', '2', ' ', ' ', ' '], ['2', '1', '1', '1', ' ', '1', '1']] neighbour_discs = checker.check_verticals_count(board, 1, 0, '2', 4) assert (neighbour_discs == 1)
def test_Block_3_check_diagonals_count_2(): block = Block_3_In_Line_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', ' ', ' ', ' ', ' ', ' '], ['2', '2', ' ', ' ', ' ', ' ', ' '], ['1', '1', ' ', ' ', '2', ' ', ' '], ['2', '1', ' ', '1', '2', '1', '1'], ['1', '2', '2', '1', '2', '1', '1']] best_move = block.check_diagonals_count(board, 4, 3, '1', 3) assert (best_move == 2)
def test_create(): board = Board(6, 7) board.create() matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ']] assert(board.matrix == matrix)
def test_minimax_Secuential(): secuential = Secuential(1, '1', '2') board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', '2'], [' ', ' ', ' ', ' ', ' ', ' ', '1'], [' ', ' ', '2', ' ', ' ', '1', '1'], ['2', '1', '2', '2', '2', '1', '1']] best_move = secuential.heuristic(board) assert (best_move == 114)
def test__check_horizontals_6_discs_but_only_4_at_the_left(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', '2', '2', '2', ' ', '2'], ['2', '1', '1', '1', '1', '1', '1']] discs_in_a_row = checker._check_horizontals(board, 5 - 1, 5, '1', False) assert (discs_in_a_row == 4)
def test_Secuential_Count_check_verticals(): checker = Secuential_Count_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', '1', ' ', ' ', ' ', ' '], ['2', ' ', '2', '1', ' ', ' ', ' '], ['2', '2', '1', '2', ' ', ' ', ' '], ['2', '1', '1', '1', ' ', '1', '1']] neighbour_discs = checker.check_verticals_count(board, 1, 0, '2', 4) assert (neighbour_discs == 1)
def test__check_horizontals_6_discs_but_an_oponent_disc_in_the_middle(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', '2', '2', '2', ' ', '2'], ['1', '1', '1', '2', '1', '1', '1']] discs_in_a_row = checker._check_horizontals(board, 0 + 1, 5, '1', True) assert (discs_in_a_row == 2)
def Update(self, game): if self.IsClickedByMouse(game): from Board.Board import Board self._newState = Board(game) from datetime import datetime time = str(datetime.now().strftime('%Y-%m-%d-%H-%M')) with open("./savegames/%s.frgame" % time, "wb") as f: pickle.dump(game.Logic, f) nself = super().Update(game) return SaveGameButton(nself.Offset, nself.Image, nself.Hover, nself.Rect, self._newState)
def test_Secuential_Count_check_diagonals(): checker = Secuential_Count_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', ' ', ' ', ' ', ' ', ' '], ['2', ' ', '1', ' ', ' ', ' ', ' '], ['2', ' ', '2', '1', ' ', ' ', ' '], ['2', '2', '1', '2', ' ', ' ', ' '], ['2', '1', '1', '1', ' ', '1', '1']] neighbour_discs = checker.check_diagonals(board, 3, 2, '2', 3) assert (neighbour_discs == 1)
def test_Secuential_Count_check_lines_3_in_line_count_4(): checker = Secuential_Count_Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', '2'], [' ', ' ', ' ', ' ', ' ', ' ', '1'], [' ', ' ', '2', ' ', ' ', '1', '1'], ['2', '1', '2', '2', '2', '1', '1']] neighbour_discs = checker.check_lines(board, '1', 2) assert (neighbour_discs == 14)
def test_horizontals_win_Player1_row_0_all_3_discs_at_the_right(): checker = Checker() board = Board(6, 7) board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', '2', '2', ' ', ' ', ' '], [' ', '1', '1', '1', '1', '2', ' ']] four_in_a_row = checker.check_horizontals(board, 1, '1') assert (four_in_a_row == True)