示例#1
0
文件: xdebug.py 项目: xw213400/halogo
def main(step):
    records = []
    with open('../data/record.json') as json_data:
        records = json.load(json_data)

    sys.setrecursionlimit(500000)
    go.init(9)
    pars = '../data/resnet_pars.pkl'
    policy = resnet.Policy(0.5, pars)

    parent = go.Position()
    position = go.Position()

    if step > 0:
        parent.fromJSON(records[step - 1])
    position.fromJSON(records[step])

    position.parent = parent

    policy.input_board(parent)

    x = Variable(resnet.INPUT_BOARD)
    out = policy.resnet(x)[0].data.numpy()

    print('next:', parent.next)
    parent.debug()

    i = go.N
    s = "\n"
    while i > 0:
        i -= 1
        j = 0
        while j < go.N:
            c = out[i * go.N + j]
            j += 1
            if c < 0:
                s += '\033[32m%03d \033[0m' % int(-c * 10)
            else:
                s += '\033[31m%03d \033[0m' % int(c * 10)
        s += "\n\n"

    print(s)
    print(out[go.LN - 1])
示例#2
0
def main(epoch=1):
    sys.setrecursionlimit(500000)
    go.init(9)

    trainset = []
    evalset = []
    trainfiles = [f for f in listdir('../data/train/') if f[-4:] == 'json']
    testfiles = [f for f in listdir('../data/test/') if f[-4:] == 'json']
    for f in trainfiles:
        with open('../data/train/' + f) as json_data:
            record = json.load(json_data)
            s = 0
            parent = go.Position()
            while s < len(record) and s <= go.LN:
                position = go.Position()
                position.fromJSON(record[s])
                position.parent = parent
                parent = position
                if position.vertex != 0:
                    trainset.append(position)
                s += 1

    for f in testfiles:
        with open('../data/test/' + f) as json_data:
            record = json.load(json_data)
            s = 0
            parent = go.Position()
            while s < len(record) and s <= go.LN:
                position = go.Position()
                position.fromJSON(record[s])
                position.parent = parent
                parent = position
                if position.vertex != 0:
                    evalset.append(position)
                s += 1

    train(trainset, evalset, epoch)
示例#3
0
 def set_size(self, size):
     go.init(size)
示例#4
0
def main(count, path):
    sys.setrecursionlimit(500000)
    go.init(9)
    playerBlack = MCTSPlayer(90, resnet.Policy(40,
                                               '../data/r1/resnet_pars.pkl'))
    playerWhite = MCTSPlayer(30, randmove.Policy(40))

    records = [
        f for f in listdir(path) if f[-4:] == 'json' and f[:6] == 'record'
    ]
    fcount = len(records)

    vertex = None
    caps = None

    black_win = 0
    white_win = 0
    draw = 0

    c = 1
    while c <= count:
        records = '[\n'
        i = 0

        print('ready: %d in %d, POSPOOL: %d' %
              (c, count, len(go.POSITION_POOL)))

        while go.POSITION.pass_count() < 2:
            i += 1

            legal = True
            if i % 2 == 1:
                legal = playerBlack.move()
            else:
                legal = playerWhite.move()

            if not legal:
                print('Illegal move!')
                break

            go.POSITION.debug()

            record = go.POSITION.toJSON()
            records += '  '
            records += record

            if go.POSITION.pass_count() < 2:
                records += ',\n'
            else:
                records += '\n]'

        score = go.POSITION.score() - go.KOMI
        playerBlack.clear()
        playerWhite.clear()
        go.clear()

        fcount += 1
        filename = path + 'record_%d.json' % fcount

        f = open(filename, 'w')
        f.write(records)
        f.close()

        if score > 0:
            black_win += 1
        elif score < 0:
            white_win += 1
        else:
            draw += 1

        c += 1

    print('back win: %d, white win: %d, draw: %d' %
          (black_win, white_win, draw))
示例#5
0
import tensorflow as tf
import os
import sys
from tensorflow.python.platform import gfile
import numpy as np
from scipy.misc import imread, imresize
from os.path import isfile, join
from os import listdir
import go
import json

sys.setrecursionlimit(500000)
go.init(9)

def input_board(position, board):
    c = 0
    x = 0
    y = 0
    while c < go.LN:
        v = go.COORDS[c]

        if v == position.ko:
            board[y, x] = 2.0
        else:
            board[y, x] = position.board[v] * position.next * 1.0

        x += 1
        if x == go.N:
            y += 1
            x = 0
        c = y * go.N + x