def hover_square(self, screen, game_board, player): mouseposition = pygame.mouse.get_pos() board = game_board.get_board() radius = int(self.spacing * 0.45) pos_x = mouseposition[0] - (mouseposition[0] - self.padding) % self.spacing pos_y = mouseposition[1] - (mouseposition[1] - self.padding) % self.spacing square = pygame.draw.rect( screen, (255, 255, 255), [pos_x + 1, pos_y + 1, self.spacing - 2, self.spacing - 2]) col = int((pos_x - self.padding) // self.spacing) row = int((pos_y - self.padding) // self.spacing) if square.collidepoint(mouseposition): if row >= 0 and row < len(board) and col >= 0 and col < len(board): if board[row][col] == 0: if player == 1: pygame.draw.circle(screen, (0, 0, 0), ((pos_x + int(self.spacing * 0.5), pos_y + int(self.spacing * 0.5))), radius, 1) else: pygame.draw.circle(screen, (0, 0, 0), ((pos_x + int(self.spacing * 0.5), pos_y + int(self.spacing * 0.5))), radius, 0)
def draw_pieces(self, screen, game_board): board = game_board.get_board() radius = round(0.45 * self.spacing) pos_x = self.padding + int(0.5 * self.spacing) pos_y = self.padding + int(0.5 * self.spacing) for row in board: for col in row: if col == 1: pygame.draw.circle(screen, (0, 0, 0), (pos_x, pos_y), radius, 1) elif col == -1: pygame.draw.circle(screen, (0, 0, 0), (pos_x, pos_y), radius, 0) pos_x += self.spacing pos_x = self.padding + int(0.5 * self.spacing) pos_y += self.spacing
[(row_index, col_index)], []) # gb.display_knowledge_base(knowledge_base) # gb.visualize_agent_board(game_board) explored_count, unexplored_cells, undiscovered_mines, score, knowledge_base = \ run_baseline(board, fringe, explored_count, unexplored_cells, undiscovered_mines, dim, score, knowledge_base, clue_prob) if explored_count == dim * dim: end_time = time.time() return score, random_picks, end_time - start_time end_time = time.time() return score, random_picks, end_time - start_time # Main code dimension = 40 density = 0.2 no_of_mines = int(dimension * dimension * density) # print "No of mines: ", no_of_mines clue_prob = 0.7 game_board = gb.get_board(dimension, no_of_mines) # gb.visualize_board(game_board) knowledge_base = {} score, random_picks, exec_time = start_baseline(game_board, no_of_mines, knowledge_base, clue_prob) # print "Game over! Score: " + str(score) + "/" + str(no_of_mines) # print "Agent accuracy: ", float(score)/no_of_mines*100, "%" # print "Random picks: ", random_picks # print "Exec time: ", exec_time
] analysis_df = pd.DataFrame(columns=column_name_list) iterations = 1 for dim in dim_array: print "dim", dim y_baseline = [] y_inference = [] for density in density_array: print "density", density mines = int(math.floor(dim * dim * density)) print "mines", mines total_score_percent = total_exec_time = total_random_picks = 0 total_score_percent_inf = total_exec_time_inf = total_random_picks_inf = 0 for k in range(iterations): print "Iteration", k game_board = gb.get_board(dim, mines) board1 = copy.deepcopy(game_board) board2 = copy.deepcopy(game_board) score, random_picks, exec_time = bl.start_baseline(board1) score_inf, random_picks_inf, exec_time_inf = inf.start_baseline( board2) print "BASELINE- score: ", score, ", random picks: ", random_picks, ", exec time: ", exec_time print "INFERENCE- score: ", score_inf, ", random picks: ", random_picks_inf, ", exec time: ", exec_time_inf score_percent = float(score) * 100 / mines total_score_percent += score_percent total_exec_time += exec_time total_random_picks += random_picks score_percent_inf = float(score_inf) * 100 / mines total_score_percent_inf += score_percent_inf
dim = len(board) unexplored_cells = get_unexplored_cells(dim, board) undiscovered_mines = total_mines while True: (row_index, col_index) = get_random_cords(unexplored_cells) random_picks += 1 print "Random cell picked: ", row_index, col_index fringe = [(row_index, col_index)] board, undiscovered_mines = query_cell(row_index, col_index, board, undiscovered_mines) explored_count += 1 unexplored_cells.remove((row_index, col_index)) if undiscovered_mines == 0: for cell in unexplored_cells: board, undiscovered_mines = \ query_cell(cell[0], cell[1], board, undiscovered_mines) # gb.visualize_agent_board(game_board) explored_count, unexplored_cells, undiscovered_mines, score = \ run_baseline(board, fringe, explored_count, unexplored_cells, undiscovered_mines, dim, score) if explored_count == dim * dim: return score, random_picks, time.time() - start_time return score, random_picks, time.time() - start_time # Main Code dimension = 5 total_mines = 10 game_board = gb.get_board(dimension, total_mines) # gb.visualize_board(game_board) score, random_picks, exec_time = start_baseline(game_board, total_mines) print "Game over! Score: " + str(score) + "/" + str(total_mines)