当前位置: 首页>>代码示例>>Python>>正文


Python Fysom.ucinewgame方法代码示例

本文整理汇总了Python中fysom.Fysom.ucinewgame方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.ucinewgame方法的具体用法?Python Fysom.ucinewgame怎么用?Python Fysom.ucinewgame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fysom.Fysom的用法示例。


在下文中一共展示了Fysom.ucinewgame方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import ucinewgame [as 别名]
                        {'name': 'isready','src':'uciok','dst':'readyok'},
                        {'name': 'ucinewgame','src':'readyok','dst':'goinfinite'},
                        {'name': 'infinite','src':'goinfinite','dst':'goinfinite'},
                        {'name': 'move','src':'goinfinite','dst':'bestmove'},
                        {'name': 'infinite','src':'bestmove','dst':'goinfinite'},
                        {'name': 'mate','src':'bestmove','dst':'end'}],
              'callbacks': {
                  'onuciok': onuciok,
                  'onreadyok': onreadyok,
                  'onucinewgame': onucinewgame,
                  'onbestmove': onbestmove,
                  'onend': onend } })

print game.current

while True:
    res = manager.get()
    print('     '+res)
    if re.search('^Stockfish', res):
        game.uci()
    if re.search('^uciok', res):
        game.isready()
    if re.search('^readyok', res):
        game.ucinewgame()
    if re.search('^info', res):
        game.infinite()
        onsearch(res, gameStatus)
    if re.search('^bestmove (?P<move>\w+) ', res):
        bestmove = re.search('^bestmove (?P<move>\w+) ', res)
        game.move(bestmove.group('move'), gameStatus)
开发者ID:Nixonite,项目名称:chesscomputer,代码行数:32,代码来源:autoplay.py

示例2: __init__

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import ucinewgame [as 别名]
class Boomerang:
    def __init__(self, gameName):
        self.gameStatus = {
            "gameName": gameName,
            "startpos": "startpos",
            "moves": [],
            "moveDepths": {},
            "fen": True,
            "centipawns": 0,
            "initialCentipawns": {},
            "currentMove": 1,
            "startPlayer": "w",
            "player": "w",
            "JSONlines": [],
            "JSONcurrentLine": {},
            "JSONmoves": [],
            "JSONcurrentMove": {},
        }

        self.movesList = []
        self.movesListCP = {}
        self.cp = 0
        self.totalMoves = 5
        self.searchingDepth = 15  # total depth for 'searching' state
        self.exploreDepth = "depth 15"  # depth for 'exploring state. "infinite" or "depth #"

        self.initialize = Fysom({"initial": "start"})
        self.search = Fysom({"initial": "start"})
        self.explore = Fysom({"initial": "start"})
        self.boomerang = Fysom({"initial": "start"})

        self.manager = StockfishManager()

        """
		INITIALIZE
		State machine for starting Stockfish
		"""

        def onstockfish(e):
            gameStatus = e.args[0]
            self.manager.uci()

        def onuciok(e):
            self.manager.isready()

        """
		SEARCH
		State machine, takes in one position, searches at increasing depth for next move
		Returns list of possible moves
		"""

        def onnewgame(e):
            gameStatus = e.args[0]
            startpos = gameStatus["startpos"]
            gameStatus["startPlayer"] = gameStatus["startpos"].split(" ")[1]  # set starting player from fen string
            fen = gameStatus["fen"]
            moves = gameStatus["moves"]

            self.manager.ucinewgame()
            self.manager.position(startpos, fen, moves)
            self.manager.go("depth 1")

        def ongodepth(e, c):
            global cp
            if re.search("depth (?P<depth>\d+) seldepth \d+ score cp (?P<cp>-?\w+)", e):
                info = re.search("depth (?P<depth>\d+) seldepth \d+ score cp (?P<cp>-?\w+)", e)
                cp = int(info.group("cp"))

        def onmove(e):
            global cp
            bestMove = e.args[0]
            movesList = e.args[1]
            movesListCP = e.args[2]
            currentDepth = e.args[3]
            searchingDepth = e.args[4]
            gameStatus = e.args[6]
            moveDepths = gameStatus["moveDepths"]
            # cp = e.args[5]

            moveDepths[bestMove] = currentDepth - 1
            movesListCP[bestMove] = cp
            if bestMove not in movesList:
                movesList.append(bestMove)

            if currentDepth <= searchingDepth:
                self.manager.go("depth " + str(currentDepth))

        """
		EXPLORE
		State machine, takes list of possible moves, plays out game
		"""

        def onucinewgame(e):
            currentMove = e.args[2]
            gameStatus = e.args[3]
            player = gameStatus["player"]
            name = gameStatus["gameName"]
            moves = gameStatus["moves"]
            fen = gameStatus["fen"]
            moveCP = str(self.movesListCP[currentMove])
#.........这里部分代码省略.........
开发者ID:Nixonite,项目名称:chesscomputer,代码行数:103,代码来源:boomerang_server.py

示例3: __init__

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import ucinewgame [as 别名]
class Boomerang:
	def __init__(self, gameName):
		self.gameStatus = {"gameName" : gameName,
					  "startpos" : 'startpos',
					  "moves" : [],
					  "moveDepths" : {},
					  "fen" : True,
					  "centipawns" : 0,
					  "initialCentipawns": {},
					  "currentMove" : 1,
					  "startPlayer" : 'w',
					  "player" : 'w',
					  "JSONlines" : [],
					  "JSONcurrentLine": {},
					  "JSONmoves": [],
					  "JSONcurrentMove":{},
					  }

		self.movesList = []
		self.movesListCP = {}
		self.cp = 0
		self.totalMoves = 5
		self.searchingDepth = 15          # total depth for 'searching' state
		self.exploreDepth = "depth 15"   # depth for 'exploring state. "infinite" or "depth #"
		
		self.initialize = Fysom({'initial': 'start'})
		self.search = Fysom({'initial': 'start'})
		self.explore = Fysom({'initial': 'start'})
		self.boomerang = Fysom({'initial': 'start'})
	
		self.manager = StockfishManager()

		"""
		INITIALIZE
		State machine for starting Stockfish
		"""
		def onstockfish(e):
			gameStatus = e.args[0]
			self.manager.uci()

		def onuciok(e):
			self.manager.isready()

		"""
		SEARCH
		State machine, takes in one position, searches at increasing depth for next move
		Returns list of possible moves
		"""
		def onnewgame(e):
			gameStatus = e.args[0]
			startpos = gameStatus["startpos"]
			gameStatus["startPlayer"] = gameStatus["startpos"].split(' ')[1]    #set starting player from fen string
			fen = gameStatus["fen"]
			moves = gameStatus["moves"]
			
			self.manager.ucinewgame()
			self.manager.position(startpos, fen, moves)
			self.manager.go("depth 1")

		def ongodepth(e, c):
			global cp
			if re.search('depth (?P<depth>\d+) seldepth \d+ score cp (?P<cp>-?\w+)', e):
				info = re.search('depth (?P<depth>\d+) seldepth \d+ score cp (?P<cp>-?\w+)', e)
				cp = int(info.group('cp'))

		def onmove(e):
			global cp
			bestMove = e.args[0]
			movesList = e.args[1]
			movesListCP = e.args[2]
			currentDepth = e.args[3]
			searchingDepth = e.args[4]
			gameStatus = e.args[6]
			moveDepths = gameStatus["moveDepths"]
			#cp = e.args[5]

			moveDepths[bestMove] = (currentDepth-1)
			movesListCP[bestMove] = cp
			if bestMove not in movesList:
				movesList.append(bestMove)
				
			

			if currentDepth <= searchingDepth:
				self.manager.go("depth " + str(currentDepth))
		
		"""
		EXPLORE
		State machine, takes list of possible moves, plays out game
		"""
		def onucinewgame(e):
			currentMove = e.args[2]
			gameStatus = e.args[3]
			player = gameStatus["player"]
			name = gameStatus["gameName"]
			moves = gameStatus["moves"]
			fen = gameStatus["fen"]
			moveCP = str(self.movesListCP[currentMove])

			startpos = e.args[1]
#.........这里部分代码省略.........
开发者ID:M0nd4,项目名称:chesscomputer,代码行数:103,代码来源:boomerang_server.py


注:本文中的fysom.Fysom.ucinewgame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。