本文整理汇总了Python中pychess.Utils.logic.validate函数的典型用法代码示例。如果您正苦于以下问题:Python validate函数的具体用法?Python validate怎么用?Python validate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: validate
def validate (self, cord0, cord1):
if cord0 is None or cord1 is None:
return False
# prevent accidental NULL_MOVE creation
if cord0 == cord1:
return False
if self.getBoard()[cord0] == None:
return False
if self.parent.setup_position:
to_piece = self.getBoard()[cord1]
# prevent moving pieces inside holding
if (cord0.x < 0 or cord0.x > self.FILES-1) and \
(cord1.x < 0 or cord1.x > self.FILES-1):
return False
# prevent moving kings off board
elif self.getBoard()[cord0].piece == KING and \
(cord1.x < 0 or cord1.x > self.FILES-1):
return False
# prevent taking enemy king
elif to_piece is not None and to_piece.piece == KING:
return False
else:
return True
if cord1.x < 0 or cord1.x > self.FILES-1:
return False
if cord0.x < 0 or cord0.x > self.FILES-1:
# drop
return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
else:
return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:ZeepXanflorp,项目名称:pychess,代码行数:32,代码来源:BoardControl.py
示例2: validate
def validate(self, cord0, cord1):
if cord0 is None or cord1 is None:
return False
# prevent accidental NULL_MOVE creation
if cord0 == cord1:
return False
if self.getBoard()[cord0] is None:
return False
if self.parent.setup_position:
# prevent moving pieces inside holding
if (cord0.x < 0 or cord0.x > self.FILES - 1) and \
(cord1.x < 0 or cord1.x > self.FILES - 1):
return False
else:
return True
if cord1.x < 0 or cord1.x > self.FILES - 1:
return False
if cord0.x < 0 or cord0.x > self.FILES - 1:
# drop
return validate(self.getBoard(), Move(lmovegen.newMove(
self.getBoard()[cord0].piece, cord1.cord, DROP)))
else:
return validate(self.getBoard(), Move(cord0, cord1,
self.getBoard()))
开发者ID:bboutkov,项目名称:pychess,代码行数:26,代码来源:BoardControl.py
示例3: test_getstatus2
def test_getstatus2(self):
"""Testing bare white king is not draw in Atomic variant"""
board = AtomicBoard(setup=FEN3)
self.assertTrue(not validate(board, parseSAN(board, 'Kxg7')))
self.assertTrue(not validate(board, parseSAN(board, 'Kg8')))
self.assertTrue(not validate(board, parseSAN(board, 'Kh7')))
print(board)
self.assertEqual(getStatus(board), (DRAW, DRAW_STALEMATE))
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:9,代码来源:atomic.py
示例4: validate
def validate (self, cord0, cord1):
assert cord0 != None and cord1 != None, "cord0: " + str(cord0) + ", cord1: " + str(cord1)
if self.getBoard()[cord0] == None:
return False
if cord1.x < 0 or cord1.x > self.FILES-1:
return False
if cord0.x < 0 or cord0.x > self.FILES-1:
# drop
return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
else:
return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:btrent,项目名称:knave,代码行数:11,代码来源:BoardControl.py
示例5: test_validate
def test_validate(self):
"""Testing validate move in Crazyhouse variant"""
board = CrazyhouseBoard(setup=FEN0)
print(board)
# Drop can save mate
self.assertTrue(validate(board, parseSAN(board, '[email protected]')))
self.assertTrue(validate(board, parseSAN(board, 'Ka7')))
self.assertTrue(validate(board, parseSAN(board, 'Kb7')))
self.assertTrue(not validate(board, parseSAN(board, '[email protected]')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb8')))
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:11,代码来源:crazyhouse.py
示例6: test_validate1
def test_validate1(self):
"""Testing castling rights lose in explosion in Atomic variant"""
board = AtomicBoard(setup=FEN1)
board = board.move(parseSAN(board, 'Nxa7'))
print(board)
# Rook exploded, no O-O-O anymore!
self.assertTrue(validate(board, parseSAN(board, 'b6')))
self.assertTrue(not validate(board, parseSAN(board, 'a6')))
self.assertTrue(not validate(board, parseSAN(board, 'Rb8')))
self.assertTrue(not validate(board, parseSAN(board, 'O-O-O')))
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:11,代码来源:atomic.py
示例7: test_validate2
def test_validate2(self):
"""Testing explode king vs mate in Atomic variant"""
board = AtomicBoard(setup=FEN1)
board = board.move(parseSAN(board, 'Nc7+'))
print(board)
# King explosion takes precedence over mate!
self.assertTrue(validate(board, parseSAN(board, 'Qxd2')))
self.assertTrue(validate(board, parseSAN(board, 'Qxf2')))
self.assertTrue(not validate(board, parseSAN(board, 'Qxb2')))
self.assertTrue(not validate(board, parseSAN(board, 'Qe4+')))
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:11,代码来源:atomic.py
示例8: validate
def validate (self, cord0, cord1):
if cord0 is None or cord1 is None:
return False
if self.getBoard()[cord0] == None:
return False
if cord1.x < 0 or cord1.x > self.FILES-1:
return False
if cord0.x < 0 or cord0.x > self.FILES-1:
# drop
return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
else:
return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:12,代码来源:BoardControl.py
示例9: validate
def validate (self, cord0, cord1):
if cord0 is None or cord1 is None:
return False
# prevent accidental NULL_MOVE creation
if cord0 == cord1:
return False
if self.getBoard()[cord0] == None:
return False
if cord1.x < 0 or cord1.x > self.FILES-1:
return False
if cord0.x < 0 or cord0.x > self.FILES-1:
# drop
return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
else:
return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:jholland6843,项目名称:pychess,代码行数:15,代码来源:BoardControl.py
示例10: makeMove
def makeMove(self, board1, move, board2):
log.debug("Human.makeMove: move=%s, board1=%s board2=%s" % (
move, board1, board2))
if self.board.view.premove_piece and self.board.view.premove0 and \
self.board.view.premove1 and \
self.color == self.board.view.premove_piece.color:
if validate(board1,
Move(self.board.view.premove0,
self.board.view.premove1,
board1,
promotion=self.board.view.premove_promotion)):
log.debug("Human.makeMove: Setting move to premove %s %s" % (
self.board.view.premove0, self.board.view.premove1))
self.board.emit_move_signal(
self.board.view.premove0,
self.board.view.premove1,
promotion=self.board.view.premove_promotion)
# reset premove
self.board.view.setPremove(None, None, None, None)
self.gmwidg.setLocked(False)
item = yield from self.move_queue.get()
self.gmwidg.setLocked(True)
if item == "del":
log.debug("Human.makeMove got: del")
raise PlayerIsDead
elif item == "int":
log.debug("Human.makeMove got: int")
raise TurnInterrupt
elif item == "pass":
log.debug("Human.makeMove got: pass")
raise PassInterrupt
return item
开发者ID:teacoffee2017,项目名称:pychess,代码行数:34,代码来源:Human.py
示例11: makeMove
def makeMove(self, board1, move, board2):
log.debug("Human.makeMove: move=%s, board1=%s board2=%s" % (
move, board1, board2))
if self.board.view.premove_piece and self.board.view.premove0 and \
self.board.view.premove1 and \
self.color == self.board.view.premove_piece.color:
if validate(board1,
Move(self.board.view.premove0,
self.board.view.premove1,
board1,
promotion=self.board.view.premove_promotion)):
log.debug("Human.makeMove: Setting move to premove %s %s" % (
self.board.view.premove0, self.board.view.premove1))
self.board.emit_move_signal(
self.board.view.premove0,
self.board.view.premove1,
promotion=self.board.view.premove_promotion)
# reset premove
self.board.view.setPremove(None, None, None, None)
self.gmwidg.setLocked(False)
item = self.queue.get(block=True)
self.gmwidg.setLocked(True)
if item == "del":
raise PlayerIsDead("Killed by foreign forces")
if item == "int":
log.debug("Human.makeMove: %s: raise TurnInterrupt" % self)
raise TurnInterrupt
return item
开发者ID:TPNguyen,项目名称:pychess,代码行数:28,代码来源:Human.py
示例12: key_pressed
def key_pressed (self, keyname):
if keyname in "PNBRQKMFSOox12345678abcdefgh":
self.keybuffer += keyname
elif keyname == "minus":
self.keybuffer += "-"
elif keyname == "at":
self.keybuffer += "@"
elif keyname == "equal":
self.keybuffer += "="
elif keyname == "Return":
color = self.view.model.boards[-1].color
board = self.view.model.getBoardAtPly(self.view.shown, self.view.shownVariationIdx)
try:
move = parseAny(board, self.keybuffer)
except:
self.keybuffer = ""
return
if validate(board, move):
if self.view.shownIsMainLine() and self.view.model.boards[-1] == board:
self.emit("piece_moved", move, color)
else:
if board.board.next is None and not self.view.shownIsMainLine():
self.view.model.add_move2variation(board, move, self.view.shownVariationIdx)
self.view.shown += 1
else:
new_vari = self.view.model.add_variation(board, (move,))
self.view.setShownBoard(new_vari[-1])
self.keybuffer = ""
elif keyname == "BackSpace":
self.keybuffer = self.keybuffer[:-1] if self.keybuffer else ""
开发者ID:ZeepXanflorp,项目名称:pychess,代码行数:30,代码来源:BoardControl.py
示例13: test_check_evasions
def test_check_evasions(self):
"""Testing check evasions in Crazyhouse variant"""
board = CrazyhouseBoard(setup=FEN1)
print(board)
# invalid drop
self.assertTrue(validate(board, parseSAN(board, '[email protected]')))
self.assertTrue(validate(board, parseSAN(board, '[email protected]')))
self.assertTrue(validate(board, parseSAN(board, 'Kxb2')))
self.assertTrue(not validate(board, parseSAN(board, '[email protected]')))
self.assertTrue(not validate(board, parseSAN(board, '[email protected]')))
evasions = [move for move in genCheckEvasions(board.board)]
self.assertTrue(parseSAN(board, '[email protected]').move in evasions)
self.assertTrue(parseSAN(board, '[email protected]').move in evasions)
self.assertTrue(parseSAN(board, 'Kxb2').move in evasions)
self.assertTrue(parseSAN(board, '[email protected]').move not in evasions)
self.assertTrue(parseSAN(board, '[email protected]').move not in evasions)
开发者ID:bboutkov,项目名称:pychess,代码行数:17,代码来源:crazyhouse.py
示例14: test_validate
def test_validate(self):
"""Testing validate move in Losers variant"""
board = LosersBoard(setup=FEN0)
print(board)
self.assertTrue(validate(board, parseSAN(board, 'Kxa7')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb8')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb7')))
board = LosersBoard(setup=FEN1)
print(board)
self.assertTrue(not validate(board, parseSAN(board, 'Kxa7')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb8')))
self.assertTrue(validate(board, parseSAN(board, 'Kb7')))
board = LosersBoard(setup=FEN2)
print(board)
self.assertTrue(not validate(board, parseSAN(board, 'Kxb7')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb8')))
self.assertTrue(validate(board, parseSAN(board, 'Rxb7')))
开发者ID:CarbonFixer,项目名称:pychess,代码行数:20,代码来源:losers.py
示例15: isAPotentiallyLegalNextMove
def isAPotentiallyLegalNextMove (self, cord0, cord1):
""" Determines whether the given move is at all legally possible
as the next move after the player who's turn it is makes their move
Note: This doesn't always return the correct value, such as when
BoardControl.setLocked() has been called and we've begun a drag,
but view.shown and BoardControl.lockedPly haven't been updated yet """
if cord0 == None or cord1 == None: return False
if not self.parent.lockedPly in self.parent.possibleBoards:
return False
for board in self.parent.possibleBoards[self.parent.lockedPly]:
if not board[cord0]:
return False
if validate(board, Move(cord0, cord1, board)):
return True
return False
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:15,代码来源:BoardControl.py
示例16: test_validate
def test_validate(self):
"""Testing validate move in Suicide variant"""
board = SuicideBoard(setup=FEN0)
print(board)
self.assertTrue(validate(board, parseSAN(board, 'Kxa7')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb8')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb7')))
board = SuicideBoard(setup=FEN1)
print(board)
self.assertTrue(validate(board, parseSAN(board, 'Kxa7')))
self.assertTrue(validate(board, parseSAN(board, 'Kxb8')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb7')))
board = SuicideBoard(setup=FEN2)
print(board)
self.assertTrue(not validate(board, parseSAN(board, 'Ka7')))
self.assertTrue(not validate(board, parseSAN(board, 'Kb8')))
self.assertTrue(validate(board, parseSAN(board, 'Kxb7')))
board = SuicideBoard(setup=FEN3)
print(board)
self.assertTrue(validate(board, parseSAN(board, 'Ked2')))
开发者ID:bboutkov,项目名称:pychess,代码行数:24,代码来源:suicide.py
示例17: key_pressed
def key_pressed(self, keyname):
if keyname in "PNBRQKMFSOox12345678abcdefgh":
self.keybuffer += keyname
elif keyname == "minus":
self.keybuffer += "-"
elif keyname == "at":
self.keybuffer += "@"
elif keyname == "equal":
self.keybuffer += "="
elif keyname == "Return":
color = self.view.model.boards[-1].color
board = self.view.model.getBoardAtPly(
self.view.shown, self.view.shown_variation_idx)
try:
move = parseAny(board, self.keybuffer)
except:
self.keybuffer = ""
return
if validate(board, move):
if (self.view.model.curplayer.__type__ == LOCAL or self.view.model.examined) and \
self.view.shownIsMainLine() and \
self.view.model.boards[-1] == board and \
self.view.model.status == RUNNING:
# emit move
self.emit("piece_moved", move, color)
if self.view.model.examined:
self.view.model.connection.bm.sendMove(toAN(board, move))
else:
play_or_add_move(self.view, board, move)
self.keybuffer = ""
elif keyname == "BackSpace":
self.keybuffer = self.keybuffer[:-1] if self.keybuffer else ""
开发者ID:bboutkov,项目名称:pychess,代码行数:38,代码来源:BoardControl.py
示例18: __parseLine
def __parseLine (self, line):
if not self.connected: return
parts = line.split()
if not parts: return
#---------------------------------------------------------- Initializing
if parts[0] == "id":
self.ids[parts[1]] = " ".join(parts[2:])
if parts[1] == "name":
self.setName(self.ids["name"])
return
if parts[0] == "uciok":
#self.emit("readyForOptions")
return
if parts[0] == "readyok":
#self.emit("readyForMoves")
return
#------------------------------------------------------- Options parsing
if parts[0] == "option":
dic = {}
last = 1
varlist = []
for i in xrange (2, len(parts)+1):
if i == len(parts) or parts[i] in OPTKEYS:
key = parts[last]
value = " ".join(parts[last+1:i])
if "type" in dic and dic["type"] in TYPEDIC:
value = TYPEDIC[dic["type"]](value)
if key == "var":
varlist.append(value)
elif key == "type" and value == "string":
dic[key] = "text"
else:
dic[key] = value
last = i
if varlist:
dic["choices"] = varlist
self.options[dic["name"]] = dic
return
#---------------------------------------------------------------- A Move
if self.mode == NORMAL and parts[0] == "bestmove":
with self.moveLock:
self.needBestmove = False
self.__sendQueuedGo()
if self.ignoreNext:
log.debug("__parseLine: line='%s' self.ignoreNext==True, returning\n" % \
line.strip(), self.defname)
self.ignoreNext = False
self.readyForStop = True
return
if not self.waitingForMove:
log.warn("__parseLine: self.waitingForMove==False, ignoring move=%s\n" % \
parts[1], self.defname)
self.pondermove = None
return
self.waitingForMove = False
try:
move = parseAN(self.board, parts[1])
except ParsingError, e:
self.end(WHITEWON if self.board.color == BLACK else BLACKWON, WON_ADJUDICATION)
return
if not validate(self.board, move):
# This is critical. To avoid game stalls, we need to resign on
# behalf of the engine.
log.error("__parseLine: move=%s didn't validate, putting 'del' in returnQueue. self.board=%s\n" % \
(repr(move), self.board), self.defname)
self.end(WHITEWON if self.board.color == BLACK else BLACKWON, WON_ADJUDICATION)
return
self._recordMove(self.board.move(move), move, self.board)
log.debug("__parseLine: applied move=%s to self.board=%s\n" % \
(move, self.board), self.defname)
if self.ponderOn:
self.pondermove = None
# An engine may send an empty ponder line, simply to clear.
if len(parts) == 4:
# Engines don't always check for everything in their
# ponders. Hence we need to validate.
# But in some cases, what they send may not even be
# correct AN - specially in the case of promotion.
try:
pondermove = parseAN(self.board, parts[3])
except ParsingError:
pass
else:
if validate(self.board, pondermove):
self.pondermove = pondermove
self._startPonder()
#.........这里部分代码省略.........
开发者ID:btrent,项目名称:knave,代码行数:101,代码来源:UCIEngine.py
示例19: parseLine
def parseLine(self, proc):
while True:
line = yield from wait_signal(proc, 'line')
if not line:
break
else:
line = line[1]
if line[0:1] == "#":
# Debug line which we shall ignore as specified in CECPv2 specs
continue
# log.debug("__parseLine: line=\"%s\"" % line.strip(), extra={"task":self.defname})
parts = whitespaces.split(line.strip())
if parts[0] == "pong":
self.lastpong = int(parts[1])
continue
# Illegal Move
if parts[0].lower().find("illegal") >= 0:
log.warning("__parseLine: illegal move: line=\"%s\", board=%s" % (
line.strip(), self.board), extra={"task": self.defname})
if parts[-2] == "sd" and parts[-1].isdigit():
print("depth", parts[-1], file=self.engine)
continue
# A Move (Perhaps)
if self.board:
if parts[0] == "move":
movestr = parts[1]
# Old Variation
elif d_plus_dot_expr.match(parts[0]) and parts[1] == "...":
movestr = parts[2]
else:
movestr = False
if movestr:
self.waitingForMove = False
self.readyForMoveNowCommand = False
if self.engineIsInNotPlaying:
# If engine was set in pause just before the engine sent its
# move, we ignore it. However the engine has to know that we
# ignored it, and thus we step it one back
log.info("__parseLine: Discarding engine's move: %s" %
movestr,
extra={"task": self.defname})
print("undo", file=self.engine)
continue
else:
try:
move = parseAny(self.board, movestr)
except ParsingError:
self.invalid_move = movestr
log.info(
"__parseLine: ParsingError engine move: %s %s"
% (movestr, self.board),
extra={"task": self.defname})
self.end(WHITEWON if self.board.color == BLACK else
BLACKWON, WON_ADJUDICATION)
continue
if validate(self.board, move):
self.board = None
self.queue.put_nowait(move)
continue
else:
self.invalid_move = movestr
log.info(
"__parseLine: can't validate engine move: %s %s"
% (movestr, self.board),
extra={"task": self.defname})
self.end(WHITEWON if self.board.color == BLACK else
BLACKWON, WON_ADJUDICATION)
continue
# Analyzing
if self.engineIsInNotPlaying:
if parts[:4] == ["0", "0", "0", "0"]:
# Crafty doesn't analyze until it is out of book
print("book off", file=self.engine)
continue
match = anare.match(line)
if match:
depth, score, moves = match.groups()
if "mat" in score.lower() or "#" in moves:
# Will look either like -Mat 3 or Mat3
scoreval = MATE_VALUE
if score.startswith('-'):
scoreval = -scoreval
else:
scoreval = int(score)
mvstrs = movere.findall(moves)
if mvstrs:
self.emit("analyze", [(mvstrs, scoreval, depth.strip())])
continue
# Offers draw
#.........这里部分代码省略.........
开发者ID:bboutkov,项目名称:pychess,代码行数:101,代码来源:CECPEngine.py
示例20: test_getstatus4
def test_getstatus4(self):
"""Testing possible move into check when king touch saves the king"""
board = AtomicBoard(setup=FEN5)
print(board)
self.assertTrue(validate(board, parseSAN(board, 'Kg5')))
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:6,代码来源:atomic.py
注:本文中的pychess.Utils.logic.validate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论