예제 #1
0
# loading database from pickle file
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:
예제 #2
0
from game_engine import GameStatus
from game_engine import GameEngine
from ai import AI
import pickle
import time
import numpy as np
import config

config.init()
ai1 = AI(1)
ai2 = AI(2, dont_use_nn=True)
game = GameEngine()
game.reset_game()
game.show_board()
# lets put two ais in front of each other:
while game.get_game_status() == GameStatus.IN_PROGRESS:
    board, player = game.get_game_state()
    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("Consumed %sB memory" % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
# ValueEstimator(5, 42, 10)