Update difficulty levels in ChessEngine

Added a new difficulty level and adjusted the ranking of the "Unbeatable" level. Changes also include a minor adjustment in the calculation of the depth variable for the GetBestMove function. Comments with the old difficulty levels have been removed from both the ChessEngine service and the _Layout view.
This commit is contained in:
Anduin Xue
2024-07-03 15:39:15 +00:00
parent 9bc235a984
commit b7a1caa5a5
2 changed files with 5 additions and 17 deletions
@@ -28,25 +28,19 @@ public class ChessEngine
4 => "Hard",
5 => "Brutal",
6 => "Grandmaster",
7 => "Unbeatable",
7 => "Torture",
8 => "Unbeatable",
_ => "Unknown"
};
}
public string GetBestMove(string fen, int difficulty)
// 1: Chimpanzee
// 2: Easy
// 3: Intermediate
// 4: Hard
// 5: Brutal
// 6: Grandmaster
// 7: Unbeatable
{
_engine.AdjustPosition($"position fen {fen}");
var positionClone = new Position(_engine.Game.CurrentPosition);
// Depth = difficulty, 50% of chance to be difficulty + 1
var depth = difficulty + (new Random().Next(2) == 0 ? 1 : 0);
var depth = difficulty - 1 + (new Random().Next(2) == 0 ? 1 : 0);
var result = _engine.IDDFS(depth, 10);
_engine.Game.ResetCurrentPositionToBeforeSearchState();
@@ -79,20 +79,14 @@
</button>
</div>
<div class="modal-body">
@* // 1: Chimpanzee *@
@* // 2: Easy *@
@* // 3: Intermediate *@
@* // 4: Hard *@
@* // 5: Brutal *@
@* // 6: Grandmaster *@
@* // 7: Unbeatable *@
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="1">Chimpanzee</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="2">Easy</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="3">Intermediate</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="4">Hard</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="5">Brutal</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="6">Grandmaster</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="7">Unbeatable</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="7">Torture</a>
<a class="btn btn-secondary btn-block btn-difficulty" asp-controller="Pve" asp-action="New" asp-route-difficulty="8">Unbeatable</a>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>