Esempio n. 1
0
def playPyramido(human=0, iterations=1000):
    movenumber = 1
    position = PyramidoPosition(toArray(1))
    player = 1
    while possible_moves(position):
        if player == human:
            position = humanPickMove(position)
        else:
            position = computerPickMove(position, iterations)
        print('Move %d: Player %d moves to\n%s'
                % (movenumber, player, str(position)))
        movenumber += 1
        player = 3 - player
Esempio n. 2
0
 def policy(position):
     moves = possible_moves(position)
     if not moves:
         return {}, leaf_node_value(position)
     moves_nn_format = [m.nn_format() for m in moves]
     scores = y.eval(feed_dict={
         x: moves_nn_format,
         keep_prob: 1.0
     }).flatten()
     probability = {}
     for i, m in enumerate(moves):
         probability[m] = scores[i]
     return probability, max(probability.values())
Esempio n. 3
0
def generate_one_game(policy, num_iterations=100):
    x = []
    y_ = []
    position = PyramidoPosition(toArray(1))
    movenumber = 1
    player = 1
    while possible_moves(position):
        dist, _ = MCTS(policy, position, num_iterations)
        max_probability = max(dist.values())
        for move, probability in dist.items():
            x.append(move)
            y_.append(probability)
            if probability == max_probability:
                position = move
                print('Move %d: Player %d moves with value %f to\n%s' %
                      (movenumber, player, probability, str(position)))
                movenumber, player = movenumber + 1, 3 - player
    return zip(x, y_)
Esempio n. 4
0
def pyramido_policy(position):
    moves = possible_moves(position)  # game must define this
    bottom_row_moves = []
    other_moves = []
    for m in moves:
        if np.logical_and.reduce(m.array()[0] == position.array()[0]):
            other_moves.append(m)
        else:
            bottom_row_moves.append(m)

    bottom_row_weight = 1.0
    if not other_moves:
        bottom_row_weight = 1.0
    if not bottom_row_moves:
        bottom_row_weight = 0.0

    distribution = {}
    for m in bottom_row_moves:
        distribution[m] = bottom_row_weight / len(bottom_row_moves)
    for m in other_moves:
        distribution[m] = (1.0 - bottom_row_weight) / len(other_moves)
    return distribution, val(position)
Esempio n. 5
0
def pol(position):
    distribution = {}
    moves = possible_moves(position)  # game must define this
    for m in moves:
        distribution[m] = 1.0 / len(moves)
    return distribution, val(position)
Esempio n. 6
0
def humanPickMove(position):
    moves = possible_moves(position)
    for i, m in enumerate(moves):
        print('Option %d:\n%s\n' % (i, str(m)))
    selection = int(input('Selection:\n'))
    return moves[selection]