本文整理汇总了Python中fysom.Fysom.searching方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.searching方法的具体用法?Python Fysom.searching怎么用?Python Fysom.searching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.searching方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import searching [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: __init__
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import searching [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]
#.........这里部分代码省略.........