예제 #1
0
파일: Referee.py 프로젝트: toobright/Ghost
class Referee():
    def __init__(self):
        self.go = Position(n=9, komi=3.25)

    def action(self, coord):
        """ 
        输入:落子坐标
        输出:是否合法,提子列表,胜负(0:未决出胜负,1:胜,-1:负)
        """

        # 判断是否pass
        if coord == [-1, -1]:
            self.go = self.go.pass_move()

            # 检查胜负情况
            winner = 0
            if self.go.is_game_over():
                winner = self.go.result()
                print(self.go.result_string())

            return [True, [], winner]

        # 检查是否合法
        if not self.go.is_move_legal(tuple(coord)):
            return (False, [], 0)

        # 棋盘信息备份
        preBoard = self.go.board.copy()
        preBoard[coord[0], coord[1]] = 1

        # 落子
        self.go = self.go.play_move(tuple(coord))

        # 检查是否提子,若提子则存储提子信息到列表
        absDiff = np.abs(preBoard) - np.abs(self.go.board)
        takes = np.transpose(np.nonzero(absDiff))

        return (True, takes, 0)
예제 #2
0
        return pv_mcts_coord

    return pv_mcts_action


def boltzman(xs, temperature):
    xs = [x**(1 / temperature) for x in xs]
    return [x / sum(xs) for x in xs]


if __name__ == '__main__':
    cur_dir = Path(__file__).parent.absolute()
    cur_dir = cur_dir / 'model'

    path = sorted(cur_dir.glob('*.h5'))[-1]
    model = load_model(str(path))

    state = Position()

    next_action = pv_mcts_action(model, 1.0)

    while True:
        if state.is_game_over():
            print(state.result_string())
            break
        action = next_action(state)

        state = state.play_move(action)

        print(state.__str__(False))
        print()