Beispiel #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	
Beispiel #2
0
def isKingCheck( color ):
	kingPos = board.findKing( color )
	for i in range( 0, 8 ):
		for j in range( 0, 8 ):
			enemyPos = [ i, j ]
			enemy = boardIndex( enemyPos )
			if enemy == " " or enemy[1] == color: # Empty or friend
				continue
				
			for enemyMove in legalMoves( enemyPos ):
				if enemy[0] == pieces["pawn"]:
					if enemyPos[1] == enemyMove[1]:
						continue # Pawns are only a threat diagonally
				
				if enemyMove == kingPos:
					return True
	
	return False