//TODO: private int MiniMax(ref Move bestMove, IBoard board, Player player, int ply, int depth, TimeSpan timeout, DateTime startTime) { if (depth <= 0) { // reached ply level // достиг уровня слоя return(Evaluate(board, player)); } else if (forceMove) { return(int.MinValue); } ICollection <Move> moves = CheckerMoveRules.GetAvailableMoves(board, player); if ((moves == null) || (moves.Count == 0)) { // reached leaf // достиг листа return(Evaluate(board, player)); } int bestScore = int.MinValue; Player opponent = BoardUtilities.GetOpponent(player); IBoard boardCopy = board.Copy(); foreach (Move move in moves) { CheckerMoveRules.UpdateBoard(boardCopy, move); int score = -MiniMax(ref bestMove, boardCopy, opponent, ply, depth - 1, timeout, startTime); boardCopy.Copy(board);// undo move //отменить движение if (depth == ply) { System.Diagnostics.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Move: {0}. Score: {1}", move, score.ToString(CultureInfo.InvariantCulture))); if ((bestMove == null) || (score > bestScore)) { bestMove = move; } } bestScore = Math.Max(bestScore, score); } return(bestScore); }
/// <summary> /// Attempt to resolve ambiguous jump move. The longest move matching the first /// location and last location is selected. /// </summary> /// <param name="board">The board</param> /// <param name="move">The possibly ambiguos move</param> /// <returns><c>true</c> if move could be resolved</returns> public Move ResolveAmbiguousMove(IBoard board, Move move) { return(CheckerMoveRules.ResolveAmbiguousMove(board, move)); }
/// <summary> /// Is the game over /// </summary> /// <param name="board">The board state</param> /// <param name="turn">The player with the current turn</param> /// <returns><c>true</c> if the game is over and <c>false</c> false if otherwise</returns> public bool IsGameOver(IBoard board, Player turn) { return(!CheckerMoveRules.HasMovesAvailable(board, turn)); }
/// <summary> /// Apply the given move to the board /// </summary> /// <param name="board">The board state</param> /// <param name="move">The move to apply to the board</param> /// <returns><c>true</c> if the move was applied successfully</returns> public bool ApplyMove(IBoard board, Move move) { CheckerMoveRules.UpdateBoard(board, move); return(true); }
/// <summary> /// Check if the given move is valid for the given state /// </summary> /// <param name="board">The board state</param> /// <param name="move">The move</param> /// <param name="player">The player that made the move</param> /// <returns>The status of the move</returns> public MoveStatus IsValidMove(IBoard board, Move move, Player player) { return(CheckerMoveRules.IsMoveLegal(board, move, player)); }