Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧬 Move ordering: MVV-LVA + caphist -> MVV + caphist SPSA'ed high level #1340

Closed
wants to merge 13 commits into from
17 changes: 16 additions & 1 deletion src/Lynx/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public sealed class GeneralSettings
{
public bool EnableLogging { get; set; }

public bool EnableTuning { get; set; }
public bool EnableTuning { get; set; } = true;
}

public sealed class EngineSettings
Expand Down Expand Up @@ -236,6 +236,21 @@ public int Threads
public int HistoryPrunning_Margin { get; set; } = -1940;

#endregion

[SPSA<int>(0, 1000, 100)]
public int MVV_Pawn { get; set; } = 63;

[SPSA<int>(2500, 3500, 100)]
public int MVV_Knight { get; set; } = 2958;

[SPSA<int>(2500, 3500, 100)]
public int MVV_Bishop { get; set; } = 2938;

[SPSA<int>(5000, 6500, 100)]
public int MVV_Rook { get; set; } = 5865;

[SPSA<int>(9000, 10500, 100)]
public int MVV_Queen { get; set; } = 9644;
}

[JsonSourceGenerationOptions(
Expand Down
6 changes: 3 additions & 3 deletions src/Lynx/EvaluationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ static EvaluationConstants()
/* k */ [1000, 3500, 4001, 5000, 11000, 0, 0, 0, 0, 0, 0 ], // 0]
];

public static ReadOnlySpan<int> MVV_PieceValues =>
public static readonly int[] MVV_PieceValues =
[
1000, 3500, 4000, 5000, 11000, 0,
1000, 3500, 4000, 5000, 11000, 0,
Configuration.EngineSettings.MVV_Pawn, Configuration.EngineSettings.MVV_Knight, Configuration.EngineSettings.MVV_Bishop, Configuration.EngineSettings.MVV_Rook, Configuration.EngineSettings.MVV_Queen, 0,
Configuration.EngineSettings.MVV_Pawn, Configuration.EngineSettings.MVV_Knight, Configuration.EngineSettings.MVV_Bishop, Configuration.EngineSettings.MVV_Rook, Configuration.EngineSettings.MVV_Queen, 0,
0
];

Expand Down
5 changes: 2 additions & 3 deletions src/Lynx/Search/MoveOrdering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Lynx;
public sealed partial class Engine
{
/// <summary>
/// Returns the score evaluation of a move taking into account <paramref name="bestMoveTTCandidate"/>, <see cref="MostValueableVictimLeastValuableAttacker"/>, <see cref="_killerMoves"/> and <see cref="_quietHistory"/>
/// Returns the score evaluation of a move taking into account <paramref name="bestMoveTTCandidate"/>, <see cref="MVV_PieceValues"/>, <see cref="_killerMoves"/> and <see cref="_quietHistory"/>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal int ScoreMove(Move move, int ply, bool isNotQSearch, ShortMove bestMoveTTCandidate = default)
Expand Down Expand Up @@ -48,8 +48,7 @@ internal int ScoreMove(Move move, int ply, bool isNotQSearch, ShortMove bestMove
Debug.Assert(capturedPiece != (int)Piece.K && capturedPiece != (int)Piece.k, $"{move.UCIString()} capturing king is generated in position {Game.CurrentPosition.FEN()}");

return baseCaptureScore
+ MostValueableVictimLeastValuableAttacker[piece][capturedPiece]
//+ EvaluationConstants.MVV_PieceValues[capturedPiece]
+ MVV_PieceValues[capturedPiece]
+ _captureHistory[CaptureHistoryIndex(piece, move.TargetSquare(), capturedPiece)];
}

Expand Down
41 changes: 41 additions & 0 deletions src/Lynx/UCIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,47 @@ private void HandleSetOption(ReadOnlySpan<char> command)
break;
}

case "mvv_pawn":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.MVV_Pawn = value;
}
break;
}
case "mvv_knight":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.MVV_Knight = value;
}
break;
}
case "mvv_bishop":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.MVV_Bishop = value;
}
break;
}
case "mvv_rook":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.MVV_Rook = value;
}
break;
}
case "mvv_queen":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.MVV_Queen = value;
}
break;
}

#endregion

default:
Expand Down
4 changes: 2 additions & 2 deletions tests/Lynx.Test/Model/MoveScoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MoveScoreTest : BaseTest
/// 2 P P P B B P P P
/// 1 R . . . K . . R
/// a b c d e f g h
/// This tests indirectly <see cref="EvaluationConstants.MostValueableVictimLeastValuableAttacker"/>
/// This tests indirectly <see cref="EvaluationConstants.MostValueableVictimLeastValuableAttacker"/> and <see cref="MVV_PieceValues"/>
/// </summary>
[TestCase(Constants.TrickyTestPositionFEN)]
public void MoveScore(string fen)
Expand Down Expand Up @@ -61,6 +61,6 @@ public void MoveScoreEnPassant(string fen, string moveWithHighestScore)
var allMoves = MoveGenerator.GenerateAllMoves(engine.Game.CurrentPosition).OrderByDescending(move => engine.ScoreMove(move, default, default)).ToList();

Assert.AreEqual(moveWithHighestScore, allMoves[0].UCIString());
Assert.AreEqual(EvaluationConstants.GoodCaptureMoveBaseScoreValue + EvaluationConstants.MostValueableVictimLeastValuableAttacker[0][6], engine.ScoreMove(allMoves[0], default, default));
Assert.AreEqual(EvaluationConstants.GoodCaptureMoveBaseScoreValue + EvaluationConstants.MVV_PieceValues[0], engine.ScoreMove(allMoves[0], default, default));
}
}
Loading