Update difficulty handling in ChessEngine
The difficulty handling logic has been modified to better determine when to use the best move in the ChessEngine class. A new method called ShouldUseBestMove(int difficulty) has been added to provide a probabilistic approach towards choosing the best move based on the provided difficulty level.
This commit is contained in:
@@ -43,7 +43,7 @@ public class ChessEngine
|
||||
var result = _engine.IDDFS(depth, 10);
|
||||
_engine.Game.ResetCurrentPositionToBeforeSearchState();
|
||||
|
||||
if (difficulty > 4)
|
||||
if (ShouldUseBestMove(difficulty))
|
||||
{
|
||||
// If difficulty is higher than 5, we should use the best move
|
||||
return result.BestMove.ToEPDString(positionClone);
|
||||
@@ -54,4 +54,12 @@ public class ChessEngine
|
||||
return result.Moves[new Random().Next(result.Moves.Count)].ToEPDString(positionClone);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldUseBestMove(int difficulty)
|
||||
{
|
||||
// For difficulties 1-6, gradually increase the probability of returning true
|
||||
var probability = (difficulty - 1) / 5.0; // 0.0 for 1, 0.2 for 2, ..., 1.0 for 6
|
||||
var random = new Random();
|
||||
return random.NextDouble() < probability;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user