Skip to content

Commit 1807217

Browse files
authored
Merge pull request #3 from Tearth/v3.0-dev
v3.0 (Luna), 12.12.2020
2 parents 3c950eb + d6793de commit 1807217

File tree

132 files changed

+4115
-582
lines changed

Some content is hidden

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

132 files changed

+4115
-582
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ MigrationBackup/
347347

348348
# Ionide (cross platform F# VS Code tools) working folder
349349
.ionide/
350+
351+
# Custom
350352
/cloc.exe
351353
/cloc.bat
352354
/Cosette.Arbiter/settings.json
355+
/Cosette.Arbiter/book.bin
356+
/Cosette.Tuner/settings.json
357+
/Cosette.Tuner/book.bin
358+
/Cosette.Tuner.Web/Database.sqlite
359+
/Cosette.Tuner.Web/wwwroot/lib/

CHANGELOG.md

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
# Version 3.0 (Luna), 12.12.2020
2+
- Added better time control for Arbiter
3+
- Added more UCI options
4+
- Added Tuner project
5+
- Added insufficient material detection
6+
- Added executable hash generator
7+
- Added abort when search lasts too long
8+
- Added legality checking of the hash table moves
9+
- Added SEE pruning in the quiescence search
10+
- Added fianchetto evaluation
11+
- Added internal iterative deepening
12+
- Added a lot of UCI options, allowing for full engine customization
13+
- Added multi-stage move ordering
14+
- Added multi-stage move generating
15+
- Fixed FEN parser when input didn't have halfmove clock and moves count
16+
- Fixed crash when the engine was receiving invalid position in UCI mode
17+
- Fixed UCI statistics
18+
- Improved time scheduler when incrementation time is present
19+
- Improved mobility calculation by rewarding for center control
20+
- Improved late move reduction conditions
21+
- Improved SEE accuracy (now includes x-ray attacks)
22+
- Improved king safety evaluation
23+
- Changed maximal moves count from 128 to 218 (according to Internet sources)
24+
- Reduced size of transposition table entry (from 12 bytes to 8 bytes)
25+
- Disabled most of the evaluation functions when the game is near to end
26+
- Disabled returning of exact transposition table entries in the PV nodes
27+
- Adjusted evaluation scores
28+
- Optimized king safety evaluation
29+
- Updated .NET Core runtime version to 5.0.100
30+
31+
Estimated strength: 2000 ELO
32+
133
# Version 2.0 (Darkness), 19.10.2020
234
- Added fifty-move rule detection
335
- Added new evaluation functions: pawn shield, bishop pair, doubled rooks, a rook on open file

Cosette.Arbiter/Cosette.Arbiter.csproj

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -17,6 +17,10 @@
1717
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
1818
</ItemGroup>
1919

20+
<ItemGroup>
21+
<ProjectReference Include="..\Cosette.Polyglot\Cosette.Polyglot.csproj" />
22+
</ItemGroup>
23+
2024
<ItemGroup>
2125
<None Update="book.bin">
2226
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+58-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
5+
using System.Security.Cryptography;
6+
using System.Text;
47
using Cosette.Arbiter.Settings;
58

69
namespace Cosette.Arbiter.Engine
710
{
811
public class EngineOperator
912
{
10-
private string _name;
13+
public Lazy<string> ExecutableHash;
14+
1115
private string _enginePath;
16+
private string _engineArguments;
1217
private Process _engineProcess;
1318

14-
public EngineOperator(string name, string path)
19+
public EngineOperator(string path, string arguments)
1520
{
16-
_name = name;
1721
_enginePath = path;
22+
_engineArguments = arguments;
23+
24+
ExecutableHash = new Lazy<string>(GetExecutableHash);
1825
}
1926

2027
public void Init()
2128
{
2229
_engineProcess = Process.Start(new ProcessStartInfo
2330
{
2431
FileName = _enginePath,
32+
Arguments = _engineArguments,
2533
CreateNoWindow = true,
2634
RedirectStandardInput = true,
2735
RedirectStandardOutput = true
@@ -30,20 +38,36 @@ public void Init()
3038
Write("uci");
3139
WaitForMessage("uciok");
3240

33-
SettingsLoader.Data.Options.ForEach(Write);
41+
ApplyOptions();
3442

3543
Write("isready");
3644
WaitForMessage("readyok");
3745
}
3846

47+
public void Restart()
48+
{
49+
if (!_engineProcess.HasExited)
50+
{
51+
_engineProcess.Close();
52+
}
53+
54+
Init();
55+
ApplyOptions();
56+
}
57+
3958
public void InitNewGame()
4059
{
4160
Write("ucinewgame");
4261
Write("isready");
4362
WaitForMessage("readyok");
4463
}
4564

46-
public BestMoveData Go(List<string> moves)
65+
public void ApplyOptions()
66+
{
67+
SettingsLoader.Data.Options.ForEach(Write);
68+
}
69+
70+
public BestMoveData Go(List<string> moves, int whiteClock, int blackClock)
4771
{
4872
var bestMoveData = new BestMoveData();
4973
var movesJoined = string.Join(' ', moves);
@@ -53,26 +77,22 @@ public BestMoveData Go(List<string> moves)
5377
Write($"position startpos moves {movesJoined}");
5478
}
5579

56-
Write($"go movetime {SettingsLoader.Data.MillisecondsPerMove}");
80+
Write($"go wtime {whiteClock} btime {blackClock} winc {SettingsLoader.Data.IncTime} binc {SettingsLoader.Data.IncTime}");
5781

5882
while (true)
5983
{
60-
try
84+
var response = Read();
85+
if (response.StartsWith("info depth"))
6186
{
62-
var response = Read();
63-
if (response.StartsWith("info depth"))
64-
{
65-
bestMoveData.LastInfoData = InfoData.FromString(response);
66-
}
67-
else if (response.StartsWith("bestmove"))
68-
{
69-
bestMoveData.BestMove = response.Split(' ')[1];
70-
break;
71-
}
87+
bestMoveData.LastInfoData = InfoData.FromString(response);
7288
}
73-
catch
89+
else if (response.StartsWith("bestmove"))
90+
{
91+
bestMoveData.BestMove = response.Split(' ')[1];
92+
break;
93+
}
94+
else if (response.StartsWith("error"))
7495
{
75-
Init();
7696
return null;
7797
}
7898
}
@@ -94,5 +114,24 @@ public void WaitForMessage(string message)
94114
{
95115
while (Read() != message) ;
96116
}
117+
118+
private string GetExecutableHash()
119+
{
120+
var md5 = new MD5CryptoServiceProvider();
121+
var path = _enginePath == "dotnet" ? _engineArguments : _enginePath;
122+
123+
using (var streamReader = new StreamReader(path))
124+
{
125+
md5.ComputeHash(streamReader.BaseStream);
126+
}
127+
128+
var hashBuilder = new StringBuilder();
129+
foreach (var b in md5.Hash)
130+
{
131+
hashBuilder.Append(b.ToString("x2"));
132+
}
133+
134+
return hashBuilder.ToString();
135+
}
97136
}
98137
}

Cosette.Arbiter/Settings/EngineData.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class EngineData
44
{
55
public string Name { get; set; }
66
public string Path { get; set; }
7+
public string Arguments { get; set; }
78
public int Rating { get; set; }
89
}
910
}

Cosette.Arbiter/Settings/SettingsModel.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ public class SettingsModel
88
public List<EngineData> Engines { get; set; }
99
public List<string> Options { get; set; }
1010

11+
[JsonProperty("base_time")]
12+
public int BaseTime { get; set; }
13+
14+
[JsonProperty("inc_time")]
15+
public int IncTime { get; set; }
16+
1117
[JsonProperty("polyglot_opening_book")]
1218
public string PolyglotOpeningBook { get; set; }
1319

1420
[JsonProperty("polyglot_max_moves")]
1521
public int PolyglotMaxMoves { get; set; }
1622

17-
[JsonProperty("milliseconds_per_move")]
18-
public int MillisecondsPerMove { get; set; }
19-
2023
[JsonProperty("max_moves_count")]
2124
public int MaxMovesCount { get; set; }
2225

Cosette.Arbiter/Tournament/ArchivedGame.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ public class ArchivedGame
55
public GameData GameData { get; }
66
public TournamentParticipant Opponent { get; }
77
public GameResult Result { get; }
8+
public bool TimeFlag { get; }
89

9-
public ArchivedGame(GameData gameData, TournamentParticipant opponent, GameResult result)
10+
public ArchivedGame(GameData gameData, TournamentParticipant opponent, GameResult result, bool timeFlag = false)
1011
{
1112
GameData = gameData;
1213
Opponent = opponent;
1314
Result = result;
15+
TimeFlag = timeFlag;
1416
}
1517
}
1618
}

Cosette.Arbiter/Tournament/GameData.cs

+26-2
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,44 @@ public class GameData
1010
public bool GameIsDone { get; private set; }
1111
public Color Winner { get; private set; }
1212

13+
public int WhiteClock { get; private set; }
14+
public int BlackClock { get; private set; }
15+
1316
private BestMoveData _lastBestMove;
1417
private Color _colorToMove;
1518

1619
public GameData(List<string> opening)
1720
{
18-
HalfMovesDone = opening;
21+
HalfMovesDone = new List<string>(opening);
22+
WhiteClock = SettingsLoader.Data.BaseTime;
23+
BlackClock = SettingsLoader.Data.BaseTime;
24+
1925
_colorToMove = Color.White;
2026
}
2127

2228
public void MakeMove(BestMoveData bestMoveData)
2329
{
2430
HalfMovesDone.Add(bestMoveData.BestMove);
2531
_lastBestMove = bestMoveData;
26-
32+
33+
var clock = _colorToMove == Color.White ? WhiteClock : BlackClock;
34+
clock -= bestMoveData.LastInfoData.Time;
35+
36+
if (clock <= 0)
37+
{
38+
GameIsDone = true;
39+
WhiteClock = _colorToMove == Color.White ? clock : WhiteClock;
40+
BlackClock = _colorToMove == Color.Black ? clock : BlackClock;
41+
42+
Winner = _colorToMove == Color.White ? Color.Black : Color.White;
43+
return;
44+
}
45+
46+
clock += SettingsLoader.Data.IncTime;
47+
48+
WhiteClock = _colorToMove == Color.White ? clock : WhiteClock;
49+
BlackClock = _colorToMove == Color.Black ? clock : BlackClock;
50+
2751
if (IsCheckmate() || bestMoveData.LastInfoData.ScoreCp >= 2000)
2852
{
2953
GameIsDone = true;

0 commit comments

Comments
 (0)