public TransportType ChooseNextTransportType(
            HashSet <Passenger> neighbors,
            TransportType currentTransportType,
            double currentSatisfaction,
            double deviationValue,
            TransportType[] availableTransportTypes)
        {
            var typeTransportInfos = neighbors
                                     .GroupBy(x => x.TransportType)
                                     .Select(GetTransportInfo);

            foreach (var info in typeTransportInfos)
            {
                if (info.Item2 > currentSatisfaction)
                {
                    currentTransportType = info.Item1;
                    currentSatisfaction  = info.Item2;
                }
            }

            if (currentTransportType == TransportType.Car)
            {
                currentTransportType = randomizer.GetRandomDouble() < carAvailabilityProbability
                    ? TransportType.Car
                    : TransportTypes.GetRandomTransportWithoutType(TransportType.Car, randomizer, availableTransportTypes);
            }

            return(currentTransportType);
        }
Exemple #2
0
        public void ProcessMap(Map <T> map, DungeonConfiguration configuration, IRandomizer randomizer)
        {
            var deadends = map.AllCells.Where(cell => cell.Sides.Values.Count(type => type) == 1).ToList();

            foreach (var cell in deadends)
            {
                if (randomizer.GetRandomDouble() > configuration.ChanceToRemoveDeadends)
                {
                    continue;
                }

                var currentCell  = cell;
                var previousCell = map.GetAdjacentCell(cell, cell.Sides.First(pair => pair.Value).Key);
                var connected    = false;
                while (!connected)
                {
                    var direction = GetRandomValidDirection(map, currentCell, previousCell, randomizer);
                    if (!direction.HasValue)
                    {
                        break;
                    }

                    var adjacentCell = map.GetAdjacentCell(currentCell, direction.Value);
                    connected           = adjacentCell.IsOpen;
                    adjacentCell.IsOpen = true;
                    currentCell.Sides[direction.Value] = adjacentCell.Sides[direction.Value.Opposite()] = true;
                    previousCell = currentCell;
                    currentCell  = adjacentCell;
                }
            }
        }
        public static TransportType GetBestNextTransportWithEpsilonMush(QFuncInfo qFuncInfo, TransportType[] availableTransportTypes)
        {
            var bestTransportType = qFuncInfo.GetBestTransportType();

            return(randomizer.GetRandomDouble() > Epsilon
                ? bestTransportType
                : TransportTypes.GetRandomTransportWithoutType(bestTransportType, randomizer, availableTransportTypes));
        }
Exemple #4
0
        public PassengerDto[] CreatePassengers(int columns, int rows)
        {
            var passengers = new List <PassengerDto>();
            var count      = rows * columns;

            for (var i = 0; i < count; i++)
            {
                var passenger = new PassengerDto
                {
                    Id              = $"{i + 1}",
                    Satisfaction    = Math.Round(randomizer.GetRandomDouble(), 2),
                    Quality         = Math.Round(randomizer.GetRandomDouble(), 2),
                    TransportType   = TransportTypes.GetRandomTransportTypeBetweenCarAndBus(randomizer),
                    FirstBusQuality = 0.5
                };
                passengers.Add(passenger);
            }

            return(passengers.ToArray());
        }
Exemple #5
0
        public void Test_GetRandomDouble()
        {
            System.Console.Out.WriteLine("GetRandomDouble");
            double      min        = -20.5234F;
            double      max        = 100.12124F;
            IRandomizer randomizer = Esapi.Randomizer;
            double      minResult  = (max - min) / 2;
            double      maxResult  = (max - min) / 2;

            for (int i = 0; i < 100; i++)
            {
                double result = randomizer.GetRandomDouble(min, max);
                if (result < minResult)
                {
                    minResult = result;
                }
                if (result > maxResult)
                {
                    maxResult = result;
                }
            }
            Assert.AreEqual(true, (minResult >= min && maxResult < max));
        }
Exemple #6
0
        private Direction?GetRandomValidDirection(Map <T> map, T cell, ICollection <T> visitedCells, double randomness, Direction?previousDirection, IRandomizer randomizer)
        {
            //Randomness determines how often the direction of a corridor changes
            if (previousDirection.HasValue &&
                randomness < 1 &&
                randomizer.GetRandomDouble() > randomness &&
                IsDirectionValid(map, cell, previousDirection.Value, visitedCells))
            {
                return(previousDirection);
            }

            var invalidDirections = new List <Direction>();

            while (invalidDirections.Count < GetAll.ValuesOf <Direction>().Count())
            {
                var direction = randomizer.GetRandomEnumValue(invalidDirections);
                if (IsDirectionValid(map, cell, direction, visitedCells))
                {
                    return(direction);
                }
                invalidDirections.Add(direction);
            }
            return(null);
        }