Add increment option
This commit is contained in:
parent
78f59b46c4
commit
4438d69e7e
4 changed files with 26 additions and 12 deletions
|
@ -9,6 +9,11 @@ namespace ChessChallenge.API
|
|||
/// </summary>
|
||||
public readonly int GameStartTimeMilliseconds;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time (in milliseconds) that gets added to the clock after each turn
|
||||
/// </summary>
|
||||
public readonly int IncrementMilliseconds;
|
||||
|
||||
/// <summary>
|
||||
/// Amount of time elapsed since the current player started thinking (in milliseconds)
|
||||
/// </summary>
|
||||
|
@ -33,12 +38,13 @@ namespace ChessChallenge.API
|
|||
sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
}
|
||||
|
||||
public Timer(int millisRemaining, int opponentMillisRemaining, int startingTimeMillis)
|
||||
public Timer(int remainingMs, int opponentRemainingMs, int startingMs, int incrementMs = 0)
|
||||
{
|
||||
millisRemainingAtStartOfTurn = millisRemaining;
|
||||
millisRemainingAtStartOfTurn = remainingMs;
|
||||
sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
GameStartTimeMilliseconds = startingTimeMillis;
|
||||
OpponentMillisecondsRemaining = opponentMillisRemaining;
|
||||
GameStartTimeMilliseconds = startingMs;
|
||||
OpponentMillisecondsRemaining = opponentRemainingMs;
|
||||
IncrementMilliseconds = incrementMs;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
|
@ -146,7 +146,7 @@ namespace ChessChallenge.Application
|
|||
API.Board botBoard = new(board);
|
||||
try
|
||||
{
|
||||
API.Timer timer = new(PlayerToMove.TimeRemainingMs, PlayerNotOnMove.TimeRemainingMs, GameDurationMilliseconds);
|
||||
API.Timer timer = new(PlayerToMove.TimeRemainingMs, PlayerNotOnMove.TimeRemainingMs, GameDurationMilliseconds, IncrementMilliseconds);
|
||||
API.Move move = PlayerToMove.Bot.Think(botBoard, timer);
|
||||
return new Move(move.RawValue);
|
||||
}
|
||||
|
@ -227,6 +227,7 @@ namespace ChessChallenge.Application
|
|||
{
|
||||
if (IsLegal(chosenMove))
|
||||
{
|
||||
PlayerToMove.AddIncrement(IncrementMilliseconds);
|
||||
if (PlayerToMove.IsBot)
|
||||
{
|
||||
moveToPlay = chosenMove;
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace ChessChallenge.Application
|
|||
|
||||
// Game settings
|
||||
public const int GameDurationMilliseconds = 60 * 1000;
|
||||
public const int IncrementMilliseconds = 0 * 1000;
|
||||
public const float MinMoveDelay = 0;
|
||||
public static readonly bool RunBotsOnSeparateThread = true;
|
||||
|
||||
|
|
|
@ -12,14 +12,15 @@ namespace ChessChallenge.Application
|
|||
public readonly HumanPlayer? Human;
|
||||
|
||||
double secondsElapsed;
|
||||
int baseTimeMS;
|
||||
int incrementAddedMs;
|
||||
int baseTimeMs;
|
||||
|
||||
public ChessPlayer(object instance, ChallengeController.PlayerType type, int baseTimeMS = int.MaxValue)
|
||||
public ChessPlayer(object instance, ChallengeController.PlayerType type, int baseTimeMs = int.MaxValue)
|
||||
{
|
||||
this.PlayerType = type;
|
||||
Bot = instance as IChessBot;
|
||||
Human = instance as HumanPlayer;
|
||||
this.baseTimeMS = baseTimeMS;
|
||||
this.baseTimeMs = baseTimeMs;
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,19 +40,24 @@ namespace ChessChallenge.Application
|
|||
secondsElapsed += dt;
|
||||
}
|
||||
|
||||
public void AddIncrement(int incrementMs)
|
||||
{
|
||||
incrementAddedMs += incrementMs;
|
||||
}
|
||||
|
||||
public int TimeRemainingMs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (baseTimeMS == int.MaxValue)
|
||||
if (baseTimeMs == int.MaxValue)
|
||||
{
|
||||
return baseTimeMS;
|
||||
return baseTimeMs;
|
||||
}
|
||||
return (int)Math.Ceiling(Math.Max(0, baseTimeMS - secondsElapsed * 1000.0));
|
||||
return (int)Math.Ceiling(Math.Max(0, baseTimeMs - secondsElapsed * 1000.0 + incrementAddedMs));
|
||||
}
|
||||
}
|
||||
|
||||
public void SubscribeToMoveChosenEventIfHuman(Action<ChessChallenge.Chess.Move> action)
|
||||
public void SubscribeToMoveChosenEventIfHuman(Action<Chess.Move> action)
|
||||
{
|
||||
if (Human != null)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue