Skip to content

Commit dfd4c07

Browse files
authored
Merge pull request #6 from Tearth/v5.0-dev
v5.0 (Megumin), 12.04.2021
2 parents 4aa5d28 + 9607a3f commit dfd4c07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+610
-321
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
# Version 5.0 (Megumin), 12.04.2021
2+
- Added more detailed evaluation info in pawn hash table entry
3+
- Added futility pruning to quiescence search
4+
- Added reuse of killer table between moves
5+
- Added razoring
6+
- Added ability to stop the search if reliable mate score was found
7+
- Added search cut when enemy king is checked
8+
- Added detection of the open file next to the king in the evaluation
9+
- Added history heuristic veto in LMR
10+
- Added late move pruning
11+
- Fixed insufficient material detection when both sides had knight or bishop
12+
- Fixed threefold repetition detection
13+
- Fixed invalid depth in killer heuristic
14+
- Fixed memory usage issues during the search
15+
- Adjusted search parameters
16+
- Adjusted evaluation parameters
17+
- Allowed to use history heuristic values from the previous iterations
18+
- Allowed late move reduction when capture has a negative score
19+
- Improved time management when incrementation is present
20+
- Improved Fianchetto detection
21+
- Improved history table structure
22+
- Enabled support for BMI instruction set (only if CPU supports it)
23+
- Disabled futility pruning when enemy king is checked
24+
125
# Version 4.0 (Komekko), 22.01.2021
226
- Added Texel project
327
- Added check extension

Cosette.Arbiter/Engine/EngineOperator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public void Init()
3838
Write("uci");
3939
WaitForMessage("uciok");
4040

41+
Write("debug off");
42+
Write("isready");
43+
WaitForMessage("readyok");
44+
4145
ApplyOptions();
4246

4347
Write("isready");

Cosette.Arbiter/Settings/EngineData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ public class EngineData
55
public string Name { get; set; }
66
public string Path { get; set; }
77
public string Arguments { get; set; }
8-
public int Rating { get; set; }
98
}
109
}

Cosette.Arbiter/Settings/SettingsModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ public class SettingsModel
2525

2626
[JsonProperty("games_count")]
2727
public int GamesCount { get; set; }
28+
29+
[JsonProperty("gauntlet")]
30+
public bool Gauntlet { get; set; }
2831
}
2932
}

Cosette.Arbiter/Tournament/TournamentArbiter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public TournamentArbiter()
3030
_participants.Add(tournamentParticipant);
3131
}
3232

33-
_scheduler.Init(_participants.Count);
33+
_scheduler.Init(_participants.Count, SettingsLoader.Data.Gauntlet);
3434
}
3535

3636
public void Run()
@@ -131,13 +131,12 @@ private void WriteResults()
131131
{
132132
foreach (var participant in _participants)
133133
{
134-
var originalRating = participant.EngineData.Rating;
135-
var performance = participant.CalculatePerformanceRating() - originalRating;
134+
var performance = participant.CalculatePerformanceRating();
136135
var wonGamesPercent = participant.WonGamesPercent();
137136
var winsByTime = participant.History.Count(p => p.Result == GameResult.Win && p.TimeFlag);
138137
var lossesByTime = participant.History.Count(p => p.Result == GameResult.Loss && p.TimeFlag);
139138

140-
Console.WriteLine($"{participant.EngineData.Name} {originalRating} ELO ({performance:+0;-#}, {wonGamesPercent}%): " +
139+
Console.WriteLine($"{participant.EngineData.Name} ({performance:+0;-#}, {wonGamesPercent}%): " +
141140
$"{participant.Wins} wins ({winsByTime} by time), {participant.Losses} losses ({lossesByTime} by time), " +
142141
$"{participant.Draws} draws");
143142
Console.WriteLine($" === {participant.AverageDepth:F} average depth, {participant.AverageNodesCount} average nodes, " +

Cosette.Arbiter/Tournament/TournamentParticipant.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public int CalculatePerformanceRating()
3131
{
3232
if (History.Count == 0)
3333
{
34-
return EngineData.Rating;
34+
return 0;
3535
}
3636

37-
return (History.Sum(p => p.Opponent.EngineData.Rating) + 400 * (Wins - Losses)) / History.Count;
37+
return 400 * (Wins - Losses) / History.Count;
3838
}
3939

4040
public int WonGamesPercent()

Cosette.Arbiter/Tournament/TournamentScheduler.cs

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,64 @@ public class TournamentScheduler
77
private int _participantsCount;
88
private List<(int playerA, int playerB)> _pairs;
99

10-
public void Init(int participantsCount)
10+
public void Init(int participantsCount, bool gauntlet)
1111
{
1212
_participantsCount = participantsCount;
1313
_pairs = new List<(int playerA, int playerB)>();
1414

15-
if (_participantsCount % 2 != 0)
15+
if (gauntlet)
1616
{
17-
_participantsCount++;
17+
for (var gameNumber = 1; gameNumber < _participantsCount; gameNumber++)
18+
{
19+
_pairs.Add((0, gameNumber));
20+
}
1821
}
19-
20-
for (var gameNumber = 0; gameNumber < _participantsCount - 1; gameNumber++)
22+
else
2123
{
22-
var firstRow = new List<int>();
23-
var secondRow = new List<int>();
24-
var teamsCount = _participantsCount / 2;
24+
if (_participantsCount % 2 != 0)
25+
{
26+
_participantsCount++;
27+
}
2528

26-
firstRow.Add(1);
29+
for (var gameNumber = 0; gameNumber < _participantsCount - 1; gameNumber++)
30+
{
31+
var firstRow = new List<int>();
32+
var secondRow = new List<int>();
33+
var teamsCount = _participantsCount / 2;
2734

28-
var secondParticipant = _participantsCount - gameNumber;
29-
var currentParticipant = secondParticipant;
35+
firstRow.Add(1);
3036

31-
for (var i = 1; i < teamsCount; i++)
32-
{
33-
currentParticipant++;
34-
if (currentParticipant > _participantsCount)
37+
var secondParticipant = _participantsCount - gameNumber;
38+
var currentParticipant = secondParticipant;
39+
40+
for (var i = 1; i < teamsCount; i++)
3541
{
36-
currentParticipant = 2;
37-
}
42+
currentParticipant++;
43+
if (currentParticipant > _participantsCount)
44+
{
45+
currentParticipant = 2;
46+
}
3847

39-
firstRow.Add(currentParticipant);
40-
}
48+
firstRow.Add(currentParticipant);
49+
}
4150

42-
for (var i = 0; i < teamsCount; i++)
43-
{
44-
currentParticipant++;
45-
if (currentParticipant > _participantsCount)
51+
for (var i = 0; i < teamsCount; i++)
4652
{
47-
currentParticipant = 2;
48-
}
53+
currentParticipant++;
54+
if (currentParticipant > _participantsCount)
55+
{
56+
currentParticipant = 2;
57+
}
4958

50-
secondRow.Add(currentParticipant);
51-
}
59+
secondRow.Add(currentParticipant);
60+
}
5261

53-
secondRow.Reverse();
62+
secondRow.Reverse();
5463

55-
for (var i = 0; i < teamsCount; i++)
56-
{
57-
_pairs.Add((firstRow[i] - 1, secondRow[i] - 1));
64+
for (var i = 0; i < teamsCount; i++)
65+
{
66+
_pairs.Add((firstRow[i] - 1, secondRow[i] - 1));
67+
}
5868
}
5969
}
6070
}

Cosette.sln

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,80 +32,61 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosette.Tuner.Texel", "Cose
3232
EndProject
3333
Global
3434
GlobalSection(SolutionConfigurationPlatforms) = preSolution
35-
BMI|x64 = BMI|x64
3635
CCRL|x64 = CCRL|x64
3736
Debug|x64 = Debug|x64
3837
Release|x64 = Release|x64
3938
EndGlobalSection
4039
GlobalSection(ProjectConfigurationPlatforms) = postSolution
41-
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.BMI|x64.ActiveCfg = BMI|x64
42-
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.BMI|x64.Build.0 = BMI|x64
4340
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.CCRL|x64.ActiveCfg = CCRL|x64
4441
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.CCRL|x64.Build.0 = CCRL|x64
4542
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.Debug|x64.ActiveCfg = Debug|x64
4643
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.Debug|x64.Build.0 = Debug|x64
4744
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.Release|x64.ActiveCfg = Release|x64
4845
{B2BA9BD6-E1C2-437E-986D-A6C08568D770}.Release|x64.Build.0 = Release|x64
49-
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.BMI|x64.ActiveCfg = BMI|x64
50-
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.BMI|x64.Build.0 = BMI|x64
51-
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.CCRL|x64.ActiveCfg = CCRL|x64
52-
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.CCRL|x64.Build.0 = CCRL|x64
46+
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.CCRL|x64.ActiveCfg = Release|x64
47+
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.CCRL|x64.Build.0 = Release|x64
5348
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.Debug|x64.ActiveCfg = Debug|x64
5449
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.Debug|x64.Build.0 = Debug|x64
5550
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.Release|x64.ActiveCfg = Release|x64
5651
{DB4710F3-2692-42AD-8B93-C77B823CEFEB}.Release|x64.Build.0 = Release|x64
57-
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.BMI|x64.ActiveCfg = Release|Any CPU
58-
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.BMI|x64.Build.0 = Release|Any CPU
5952
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.CCRL|x64.ActiveCfg = Release|x64
6053
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.CCRL|x64.Build.0 = Release|x64
6154
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.Debug|x64.ActiveCfg = Debug|x64
6255
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.Debug|x64.Build.0 = Debug|x64
6356
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.Release|x64.ActiveCfg = Release|x64
6457
{DAB140A1-17EB-4688-8107-8C2AEA737AD6}.Release|x64.Build.0 = Release|x64
65-
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.BMI|x64.ActiveCfg = Release|Any CPU
66-
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.BMI|x64.Build.0 = Release|Any CPU
6758
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.CCRL|x64.ActiveCfg = Release|x64
6859
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.CCRL|x64.Build.0 = Release|x64
6960
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.Debug|x64.ActiveCfg = Debug|x64
7061
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.Debug|x64.Build.0 = Debug|x64
7162
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.Release|x64.ActiveCfg = Release|x64
7263
{446DB14C-F30C-4A0C-86AB-8CCF3CF7CB53}.Release|x64.Build.0 = Release|x64
73-
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.BMI|x64.ActiveCfg = Release|Any CPU
74-
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.BMI|x64.Build.0 = Release|Any CPU
7564
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.CCRL|x64.ActiveCfg = Release|x64
7665
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.CCRL|x64.Build.0 = Release|x64
7766
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.Debug|x64.ActiveCfg = Debug|x64
7867
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.Debug|x64.Build.0 = Debug|x64
7968
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.Release|x64.ActiveCfg = Release|x64
8069
{AB6B0059-A70B-4A8F-9F55-22DB3A92E83F}.Release|x64.Build.0 = Release|x64
81-
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.BMI|x64.ActiveCfg = Release|Any CPU
82-
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.BMI|x64.Build.0 = Release|Any CPU
8370
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.CCRL|x64.ActiveCfg = Release|x64
8471
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.CCRL|x64.Build.0 = Release|x64
8572
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.Debug|x64.ActiveCfg = Debug|x64
8673
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.Debug|x64.Build.0 = Debug|x64
8774
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.Release|x64.ActiveCfg = Release|x64
8875
{0EEBE02C-E239-4727-8B8B-6ADD603B73B7}.Release|x64.Build.0 = Release|x64
89-
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.BMI|x64.ActiveCfg = Release|Any CPU
90-
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.BMI|x64.Build.0 = Release|Any CPU
9176
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.CCRL|x64.ActiveCfg = Release|x64
9277
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.CCRL|x64.Build.0 = Release|x64
9378
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.Debug|x64.ActiveCfg = Debug|x64
9479
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.Debug|x64.Build.0 = Debug|x64
9580
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.Release|x64.ActiveCfg = Release|x64
9681
{5AD2DF22-EEB4-4696-B4D0-FA97C1DE871E}.Release|x64.Build.0 = Release|x64
97-
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.BMI|x64.ActiveCfg = Release|Any CPU
98-
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.BMI|x64.Build.0 = Release|Any CPU
9982
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.CCRL|x64.ActiveCfg = Release|x64
10083
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.CCRL|x64.Build.0 = Release|x64
10184
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.Debug|x64.ActiveCfg = Debug|x64
10285
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.Debug|x64.Build.0 = Debug|x64
10386
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.Release|x64.ActiveCfg = Release|x64
10487
{97466830-B71A-4DC4-AD43-D92CC6F867DE}.Release|x64.Build.0 = Release|x64
105-
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.BMI|x64.ActiveCfg = Debug|Any CPU
106-
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.BMI|x64.Build.0 = Debug|Any CPU
107-
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.CCRL|x64.ActiveCfg = Debug|x64
108-
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.CCRL|x64.Build.0 = Debug|x64
88+
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.CCRL|x64.ActiveCfg = Release|x64
89+
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.CCRL|x64.Build.0 = Release|x64
10990
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.Debug|x64.ActiveCfg = Debug|x64
11091
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.Debug|x64.Build.0 = Debug|x64
11192
{AC5C8DF9-E46A-4F9B-9AE9-7380E3044263}.Release|x64.ActiveCfg = Release|x64

Cosette/Cosette.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<TargetFramework>net5.0</TargetFramework>
66
<Configurations>Debug;Release;BMI;CCRL</Configurations>
77
<Platforms>x64</Platforms>
8-
<Version>4.0.0</Version>
9-
<FileVersion>4.0.0.0</FileVersion>
8+
<Version>5.0.0</Version>
9+
<FileVersion>5.0.0.0</FileVersion>
1010
</PropertyGroup>
1111

1212
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

Cosette/Engine/Ai/Ordering/HistoryHeuristic.cs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,68 @@ public static class HistoryHeuristic
1111
static HistoryHeuristic()
1212
{
1313
_historyMoves = new uint[2][][];
14-
_historyMoves[Color.White] = new uint[64][];
15-
_historyMoves[Color.Black] = new uint[64][];
14+
_historyMoves[Color.White] = new uint[6][];
15+
_historyMoves[Color.Black] = new uint[6][];
1616

17-
for (var from = 0; from < 64; from++)
17+
for (var piece = 0; piece < 6; piece++)
1818
{
19-
_historyMoves[Color.White][from] = new uint[64];
20-
_historyMoves[Color.Black][from] = new uint[64];
19+
_historyMoves[Color.White][piece] = new uint[64];
20+
_historyMoves[Color.Black][piece] = new uint[64];
2121
}
2222

23-
_max = MoveOrderingConstants.HistoryHeuristicMaxScore;
23+
_max = 1;
2424
}
2525

26-
public static void AddHistoryMove(int color, int from, int to, int depth)
26+
public static void AddHistoryMove(int color, int piece, int to, int depth)
2727
{
28-
var newValue = _historyMoves[color][from][to] + (uint)(depth * depth);
28+
var newValue = _historyMoves[color][piece][to] + (uint)(depth * depth);
2929

3030
_max = Math.Max(_max, newValue);
31-
_historyMoves[color][from][to] = newValue;
31+
_historyMoves[color][piece][to] = newValue;
3232
}
3333

34-
public static short GetHistoryMoveValue(int color, int from, int to)
34+
public static short GetMoveValue(int color, int piece, int to, uint scale)
3535
{
36-
return (short)(_historyMoves[color][from][to] / ((float)_max / MoveOrderingConstants.HistoryHeuristicMaxScore));
36+
return (short)(_historyMoves[color][piece][to] * scale / _max);
37+
}
38+
39+
public static uint GetRawMoveValue(int color, int piece, int to)
40+
{
41+
return _historyMoves[color][piece][to];
42+
}
43+
44+
public static uint GetMaxValue()
45+
{
46+
return _max;
47+
}
48+
49+
public static void AgeValues()
50+
{
51+
for (var color = 0; color < 2; color++)
52+
{
53+
for (var piece = 0; piece < 6; piece++)
54+
{
55+
for (var to = 0; to < 64; to++)
56+
{
57+
_historyMoves[color][piece][to] /= 2;
58+
}
59+
}
60+
}
61+
62+
_max = Math.Max(_max / 2, 1);
3763
}
3864

3965
public static void Clear()
4066
{
4167
for (var color = 0; color < 2; color++)
4268
{
43-
for (var from = 0; from < 64; from++)
69+
for (var piece = 0; piece < 6; piece++)
4470
{
45-
Array.Clear(_historyMoves[color][from], 0, 64);
71+
Array.Clear(_historyMoves[color][piece], 0, 64);
4672
}
4773
}
4874

49-
_max = MoveOrderingConstants.HistoryHeuristicMaxScore;
75+
_max = 1;
5076
}
5177
}
5278
}

0 commit comments

Comments
 (0)