Skip to content

Commit

Permalink
Fix all timer issues (SebLague#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Whiting <[email protected]>
  • Loading branch information
Gigantua and jw1912 authored Sep 13, 2023
1 parent 037724f commit 8d4c807
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Chess-Challenge/src/My Bot/MyBot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ChessChallenge.API;
using ChessChallenge.API;
using System;

public class MyBot : IChessBot
Expand Down Expand Up @@ -28,23 +28,23 @@ public MyBot()

public Move ThinkInternal(Board board, Timer timer, int maxDepth = 50, bool report = true)
#else
public Move Think(Board board, Timer timer)
public Move Think(Board board, ChessChallenge.API.Timer timer)
#endif
{
Move bestMoveRoot = default;
var killers = new Move[128];

int maxTime = timer.MillisecondsRemaining / 30, iterDepth = 1;
#if UCI
nodes = 0;
for (int depth = 0; ++depth <= maxDepth && timer.MillisecondsElapsedThisTurn < timer.MillisecondsRemaining / 30;)
#else
for (int depth = 0; ++depth <= 50 && timer.MillisecondsElapsedThisTurn < timer.MillisecondsRemaining / 30;)
while (timer.MillisecondsElapsedThisTurn < maxTime)
#endif
{
#if UCI
int score =
#endif
Search(-30000, 30000, depth, 0);
Search(-30000, 30000, iterDepth++, 0);
#if UCI
if (report && timer.MillisecondsElapsedThisTurn < timer.MillisecondsRemaining / 30)
{
Expand Down Expand Up @@ -104,7 +104,7 @@ int Search(int alpha, int beta, int depth, int ply)

foreach (Move move in moves)
{
if (timer.MillisecondsElapsedThisTurn >= timer.MillisecondsRemaining / 10)
if (timer.MillisecondsElapsedThisTurn >= maxTime * 2)
return 30000;

board.MakeMove(move);
Expand All @@ -116,7 +116,8 @@ int Search(int alpha, int beta, int depth, int ply)
alpha = score;
hashMove = move;
if (ply == 0) bestMoveRoot = move;
if (alpha >= beta) {
if (alpha >= beta)
{
if (!move.IsCapture)
killers[ply] = move;
break;
Expand Down

0 comments on commit 8d4c807

Please sign in to comment.