private double maxValue(CheckersModel gameClone, int depth) { var moves = shuffle(gameClone.GetPossibleMoves(Colour)); if (moves.Count == 0) { return(double.MinValue); } if (depth == 0) { return(gameClone.CountPiecesOfColour(Colour) - gameClone.CountPiecesOfColour(Colour.MyEnemy())); } var maxFound = double.MinValue; foreach (var move in moves) { CheckersModel clone = gameClone.Clone(); if (!clone.TryMakeMove(Colour, move)) { Console.WriteLine("YOU ALSO F****D UP"); } maxFound = Math.Max(maxFound, minValue(clone, depth - 1)); } return(maxFound); }
private void CheckForGameCompletion() { if (model.GetPossibleMoves(currentPlayer.Colour).Count == 0) { //Toggle the player so that it is the winners turn. currentPlayer = player1 == currentPlayer ? player2 : player1; UIUpdateActionOnWinningMove(); } }
private Move miniMax(CheckersModel gameModel, int depth = 5) { var bestScore = double.MinValue; var bestMove = Move.Empty; foreach (var move in shuffle(gameModel.GetPossibleMoves(Colour))) { CheckersModel clone = gameModel.Clone(); clone.TryMakeMove(Colour, move); var score = minValue(clone, depth - 1); if (score >= bestScore) { bestMove = move; bestScore = score; } } return(bestMove); }