Exemplo n.º 1
0
        //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);
        }
Exemplo n.º 2
0
 /// <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);
 }