Beispiel #1
0
        public void TestPlayGame(int[] playerSubmission, int[] opponentSubmission, double expectedPlayerScore, double expectedOpponentScore, int numCastles,
                                 int numTroops)
        {
            var warSimulator = new WarSimulator(numCastles, numTroops);

            (double playerScore, double opponentScore) = warSimulator.PlayGame(playerSubmission.ToList(), opponentSubmission.ToList());
            Assert.AreEqual(expectedPlayerScore, playerScore);
            Assert.AreEqual(expectedOpponentScore, opponentScore);
        }
Beispiel #2
0
        public void TestSimulation()
        {
            var submissions = new List <List <int> > {
                submission1, submission2, submission3, submission4
            };
            var warSimulator = new WarSimulator(3, 3);
            var results      = warSimulator.SimulateWars(submissions);

            Assert.AreEqual(0, results.Single(r => r.Submission.Equals(submission1)).NumWins);
            Assert.AreEqual(1, results.Single(r => r.Submission.Equals(submission2)).NumWins);
            Assert.AreEqual(2, results.Single(r => r.Submission.Equals(submission3)).NumWins);
            Assert.AreEqual(2, results.Single(r => r.Submission.Equals(submission4)).NumWins);
        }
Beispiel #3
0
    void OnTriggerEnter(Collider __collider)
    {
        WarSimulator ws = GameObject.FindWithTag("WarSimulator").GetComponent <WarSimulator>();

        if (!success)
        {
            GameObject.Instantiate(splash);
        }
        else
        {
            GameObject.Instantiate(explossion);
        }
        ws.NextPigeon();
        UnityEngine.Object.Destroy(gameObject);
    }
Beispiel #4
0
        //[TestCase(10, 100, false, 0)]
        //[TestCase(10, 100, true, 0)]
        //[TestCase(10, 100, false, 1)]
        //[TestCase(10, 100, false, 2)]
        public void GenerateTrainingDataTargetAllCastlesEvenlyStrategy(int numCastles, int numTroops, bool restrictToStrategiesTargetingMajorityOfPoints,
                                                                       int valueToAssignPerNonTargetedCastle)
        {
            var castleTargeter = new CastleTargeter();
            var strategy       = new TargetCastlesStrategy(numCastles, numTroops, castleTargeter);
            var trainingData   = strategy.GenerateTroopPlacements(
                restrictToStrategiesTargetingMajorityOfPoints,
                valueToAssignPerNonTargetedCastle,
                TroopAllocationStrategy.EvenDistribution,
                TroopAllocationStrategy.EvenDistribution
                );

            var warSimulator = new WarSimulator(numCastles, numTroops);
            var results      = warSimulator.SimulateWars(trainingData).ToArray();
            var winningStrategyInTrainingSet    = results[0];
            var secondBestStrategyInTrainingSet = results[1];
        }
Beispiel #5
0
        //// passed in parameters that would generate something similar to winner's strategy
        //[TestCase(@"C:\Users\djt74_000\Projects\riddles\Riddles\Riddles\Riddles.Tests\RiddlerNationWar\Data\submissions-1.txt",
        //	new int[] { 3, 6, 9, 13, 16, 2, 22, 25, 2, 2 })]
        //// came in first, naive version
        //[TestCase(@"C:\Users\djt74_000\Projects\riddles\Riddles\Riddles\Riddles.Tests\RiddlerNationWar\Data\submissions-1.txt",
        //	new int[] { 0, 0, 0, 0, 18, 21, 0, 29, 32, 0 })]
        //// came in second, naive version
        //[TestCase(@"C:\Users\djt74_000\Projects\riddles\Riddles\Riddles\Riddles.Tests\RiddlerNationWar\Data\submissions-1.txt",
        //	new int[] { 1, 1, 1, 1, 17, 20, 1, 27, 30, 1 })]
        //// came in third, naive version
        //[TestCase(@"C:\Users\djt74_000\Projects\riddles\Riddles\Riddles\Riddles.Tests\RiddlerNationWar\Data\submissions-1.txt",
        //	new int[] { 1, 1, 1, 1, 17, 20, 23, 1, 1, 34 })]
        public void TestAgainstTrainingData(string filename, int[] testSubmission)
        {
            List <WarSimulator.SimulationEntry> testData = new List <WarSimulator.SimulationEntry>();

            using (StreamReader sr = new StreamReader(filename))
            {
                // ignore the header line
                var submission = sr.ReadLine();
                while (sr.Peek() >= 0)
                {
                    submission = sr.ReadLine();
                    var troopDeployment = submission.Split(',');
                    troopDeployment = troopDeployment.Where((t, index) => index < 10).ToArray();
                    int n;
                    if (troopDeployment.Any(t => !int.TryParse(t, out n)))
                    {
                        continue;
                    }
                    var troopDeploymentSanitized = troopDeployment.Select(c => int.Parse(c)).ToList();
                    if (troopDeploymentSanitized.Count != 10 || troopDeploymentSanitized.Sum() != 100)
                    {
                        continue;
                    }
                    testData.Add(new WarSimulator.SimulationEntry {
                        Id = null,
                        IsTestSubmission = false,
                        TroopAllocation  = troopDeploymentSanitized
                    });
                }
            }

            var castleTargeter    = new CastleTargeter();
            var castlesToTarget   = castleTargeter.GetCastlesToTargetForPermuation(10, 223);
            var strategyGenerator = new TargetCastlesStrategy(10, 100, castleTargeter);

            testData.Add(new WarSimulator.SimulationEntry {
                Id = 1, IsTestSubmission = true, TroopAllocation = testSubmission.ToList()
            });
            var warSimulator     = new WarSimulator(10, 100);
            var results          = warSimulator.SimulateWars(testData);
            var resultsWithRank  = results.Select((r, index) => new { Id = r.Id, TroopAllocation = r.Submission, NumWins = r.NumWins, Rank = index + 1 });
            var submissionResult = resultsWithRank.Single(r => r.Id == 1);
        }
Beispiel #6
0
        public void TestValidation()
        {
            var warSimulator       = new WarSimulator(5, 1000);
            var invalidSubmission1 = new List <List <int> > {
                tooFewCastles
            };
            var invalidSubmission2 = new List <List <int> > {
                tooManyCastles
            };
            var invalidSubmission3 = new List <List <int> > {
                tooFewTroops
            };
            var invalidSubmission4 = new List <List <int> > {
                tooManyTroops
            };
            var invalidSubmission5 = new List <List <int> > {
                tooManyTroops, tooFewTroops, tooManyCastles
            };
            var invalidSubmission6 = new List <List <int> > {
                tooFewCastles, validDistribution1, validDistribution2
            };

            var validSubmission1 = new List <List <int> > {
                validDistribution3
            };
            var validSubmission2 = new List <List <int> > {
                validDistribution1, validDistribution2, validDistribution3
            };

            Assert.IsFalse(warSimulator.ValidateSubmissions(invalidSubmission1));
            Assert.IsFalse(warSimulator.ValidateSubmissions(invalidSubmission2));
            Assert.IsFalse(warSimulator.ValidateSubmissions(invalidSubmission3));
            Assert.IsFalse(warSimulator.ValidateSubmissions(invalidSubmission4));
            Assert.IsFalse(warSimulator.ValidateSubmissions(invalidSubmission5));
            Assert.IsFalse(warSimulator.ValidateSubmissions(invalidSubmission6));

            Assert.IsTrue(warSimulator.ValidateSubmissions(validSubmission1));
            Assert.IsTrue(warSimulator.ValidateSubmissions(validSubmission2));
        }
Beispiel #7
0
        //[TestCase(10, 100)]
        public void GenerateDataSetForOptimization(int numCastles, int numTroops)
        {
            var castleTargeter    = new CastleTargeter();
            var strategyGenerator = new TargetCastlesStrategy(numCastles, numTroops, castleTargeter);
            var strategy1         = strategyGenerator.GenerateTroopPlacements(false, 0, TroopAllocationStrategy.EvenDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy2         = strategyGenerator.GenerateTroopPlacements(false, 1, TroopAllocationStrategy.EvenDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy3         = strategyGenerator.GenerateTroopPlacements(false, 2, TroopAllocationStrategy.EvenDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy4         = strategyGenerator.GenerateTroopPlacements(true, 0, TroopAllocationStrategy.EvenDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy5         = strategyGenerator.GenerateTroopPlacements(true, 1, TroopAllocationStrategy.EvenDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy6         = strategyGenerator.GenerateTroopPlacements(true, 2, TroopAllocationStrategy.EvenDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy7         = strategyGenerator.GenerateTroopPlacements(false, 0, TroopAllocationStrategy.ProportionalDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy8         = strategyGenerator.GenerateTroopPlacements(false, 1, TroopAllocationStrategy.ProportionalDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy9         = strategyGenerator.GenerateTroopPlacements(false, 2, TroopAllocationStrategy.ProportionalDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy10        = strategyGenerator.GenerateTroopPlacements(true, 0, TroopAllocationStrategy.ProportionalDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy11        = strategyGenerator.GenerateTroopPlacements(true, 1, TroopAllocationStrategy.ProportionalDistribution, TroopAllocationStrategy.EvenDistribution);
            var strategy12        = strategyGenerator.GenerateTroopPlacements(true, 2, TroopAllocationStrategy.ProportionalDistribution, TroopAllocationStrategy.EvenDistribution);

            var trainingData = new List <List <int> >();

            trainingData.AddRange(strategy1);
            trainingData.AddRange(strategy2);
            trainingData.AddRange(strategy3);
            trainingData.AddRange(strategy4);
            trainingData.AddRange(strategy5);
            trainingData.AddRange(strategy6);
            trainingData.AddRange(strategy7);
            trainingData.AddRange(strategy8);
            trainingData.AddRange(strategy9);
            trainingData.AddRange(strategy10);
            trainingData.AddRange(strategy11);
            trainingData.AddRange(strategy12);
            trainingData = trainingData.ToList();

            var warSimulator = new WarSimulator(numCastles, numTroops);
            var results      = warSimulator.SimulateWars(trainingData);
        }