Reduce search depth and fix turn-checking method
The search depth for the iterative deepening depth-first search (IDDFS) in the ChessEngine has been reduced for performance reasons. In addition, the method for checking whose turn it is in the PveController has been altered. This now checks the color of the pieces, rather than looking up the player's ID, yielding more accurate results.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Drawing;
|
||||
using Aiursoft.AiurObserver;
|
||||
using Aiursoft.AiurObserver.WebSocket;
|
||||
using Aiursoft.ChessServer.Data;
|
||||
@@ -6,6 +7,7 @@ using Aiursoft.CSTools.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Aiursoft.AiurObserver.Extensions;
|
||||
using Aiursoft.ChessServer.Services;
|
||||
using Chess;
|
||||
|
||||
namespace Aiursoft.ChessServer.Controllers;
|
||||
|
||||
@@ -22,6 +24,7 @@ public class PveController(
|
||||
// Add a computer player
|
||||
var computerId = Guid.NewGuid();
|
||||
database.GetOrAddPlayer(computerId).NickName = "Computer";
|
||||
//var asyncLock = new SemaphoreSlim(1, 1);
|
||||
|
||||
// Create a challenge
|
||||
var player = database.GetOrAddPlayer(playerId);
|
||||
@@ -53,7 +56,8 @@ public class PveController(
|
||||
subscription = client.Subscribe(async fen =>
|
||||
{
|
||||
// When fen changes, it means someone has made a move. If it's the computer's turn, let the computer respond.
|
||||
if (acceptedChallenge?.GetTurnPlayer().Id == computerId)
|
||||
var board = ChessBoard.LoadFromFen(fen);
|
||||
if (board.Turn == PieceColor.Black)
|
||||
{
|
||||
// Wait for the UI to update
|
||||
await Task.Delay(300);
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ChessEngine
|
||||
public string GetBestMove(string fen)
|
||||
{
|
||||
_engine.AdjustPosition($"position fen {fen}");
|
||||
return _engine.IDDFS(5, int.MaxValue)
|
||||
return _engine.IDDFS(1, int.MaxValue)
|
||||
.BestMove
|
||||
.ToEPDString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user