public static void AssignLoudValues(BoardState board, Span <Move> moves, Span <short> moveValues, int movesCount, int depth, Move hashOrPvMove) { for (var moveIndex = 0; moveIndex < movesCount; moveIndex++) { if (hashOrPvMove == moves[moveIndex]) { moveValues[moveIndex] = MoveOrderingConstants.HashMove; } else if (moves[moveIndex].Flags == MoveFlags.EnPassant) { moveValues[moveIndex] = MoveOrderingConstants.EnPassant; } else if (((byte)moves[moveIndex].Flags & MoveFlagFields.Promotion) != 0) { moveValues[moveIndex] = (short)(MoveOrderingConstants.Promotion + (int)moves[moveIndex].Flags); } else if (moves[moveIndex].IsCapture()) { var enemyColor = ColorOperations.Invert(board.ColorToMove); var attackingPiece = board.PieceTable[moves[moveIndex].From]; var capturedPiece = board.PieceTable[moves[moveIndex].To]; var attackers = board.GetAttackingPiecesWithColor(board.ColorToMove, moves[moveIndex].To); var defenders = board.GetAttackingPiecesWithColor(enemyColor, moves[moveIndex].To); var seeEvaluation = StaticExchangeEvaluation.Evaluate(attackingPiece, capturedPiece, attackers, defenders); moveValues[moveIndex] = (short)(MoveOrderingConstants.Capture + seeEvaluation); } else if (moves[moveIndex].Flags == MoveFlags.KingCastle || moves[moveIndex].Flags == MoveFlags.QueenCastle) { moveValues[moveIndex] = MoveOrderingConstants.Castling; } else { moveValues[moveIndex] = MoveOrderingConstants.PawnNearPromotion; } } }
public static void AssignQValues(BoardState board, Span <Move> moves, Span <short> moveValues, int movesCount) { var enemyColor = ColorOperations.Invert(board.ColorToMove); for (var moveIndex = 0; moveIndex < movesCount; moveIndex++) { if (moves[moveIndex].Flags == MoveFlags.EnPassant) { moveValues[moveIndex] = MoveOrderingConstants.EnPassant; } else { var attackingPiece = board.PieceTable[moves[moveIndex].From]; var capturedPiece = board.PieceTable[moves[moveIndex].To]; var attackers = board.GetAttackingPiecesWithColor(board.ColorToMove, moves[moveIndex].To); var defenders = board.GetAttackingPiecesWithColor(enemyColor, moves[moveIndex].To); var seeEvaluation = StaticExchangeEvaluation.Evaluate(attackingPiece, capturedPiece, attackers, defenders); moveValues[moveIndex] = seeEvaluation; } } }