def evalKingTropism(board): """ All other things being equal, having your Knights, Queens and Rooks close to the opponent's king is a good thing """ score = 0 try: wking, bking = findKings(board) wky, wkx = wking.cords bky, bkx = bking.cords except: return 0 for py, row in enumerate(board.data): for px, piece in enumerate(row): if piece and piece.color == WHITE: if piece.sign == KNIGHT: score += lookUpTropism(px, py, bkx, bky, KNIGHT) elif piece.sign == ROOK: score += lookUpTropism(px, py, bkx, bky, ROOK) elif piece.sign == QUEEN: score += lookUpTropism(px, py, bkx, bky, QUEEN) elif piece and piece.color == BLACK: if piece.sign == KNIGHT: score -= lookUpTropism(px, py, wkx, wky, KNIGHT) elif piece.sign == ROOK: score -= lookUpTropism(px, py, wkx, wky, ROOK) elif piece.sign == QUEEN: score -= lookUpTropism(px, py, wkx, wky, QUEEN) return score
def evalDevelopment(board): """ Mostly useful in the opening, this term encourages the machine to move its bishops and knights into play, to control the center with its queen's and king's pawns """ score = 0 # Test endgame if pieceCount <= 8: wking, bking = findKings(board) score += endking[wking.y * 8 + wking.x] score -= endking[bking.y * 8 + bking.x] return score for y, row in enumerate(board.data): for x, piece in enumerate(row): if not piece: continue # s = pos[piece.sign][piece.color][y*8+x] if piece.color == WHITE: if piece.sign == PAWN: score += whitepawn[x + y * 8] elif piece.sign == KNIGHT: score += whiteknight[x + y * 8] elif piece.sign == BISHOP: score += whitebishop[x + y * 8] elif piece.sign == ROOK: score += whiterook[x + y * 8] elif piece.sign == QUEEN: score += whitequeen[x + y * 8] elif piece.sign == KING: score += whiteking[x + y * 8] else: if piece.sign == PAWN: score -= blackpawn[x + y * 8] elif piece.sign == KNIGHT: score -= blackknight[x + y * 8] elif piece.sign == BISHOP: score -= blackbishop[x + y * 8] elif piece.sign == ROOK: score -= blackrook[x + y * 8] elif piece.sign == QUEEN: score -= blackqueen[x + y * 8] elif piece.sign == KING: score -= blackking[x + y * 8] return score