try: new_file = open("database_dump.pkl", "rb") database = pickle.load(new_file) new_file.close() except: database = [] new_file = open("database_dump.pkl", "wb") pickle.dump(database, new_file) new_file.close() batch = [] while time.time() - train_start_time < running_train_time: game.reset_game() batch.clear() while game.get_game_status() == GameStatus.IN_PROGRESS: board, player = game.get_game_state() batch.append(board) if player == 1: action = ai1.select_action(board) else: action = ai2.select_action(board) game.register_action(player, action) # we now have a complete history of a game between two ais: # we now update the database: game_value = 0 if game.get_game_status() is GameStatus.WINED_BY_P1: game_value = 1 elif game.get_game_status() is GameStatus.WINED_BY_P2: game_value = -1 # for state in batch: # database.index()
# creating a new game and two ais: ai1 = AI(1) ai2 = AI(2) game = GameEngine() # game.show_board() # lets put two ais in front of each other: T = 0 database = {} batch = [] while T < 50000: game.reset_game() batch.clear() while game.get_game_status() == GameStatus.IN_PROGRESS: T += 1 board, player = game.get_game_state() batch.append(board) if player == 1: action = ai1.select_action(board) else: action = ai2.select_action(board) # action = int(input("select a column to drop your block: ")) game.register_action(player, action) # print("player {} took action {}".format(player, action)) # game.show_board() print("game state {}".format(game.get_game_status())) print("game took {} number of steps".format(T)) for board in batch: database.setdefault(board, 0) database[board][0] += 1 if game.get_game_state() == GameStatus.WINED_BY_P1: