Exemplo n.º 1
0
def isKingMate( color ):
	# Check if king is even mate before checking moves
	if not isKingCheck( color ):
		return False	
	kingPos = board.findKing( color )
	oldBoard = board.getBoardCopy() # F**k this shallow copy shit
	kingMate = True
	for move in legalMoves( kingPos ):
		board.setBoardCopy( oldBoard )
		board.movePiece( kingPos, move )

		if not isKingCheck( color ):
			kingMate = False
			break
		
	# King is mate if no "not-checks" are found
	board.setBoard( oldBoard ) # Revert board
	return kingMate	
Exemplo n.º 2
0
def movePiece( pos, to ):
	if not posLegal( to ):
		raise exceptions.IllegalPositionException
	
	allowed = False
	for move in legalMoves( pos ):
		if move == to:
			allowed = True
			break
			
	if not allowed:
		raise exceptions.IllegalMoveException
	
	boardCopy = board.getBoardCopy()
	board.movePiece( pos, to )
	
	if isKingCheck( boardIndex( to )[1] ):
		board.setBoard( boardCopy ) # Revert move
		raise exceptions.SelfCheckException # Cannot check self