Skip to content

Commit

Permalink
最大手数を指定できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
nodchip committed Jan 9, 2021
1 parent 429452f commit d4b23dc
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 17 deletions.
7 changes: 4 additions & 3 deletions TanukiColiseum/Coliseum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void Run(Options options, string logFolderPath)
{"ConsiderBookMoveCount", options.ConsiderBookMoveCount1},
{"IgnoreBookPly", options.IgnoreBookPly1},
{"BookDepthLimit", "0"},
{"MaxMovesToDraw", "256"},
{"MaxMovesToDraw", options.MaxMovesToDraw.ToString()},
{"ThreadIdOffset", (gameIndex * threadIdStride).ToString()},
{"LargePageEnable", "false"},
};
Expand Down Expand Up @@ -143,7 +143,7 @@ public void Run(Options options, string logFolderPath)
{"ConsiderBookMoveCount", options.ConsiderBookMoveCount2},
{"IgnoreBookPly", options.IgnoreBookPly2},
{"BookDepthLimit", "0"},
{"MaxMovesToDraw", "256"},
{"MaxMovesToDraw", options.MaxMovesToDraw.ToString()},
{"ThreadIdOffset", (gameIndex * threadIdStride).ToString()},
{"LargePageEnable", "false"},
};
Expand All @@ -163,7 +163,8 @@ public void Run(Options options, string logFolderPath)
options.NodesRandomEveryMove1, options.NodesRandomEveryMove2, options.Time1,
options.Time2, options.Byoyomi1, options.Byoyomi2, options.Inc1, options.Inc2,
options.Rtime1, options.Rtime2, engine1, engine2, options.NumBookMoves,
openings, sfenFilePath, sqlite3FilePath, ShowErrorMessage));
options.MaxMovesToDraw, openings, sfenFilePath, sqlite3FilePath,
ShowErrorMessage, this));
}

Console.WriteLine("Initialized engines...");
Expand Down
8 changes: 3 additions & 5 deletions TanukiColiseum/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace TanukiColiseum
{
public class Engine
{
private const int MaxMoves = 320;
private static readonly TimeSpan ProcessWaitTime = TimeSpan.FromMinutes(1);
private Process Process = new Process();
private Coliseum Coliseum;
Expand Down Expand Up @@ -180,7 +179,7 @@ private void HandleReadyok(List<string> command)
private void HandleBestmove(List<string> command)
{
var game = Coliseum.Games[GameIndex];
if (command[1] == "resign" || command[1] == "win" || game.Moves.Count >= MaxMoves)
if (command[1] == "resign" || command[1] == "win")
{
int engineWin;
int blackWhiteWin;
Expand Down Expand Up @@ -252,10 +251,9 @@ private void HandleBestmove(List<string> command)
}
}

game.OnMove(move);

lastInfoCommand = null;
game.Go();

game.OnMove(move);
}
}

Expand Down
30 changes: 27 additions & 3 deletions TanukiColiseum/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Move
}

private int NumBookMoves;
private int MaxMovesToDraw;
public List<Move> Moves { get; } = new List<Move>();
public int Turn { get; private set; }
public int InitialTurn { get; private set; }
Expand All @@ -55,12 +56,14 @@ public class Move
private static object WriteResultLock = new object();
private static int globalGameId = 0;
private DateTime goDateTime;
private Coliseum coliseum;

public Game(int initialTurn, int nodes1, int nodes2, int nodesRandomPercent1,
int nodesRandomPercent2, bool nodesRandomEveryMove1, bool nodesRandomEveryMove2,
int time1, int time2, int byoyomi1, int byoyomi2, int inc1, int inc2, int rtime1,
int rtime2, Engine engine1, Engine engine2, int numBookMoves, string[] openings,
string sfenFilePath, string sqlite3FilePath, ErrorHandler ShowErrorMessage)
int rtime2, Engine engine1, Engine engine2, int numBookMoves, int maxMovesToDraw,
string[] openings, string sfenFilePath, string sqlite3FilePath,
ErrorHandler ShowErrorMessage, Coliseum coliseum)
{
this.InitialTurn = initialTurn;
this.Nodes = new int[] { nodes1, nodes2 };
Expand All @@ -74,10 +77,12 @@ public Game(int initialTurn, int nodes1, int nodes2, int nodesRandomPercent1,
this.Engines.Add(engine1);
this.Engines.Add(engine2);
this.NumBookMoves = numBookMoves;
this.MaxMovesToDraw = maxMovesToDraw;
this.Openings = openings;
this.sfenFilePath = sfenFilePath;
this.sqlite3FilePath = sqlite3FilePath;
this.ShowErrorMessage = ShowErrorMessage;
this.coliseum = coliseum;
}

public void OnNewGame()
Expand Down Expand Up @@ -194,10 +199,29 @@ public void OnMove(Move move)

Moves.Add(move);
Turn ^= 1;

if (Moves.Count >= MaxMovesToDraw)
{
// 引き分け
int engineWin = 0;
int blackWhiteWin = 0;
bool draw = true;
Game.Result result = Game.Result.Draw;
bool declaration = false;

// 次の対局を開始する
// 先にGame.OnGameFinished()を読んでゲームの状態を停止状態に移行する
OnGameFinished(result);
coliseum.OnGameFinished(engineWin, blackWhiteWin, draw, declaration, InitialTurn);
}
else
{
Go();
}
}

/// <summary>
/// 宗教した場合に呼ばれる
/// 終局した場合に呼ばれる
/// </summary>
/// <param name="win"></param>
public void OnGameFinished(Result result)
Expand Down
9 changes: 9 additions & 0 deletions TanukiColiseum/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class MainModel : INotifyPropertyChanged
[DataMember]
public ReactiveProperty<int> NumBookMoves { get; set; } = new ReactiveProperty<int>(24);

[DataMember]
public ReactiveProperty<int> MaxMovesToDraw { get; set; } = new ReactiveProperty<int>(320);

[DataMember]
public ReactiveProperty<string> SfenFilePath { get; set; } = new ReactiveProperty<string>("records2016_10818.sfen");

Expand Down Expand Up @@ -265,6 +268,11 @@ public void Load(string filePath)
model.NodesRandomEveryMove2 = new ReactiveProperty<bool>(true);
}

if (model.MaxMovesToDraw == null)
{
model.MaxMovesToDraw = new ReactiveProperty<int>(320);
}

CopyFrom(model);
}

Expand All @@ -282,6 +290,7 @@ public void CopyFrom(MainModel model)
BookFileName1.Value = model.BookFileName1.Value;
BookFileName2.Value = model.BookFileName2.Value;
NumBookMoves.Value = model.NumBookMoves.Value;
MaxMovesToDraw.Value = model.MaxMovesToDraw.Value;
SfenFilePath.Value = model.SfenFilePath.Value;
Nodes1.Value = model.Nodes1.Value;
Nodes2.Value = model.Nodes2.Value;
Expand Down
21 changes: 16 additions & 5 deletions TanukiColiseum/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -127,8 +128,18 @@
Grid.Row="4"
Grid.Column="0"
VerticalAlignment="Center"
Text="最大手数" />
<TextBox
Grid.Row="4"
Grid.Column="1"
Text="{Binding MaxMovesToDraw.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<TextBlock
Grid.Row="5"
Grid.Column="0"
VerticalAlignment="Center"
Text="開始局面ファイルパス" />
<Grid Grid.Row="4" Grid.Column="1">
<Grid Grid.Row="5" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
Expand All @@ -150,22 +161,22 @@
</Grid>

<TextBlock
Grid.Row="5"
Grid.Row="6"
Grid.Column="0"
VerticalAlignment="Center"
Text="NUMAノード数" />
<TextBox
Grid.Row="5"
Grid.Row="6"
Grid.Column="1"
Text="{Binding NumNumaNodes.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<TextBlock
Grid.Row="6"
Grid.Row="7"
Grid.Column="0"
VerticalAlignment="Center"
Text="表示更新間隔(ms)" />
<TextBox
Grid.Row="6"
Grid.Row="7"
Grid.Column="1"
Text="{Binding ProgressIntervalMs.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
Expand Down
8 changes: 8 additions & 0 deletions TanukiColiseum/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public class MainViewModel
[RangeAttribute(0, int.MaxValue)]
public ReactiveProperty<int> NumBookMoves { get; }

/// <summary>
/// 最大手数。この手数を超えて対局が続く場合は引き分けとなる。
/// </summary>
[RangeAttribute(0, int.MaxValue)]
public ReactiveProperty<int> MaxMovesToDraw { get; }

public ReactiveProperty<string> SfenFilePath { get; }

/// <summary>
Expand Down Expand Up @@ -224,6 +230,7 @@ public MainViewModel()
BookFileName1 = model.BookFileName1.ToReactivePropertyAsSynchronized(x => x.Value);
BookFileName2 = model.BookFileName2.ToReactivePropertyAsSynchronized(x => x.Value);
NumBookMoves = model.NumBookMoves.ToReactivePropertyAsSynchronized(x => x.Value);
MaxMovesToDraw = model.MaxMovesToDraw.ToReactivePropertyAsSynchronized(x => x.Value);
SfenFilePath = model.SfenFilePath.ToReactivePropertyAsSynchronized(x => x.Value);
Nodes1 = model.Nodes1.ToReactivePropertyAsSynchronized(x => x.Value);
Nodes2 = model.Nodes2.ToReactivePropertyAsSynchronized(x => x.Value);
Expand Down Expand Up @@ -344,6 +351,7 @@ private void OnStart()
BookFileName1 = BookFileName1.Value,
BookFileName2 = BookFileName2.Value,
NumBookMoves = NumBookMoves.Value,
MaxMovesToDraw = MaxMovesToDraw.Value,
SfenFilePath = SfenFilePath.Value,
Nodes1 = Nodes1.Value,
Nodes2 = Nodes2.Value,
Expand Down
9 changes: 8 additions & 1 deletion TanukiColiseum/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class Options
public string BookFileName1 { get; set; }
public string BookFileName2 { get; set; }
public int NumBookMoves { get; set; }

/// <summary>
/// 最大手数。この手数を超えて対局が続く場合は引き分けとなる。
/// </summary>
public int MaxMovesToDraw { get; set; }

public string SfenFilePath { get; set; }

/// <summary>
Expand Down Expand Up @@ -130,6 +136,7 @@ public MainModel ToModel()
model.BookFileName1.Value = BookFileName1;
model.BookFileName2.Value = BookFileName2;
model.NumBookMoves.Value = NumBookMoves;
model.MaxMovesToDraw.Value = MaxMovesToDraw;
model.SfenFilePath.Value = SfenFilePath;
model.Nodes1.Value = Nodes1;
model.Nodes2.Value = Nodes2;
Expand Down Expand Up @@ -160,7 +167,7 @@ public MainModel ToModel()

public string ToHumanReadableString(Engine engine1, Engine engine2)
{
return $@"対局数={NumGames} 同時対局数={NumConcurrentGames} ハッシュサイズ={HashMb} 開始手数={NumBookMoves} 開始局面ファイル={SfenFilePath} NUMAノード数={NumNumaNodes} 表示更新間隔(ms)={ProgressIntervalMs}
return $@"対局数={NumGames} 同時対局数={NumConcurrentGames} ハッシュサイズ={HashMb} 開始手数={NumBookMoves} 最大手数={MaxMovesToDraw} 開始局面ファイル={SfenFilePath} NUMAノード数={NumNumaNodes} 表示更新間隔(ms)={ProgressIntervalMs}
思考エンジン1 name={engine1.Name} author={engine1.Author} exeファイル={Engine1FilePath} 評価関数フォルダパス={Eval1FolderPath} 定跡手数={NumBookMoves1} 定跡ファイル名={BookFileName1} 思考ノード数={Nodes1} 思考ノード数に加える乱数(%)={NodesRandomPercent1} 思考ノード数の乱数を1手毎に変化させる={NodesRandomEveryMove1} 持ち時間(ms)={Time1} 秒読み時間(ms)={Byoyomi1} 加算時間(ms)={Inc1} 乱数付き思考時間(ms)={Rtime1} スレッド数={NumThreads1} BookEvalDiff={BookEvalDiff1} 定跡の採択率を考慮する={ConsiderBookMoveCount1} 定跡の手数を無視する={IgnoreBookPly1}
思考エンジン2 name={engine2.Name} author={engine2.Author} exeファイル={Engine2FilePath} 評価関数フォルダパス={Eval2FolderPath} 定跡手数={NumBookMoves2} 定跡ファイル名={BookFileName2} 思考ノード数={Nodes2} 思考ノード数に加える乱数(%)={NodesRandomPercent2} 思考ノード数の乱数を1手毎に変化させる={NodesRandomEveryMove2} 持ち時間(ms)={Time2} 秒読み時間(ms)={Byoyomi2} 加算時間(ms)={Inc2} 乱数付き思考時間(ms)={Rtime2} スレッド数={NumThreads2} BookEvalDiff={BookEvalDiff2} 定跡の採択率を考慮する={ConsiderBookMoveCount2} 定跡の手数を無視する={IgnoreBookPly2}
";
Expand Down
2 changes: 2 additions & 0 deletions TanukiColiseum/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static void Main(
string bookFileName1 = "no_book",
string bookFileName2 = "no_book",
int numBookMoves = 0,
int maxMovesToDraw = 320,
string sfenFilePath = "records2016_10818.sfen",
int numNumaNodes = 1,
int progressIntervalMs = 60 * 60 * 1000,
Expand Down Expand Up @@ -59,6 +60,7 @@ static void Main(
BookFileName1 = bookFileName1,
BookFileName2 = bookFileName2,
NumBookMoves = numBookMoves,
MaxMovesToDraw = maxMovesToDraw,
SfenFilePath = sfenFilePath,
Nodes1 = nodes1,
Nodes2 = nodes2,
Expand Down

0 comments on commit d4b23dc

Please sign in to comment.