This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NUMBER_OF_GAMES = 5000 | |
begintime = time.time() | |
for game in range(NUMBER_OF_GAMES): | |
board_log, action_log, probs_log, result = play_game() | |
all_boards.append(board_log[-1][-1]) | |
all_actions.append(action_log) | |
all_probs.append(probs_log) | |
if (game + 1) % math.floor(NUMBER_OF_GAMES / 100) == 0 and game > 0: | |
time_passed = math.floor(time.time() - begintime) | |
print(str(game) + " / " + str(NUMBER_OF_GAMES) + \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
botName = 'yourbotname' | |
from random import randint | |
from random import choice | |
import tensorflow as tf | |
import numpy as np | |
import time | |
import datetime | |
import math | |
import requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def benchmark(games = 100): | |
wins = draws = losses = 0 | |
for i in range(games): | |
player_index = 0 | |
player_ids = ["p0", "p1"] | |
result = initialise(player_index, player_ids, BOARD_SIZE) | |
# Initialise logs for game | |
board_log = [] | |
action_log = [[], []] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(benchmark(1000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def guess_move(current_board, possible_moves, training): | |
probs = session.run(probabilities, feed_dict={input_positions:[[cell for row in current_board for cell in row]]})[0] | |
possible_moves = [move[0] * BOARD_SIZE[1] + move[1] for move in possible_moves] | |
probs = [p if index in possible_moves else 0 for index, p in enumerate(probs)] | |
probs = [round(p, 6) for p in probs] | |
if sum(probs) > 0: | |
probs = [p / sum(probs) for p in probs] | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aigamingReversingStones | |
import tensorflow as tf | |
import numpy as np | |
import time | |
import datetime | |
import math | |
from random import randint | |
from random import choice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONFIGURATIONS = [[8, 8], [14, 8], [4, 4]] | |
USE_CONFIGURATION = 0 | |
BOARD_SIZE = CONFIGURATIONS[USE_CONFIGURATION] | |
print("Using configuration: \nBoard size: " + str(BOARD_SIZE[0]) + " by " + str(BOARD_SIZE[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputs_units = BOARD_SIZE[0] * BOARD_SIZE[1] | |
hidden_units = BOARD_SIZE[0] * BOARD_SIZE[1] | |
output_units = BOARD_SIZE[0] * BOARD_SIZE[1] | |
def initialise_tf(): | |
global input_positions, labels, learning_rate, W1, b1, h1, W2, b2, logits, probabilities, cross_entropy, train_step | |
input_positions = tf.placeholder(tf.float32, shape=(1, inputs_units)) | |
labels = tf.placeholder(tf.int64) | |
learning_rate = tf.placeholder(tf.float32, shape=[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initialise(player_index, player_ids, board_dimensions): | |
return aigamingReversingStones.initialise(player_index=player_index, player_ids=player_ids, board_dimensions=board_dimensions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_model(name='model.ckpt', games = 100): | |
global session | |
tf.reset_default_graph() | |
initialise_tf() | |
session = tf.Session() | |
tf.train.Saver().restore(session, "./models/" + name) | |
benchmark(games) |
OlderNewer