Beispiel #1
0
        public static void Main(string[] args)
        {
            List <string> linesOfText = null;

            try
            {
                linesOfText = File.ReadAllLines(args[0]).ToList();
            }
            catch (Exception)
            {
                Console.WriteLine("Please pass a URL to a text file with containing test cases. Commas between the coordinates and spaces between the positions");

                /* The requirements on this were a bit vague, I'm expecting an input like this
                 * 2
                 * 3 0,0,0 50,50,50 1000,1000,1000
                 * 1 500,500,500
                 */
            }

            //var testCases = ExtractTestCasesFromText(linesOfText);
            var testCases = SimulateSomeRandomBombs();

            foreach (var tc in testCases)
            {
                var calculator = new RandomCalculator(tc.Bombs, 10000);           //Raise or lower the iterations depending on how until the bombs go off
                //var calculator = new BruteForceCalculator(bombPositions);       //Only works well in dimensions of 300 or less
                calculator.CalculateSafestPlaceToHide();

                //Console.WriteLine(
                //    $"Safest Position {calculator.SafestPosition[0]},{calculator.SafestPosition[1]},{calculator.SafestPosition[2]} " +
                //    $"- Distance {calculator.SafestDistance}");
                Console.WriteLine(calculator.SafestDistanceAsInt);
            }
            Console.ReadLine();
        }
Beispiel #2
0
    private bool teamScores()
    {
        //Si estoy en posición de tiro al arco y meto gol
        if (currentPosition >= 85 && currentBallHolder == myClub && RandomCalculator.evaluateChances(myClubScoreChance() / scoringChanceDividerConstant))
        {
            myClubScore++;

            MatchController.updateMatchScore(myClubScore.ToString() + "-" + enemyClubScore.ToString(), currentBallHolder.getName());
            currentBallHolder = enemyClub;
            currentPosition   = 50;
            return(true);
        }

        //Si el equipo contrario está en posición de tiro al arco y mete gol

        if (currentPosition <= 15 && currentBallHolder == enemyClub && RandomCalculator.evaluateChances(myClubStopChance() / scoringChanceDividerConstant))
        {
            enemyClubScore++;

            MatchController.updateMatchScore(myClubScore.ToString() + "-" + enemyClubScore.ToString(), currentBallHolder.getName());
            currentBallHolder = myClub;
            currentPosition   = 50;
            return(true);
        }
        return(false);
    }
Beispiel #3
0
        public void InvokeCalculator()
        {
            var calculator = new RandomCalculator(new ICalculatorFuncion[]
            {
                new SquareCalculator(),
                new SquareRootCalculator()
            });

            //Should we record or stat anything here?
            var result = calculator.Calculate();
        }
Beispiel #4
0
        private StellarSystem GenerateMultiStarSystem(StellarSystem parent, int position)
        {
            var countStars = RandomCalculator.SelectByWeight(_multiStarCountOccurrences);

            var system = new MultiObjectSystem(parent);

            for (var i = 0; i < countStars; i++)
            {
                var starSystem = GenerateSingleStarSystem(system, position);

                system.CenterSystems.Add(starSystem);
            }

            return(system);
        }
Beispiel #5
0
        private List <StellarSystem> GenerateCenter(StellarSystem parent, int position)
        {
            var center = new List <StellarSystem>();

            var starsToCreate = RandomCalculator.SelectByWeight(_starOccurrences);

            for (var i = 0; i < starsToCreate; i++)
            {
                var isMultiSystem = RandomCalculator.SelectByWeight(_multiStarOccurrences);

                var system = GenerateCenter(parent, position, isMultiSystem);
                center.Add(system);
            }

            return(center);
        }
Beispiel #6
0
        private List <StellarSystem> GenerateSatellites(StellarSystem parent, int position)
        {
            var satelliteSystems = new List <StellarSystem>();

            var countSatellites = RandomCalculator.SelectByWeight(_satelliteOccurrences);

            for (var i = position; i <= countSatellites; i++)
            {
                var multiSatelliteCount = RandomCalculator.SelectByWeight(_multiSatelliteCountOccurrences);

                var satelliteSystem = GenerateSatelliteSystem(parent, position, multiSatelliteCount);

                satelliteSystems.Add(satelliteSystem);
            }

            return(satelliteSystems);
        }
Beispiel #7
0
    private void calculateGoalKeeper(int chancesToEvaluate)
    {
        previousBallHolder = currentBallHolder;

        if (RandomCalculator.evaluateChances(chancesToEvaluate))
        {
            currentBallHolder = myClub;
            currentPosition   = Math.Min(95, currentPosition + 10);
            calculateNewPlayer();
        }
        else
        {
            currentBallHolder = enemyClub;
            currentPosition   = Math.Max(5, currentPosition - 10);
            calculateNewPlayer();
        }

        if ((System.Object)previousBallHolder == null)
        {
            previousBallHolder = currentBallHolder;
        }
    }
Beispiel #8
0
        public List <List <int> > GetWinner(int attackingTerritoryId, int defencingTerritoryId)
        {
            var tmpList   = myRootW.GetRoot();
            int attackers = tmpList.features[attackingTerritoryId - 1].properties.troops - 1;
            int defencors = tmpList.features[defencingTerritoryId - 1].properties.troops;
            var result    = new RandomCalculator().calculateWinner(attackers, defencors);

            if (result[0].Count != 0)
            {
                tmpList.features[defencingTerritoryId - 1].properties.playerId = tmpList.features[attackingTerritoryId - 1].properties.playerId;
                tmpList.features[defencingTerritoryId - 1].properties.troops   = result[0].Count;
                tmpList.features[attackingTerritoryId - 1].properties.troops   = 1;
            }
            else
            {
                tmpList.features[defencingTerritoryId - 1].properties.troops = result[1].Count;
                tmpList.features[attackingTerritoryId - 1].properties.troops = 1;
            }

            //new Filer().SaveFiler(tmpList);
            return(result);
        }