Skip to content

Commit

Permalink
♻️: add GetScore for bot moves
Browse files Browse the repository at this point in the history
  • Loading branch information
VsIG-official committed Nov 3, 2021
1 parent 8f5191d commit f11db9a
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions Quoridor.Model/Player/MinimaxAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public MinimaxAlgorithm(QuoridorGame game)
continue;
}

int score = Minimax(Depth, int.MinValue, int.MaxValue, false);

_game.UnplaceWall(wall);
int score = GetWallScore(wall);

if (score >= bestScore)
{
Expand All @@ -45,10 +43,7 @@ public MinimaxAlgorithm(QuoridorGame game)

foreach (Cell move in moves)
{
var beforeMove = _game.CurrentPlayer.CurrentCell;
_game.MakeMove(move);
int score = Minimax(Depth, int.MinValue, int.MaxValue, false);
_game.UnmakeMove(beforeMove);
int score = GetMoveScore(move);

if (score >= bestScore)
{
Expand All @@ -60,10 +55,7 @@ public MinimaxAlgorithm(QuoridorGame game)

foreach (Cell jump in jumps)
{
var beforeMove = _game.CurrentPlayer.CurrentCell;
_game.MakeMove(jump, true);
int score = Minimax(Depth, int.MinValue, int.MaxValue, false);
_game.UnmakeMove(beforeMove);
int score = GetJumpScore(jump);

if (score >= bestScore)
{
Expand All @@ -76,6 +68,35 @@ public MinimaxAlgorithm(QuoridorGame game)
return (command, step);
}

private int GetWallScore(Wall wall)
{
int score = Minimax(Depth, int.MinValue, int.MaxValue, false);

_game.UnplaceWall(wall);

return score;
}

private int GetMoveScore(Cell move)
{
var beforeMove = _game.CurrentPlayer.CurrentCell;
_game.MakeMove(move);
int score = Minimax(Depth, int.MinValue, int.MaxValue, false);
_game.UnmakeMove(beforeMove);

return score;
}

private int GetJumpScore(Cell jump)
{
var beforeMove = _game.CurrentPlayer.CurrentCell;
_game.MakeMove(jump, true);
int score = Minimax(Depth, int.MinValue, int.MaxValue, false);
_game.UnmakeMove(beforeMove);

return score;
}

private int Sev(bool maximizingPlayer)
{
(int pathLenPlayer1, int pathLenPlayer2) = GetPlayersPathes();
Expand Down

0 comments on commit f11db9a

Please sign in to comment.