Beispiel #1
0
from player import Player, Player_keras, Player_fast, Player_random  # , ANN_Player
import gomoku_alpha_beta_ai as alpha_beta
import parameters
import game
import time

N_GAMES = 10
game_nr = 0

new_ai_win, new_ai_loose = 0, 0

super_start_time = time.time()

game = game.GomokuGame(parameters.DEFAULT_SIZE)
player1 = Player_keras(game.FIRST_PLAYER, random_start=parameters.RANDOM_START)     # BLACK
player2 = Player_fast(game.getOtherPlayer(game.FIRST_PLAYER))                       # WHITE

for i in range(N_GAMES):
    start_time = time.time()
    print("Starting test nr", game_nr)

    # player2 = Player(game.getOtherPlayer(game.FIRST_PLAYER))

    # layer_sizes = [400, 10, 1]

    # weights, biases = new_ann.convert_all_to_weights_biases(layer_sizes, arr)
    # ann = new_ann.neuralnetwork(weights, biases, layer_sizes, activation=[nnet.sigmoid, nnet.sigmoid, nnet.sigmoid])
    # ann_player = ANN_Player(game.getOtherPlayer(game.FIRST_PLAYER), ann)

    move_nr = 1
Beispiel #2
0
# Loop until the user clicks the close button.
done = False

# Used to manage how fast the screen updates
clock = pygame.time.Clock()

game = game.GomokuGame(parameters.DEFAULT_SIZE)
col_size = int(size[0] / game.size[0])
row_size = int(size[1] / game.size[1])
cell_padding = 1

ai_turn = parameters.AI_FIRST
p1 = Player_fast(game.FIRST_PLAYER, random_start=parameters.RANDOM_START)
# player = Player(game.FIRST_PLAYER, random_start=parameters.RANDOM_START)
# player = ANN_Player(game.FIRST_PLAYER, new_ann.loadNeuralNetwork(), random_start=parameters.RANDOM_START)
other_color = game.getOtherPlayer(p1.color)
p2 = None
if parameters.AI_VS_AI:
    p2 = Player_fast(other_color)

# -------- Main Program Loop -----------
while not done:
    # --- Main event loop
    if parameters.PLAY_WITH_AI and ai_turn:
        move = ai.rootAlphaBeta(game, parameters.DEFAULT_ALPHA_BETA_DEPTH, p1)
        validMove = game.doMove(p1.color, move)
        if validMove:
            ai_turn = False
            print("AI --> X:", move[0], "Y:", move[1])

    if parameters.PLAY_WITH_AI and parameters.AI_VS_AI and not ai_turn: