Ejemplo n.º 1
0
def random_to_random():
    win_num = 0
    for j in range(10000):
        pos = Position(empty_board,'A',0,-1)
        step = 0
        while True:
            try:
                index = pos.pick_move()[0]
            except Exception:
                win_num+=0.5
                break
            pos = pos.move(index)
            if pos.reward()!=0:
                win_num+=1
                break
            try:
                index2 = pos.pick_move()[0]
            except Exception:
                win_num+=0.5
                break
            pos = pos.move(index2)
            if pos.reward()!=0:
                break
            step+=1
            if step>=N*N:
                win_num+=0.5
    pos.show()
    return win_num/100.0
Ejemplo n.º 2
0
def evaluate_random(net):
    win_num = 0
    for j in range(100):
        pos = Position(empty_board,'A',0,-1)
        step = 0
        while True:
            pos_array = encode_position(pos)
            pos_array_new = np.expand_dims(pos_array,axis=0)
            dis = net.predict_distribution(pos_array_new)
            index = np.argmax(dis)
            while index<N*N and pos.board[index]!='.':
                dis[index] = 0.0
                index = np.argmax(dis)
            if index == N*N:
                index = pos.pick_move()[0]
            if pos.board[index]!='.':
                win_num+=0.5
                break
            
            pos = pos.move(index)
            if pos.reward()!=0:
                win_num+=1
                break
            try:
                index2 = pos.pick_move()[0]
            except Exception:
                win_num+=0.5
                break
            pos = pos.move(index2)
            if pos.reward()!=0:
                break
            step+=1
            if step>=N*N:
                win_num+=0.5
    pos.show()
    return win_num/100.0
Ejemplo n.º 3
0
@author: ubuntu
"""

from mcts import encode_position, TreeNode
from board import Position, make_board, empty_board
from net import GobangModel

p0 = Position(make_board(empty_board), 'a', 0, -1)
p0.show()
x = encode_position(p0)
print x[10:15, 0, 0]
print x[10:15, 0, 1]
print x[10:15, 0, 2]

p1 = p0.move(18)
y = encode_position(p1)
print y[10:15, 0, 0]
print y[10:15, 0, 1]
print y[10:15, 0, 2]

p2 = p1.move(37)
z = encode_position(p2)
print z[10:15, 0, 0]
print z[10:15, 0, 1]
print z[10:15, 0, 2]

net = GobangModel
t0 = TreeNode(net, p0)
print list(p0.moves())
Ejemplo n.º 4
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Oct  7 16:56:36 2018

@author: ubuntu
"""

from board import make_board, Position, empty_board

p0 = Position(empty_board, 'A', 0, -1)
p0.show()
print '==========='
p1 = p0.move(0)
p1.show()
print '==========='
p2 = p1.move(1)
p2.show()
print '==========='
p3 = p2.move(2)
p3.show()
print '==========='
board = make_board(empty_board)
p4 = Position(board, 'A', 10, -1)
p4.show()
p5 = p4.flip_clock()
print '==========='
p5.show()
print '==========='
p6 = p4.flip_reverse_clock()
p6.show()