示例#1
0
        /// <summary>
        /// Wykonujemy symulacje
        /// </summary>
        /// <returns></returns>
        private double Rollout(MctsNode node, int numberOfLastKingMovesWithoutBeat)
        {
            int           result = 0;
            CheckersBoard board  = node.Board;
            PieceColor    color  = node.Color;

            while (true)
            {
                var moves = board.GetAllPossibleMoves(color);
                if (moves.Count > 0)
                {
                    var move = moves[RandomGenerator.Next(0, moves.Count - 1)];
                    board = board.GetBoardAfterMove(move);
                    if (move.OldPiece.IsKing && (move.BeatedPieces == null || move.BeatedPieces.Count == 0))
                    {
                        numberOfLastKingMovesWithoutBeat++;
                    }
                    else
                    {
                        numberOfLastKingMovesWithoutBeat = 0;
                    }
                    if (numberOfLastKingMovesWithoutBeat > 49)
                    {
                        return(0.5);
                    }
                }
                else
                {
                    result = color == PieceColor.Black ? 1 : -1;
                    break;
                }
                color = color == PieceColor.Black ? PieceColor.White : PieceColor.Black;
            }
            return(result);
        }