本文整理汇总了Python中fysom.Fysom.uci方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.uci方法的具体用法?Python Fysom.uci怎么用?Python Fysom.uci使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.uci方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import uci [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])
#.........这里部分代码省略.........
示例2: onanalyze
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import uci [as 别名]
break
boomerang.noMoves()
def onanalyze(e):
manager.end()
boomerang = Fysom({'initial': 'start',
'events': [{'name': 'startsearch','src':'start','dst':'godeeper'},
{'name': 'exploremove','src':'godeeper','dst':'explore'},
{'name': 'exploremove','src':'explore','dst':'explore'},
{'name': 'noMoves','src':'explore','dst':'analyze'}],
'callbacks': {
'ongodeeper': ongodeeper,
'onexplore': onexplore
} })
while True:
if boomerang.isstate("start"):
res = manager.get()
if re.search('^Stockfish', res):
initialize.uci(gameStatus)
if re.search('^uciok', res):
initialize.isready()
if re.search('^readyok', res):
boomerang.startsearch(movesList, movesListCP, searchingDepth, gameStatus, cp)
elif boomerang.isstate("godeeper"):
boomerang.exploremove(movesList, movesListCP, totalMoves, exploreDepth, gameStatus)
示例3: print
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import uci [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)
示例4: __init__
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import uci [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]
#.........这里部分代码省略.........