示例#1
0
        public void AssignMovesPaired()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1
                },                                       // should always be picked first
                new PokemonMoveSetResult {
                    MoveId = 2
                },
                new PokemonMoveSetResult {
                    MoveId = 3
                },
                new PokemonMoveSetResult {
                    MoveId = 4
                },
                new PokemonMoveSetResult {
                    MoveId = 5
                },
                new PokemonMoveSetResult {
                    MoveId = 6
                }
            };

            _config.Value.Configuration.PairedMoves = new Dictionary <int, int[]>
            {
                [1] = new [] { 2, 3 },
                [2] = new [] { 5 }
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>(0));
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var pairedKeys    = _config.Value.Configuration.PairedMoves.Keys.ToList();
            var expectedMoves = pairedKeys.Union(pairedKeys.SelectMany(key => _config.Value.Configuration.PairedMoves[key])).ToList();

            Assert.Contains(poke.MoveIndex1, expectedMoves);
            Assert.Contains(poke.MoveIndex2, expectedMoves);
            Assert.Contains(poke.MoveIndex3, expectedMoves);
            Assert.Contains(poke.MoveIndex4, expectedMoves);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#2
0
        public void AssignMovesRemovesFromTmBank()
        {
            // Set up
            var poke   = new Pokemon();
            var tmBank = new List <int> {
                3, 2, 4
            };
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, LearnType = "machine"
                },
                new PokemonMoveSetResult {
                    MoveId = 2, LearnType = "machine"
                },
                new PokemonMoveSetResult {
                    MoveId = 3, LearnType = "machine"
                },
                new PokemonMoveSetResult {
                    MoveId = 4, LearnType = "machine"
                },
                new PokemonMoveSetResult {
                    MoveId = 5, LearnType = "machine"
                },
                new PokemonMoveSetResult {
                    MoveId = 6
                },
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(tmBank);
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var expected = tmBank.Union(movesForPokemon.Where(move => move.LearnType == null).Select(move => move.MoveId)).ToList();

            Assert.Equal(4, expected.Count); // sanity
            Assert.Contains(poke.MoveIndex1, expected);
            Assert.Contains(poke.MoveIndex2, expected);
            Assert.Contains(poke.MoveIndex3, expected);
            Assert.Contains(poke.MoveIndex4, expected);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#3
0
        public void AssignMovesWeighsSimilarEffects()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, Effect = "test1"
                },                                                        // should always be picked first
                new PokemonMoveSetResult {
                    MoveId = 2, Effect = "test1"
                },
                new PokemonMoveSetResult {
                    MoveId = 3, Effect = "test1"
                },
                new PokemonMoveSetResult {
                    MoveId = 4, Effect = "test2"
                },
                new PokemonMoveSetResult {
                    MoveId = 5, Effect = "test3"
                },
                new PokemonMoveSetResult {
                    MoveId = 6, Effect = "test4"
                }
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>(0));
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var expectedMoves = new List <int> {
                1, 4, 5, 6
            };                                                // too complicated to use logic here

            Assert.Contains(poke.MoveIndex1, expectedMoves);
            Assert.Contains(poke.MoveIndex2, expectedMoves);
            Assert.Contains(poke.MoveIndex3, expectedMoves);
            Assert.Contains(poke.MoveIndex4, expectedMoves);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#4
0
        public void AssignMovesWeighsDamage()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, Power = 100
                },                                                    // this is epected
                new PokemonMoveSetResult {
                    MoveId = 2, Power = 80
                },
                new PokemonMoveSetResult {
                    MoveId = 3, Power = 90
                },                                                    // this is epected
                new PokemonMoveSetResult {
                    MoveId = 4, Power = 70
                },
                new PokemonMoveSetResult {
                    MoveId = 5, Power = 0
                },                                                    // this will be chosen bc of damage flag toggling
                new PokemonMoveSetResult {
                    MoveId = 6, Power = 0
                }                                                     // this will be chosen bc of damage flag toggling
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>(0));
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var highestDamagingMoves = movesForPokemon.OrderByDescending(move => move.Power).Take(2).ToList();
            var nonDamagingMoves     = movesForPokemon.OrderBy(move => move.Power).Take(2).ToList();
            var expectedMoves        = highestDamagingMoves.Union(nonDamagingMoves).Select(move => move.MoveId).ToList();

            Assert.Contains(poke.MoveIndex1, expectedMoves);
            Assert.Contains(poke.MoveIndex2, expectedMoves);
            Assert.Contains(poke.MoveIndex3, expectedMoves);
            Assert.Contains(poke.MoveIndex4, expectedMoves);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#5
0
        public void AssignMovesBalancesDamageFlag()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, Power = 0
                },
                new PokemonMoveSetResult {
                    MoveId = 2, Power = 90
                },
                new PokemonMoveSetResult {
                    MoveId = 3, Power = 130
                },
                new PokemonMoveSetResult {
                    MoveId = 4, Power = 25
                },
                new PokemonMoveSetResult {
                    MoveId = 5, Power = 0
                },
                new PokemonMoveSetResult {
                    MoveId = 6, Power = 0
                },
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>(0));
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var moves = new List <int> {
                poke.MoveIndex1, poke.MoveIndex2, poke.MoveIndex3, poke.MoveIndex4,
            };
            var powers = moves.Join(movesForPokemon, moveId => moveId, move => move.MoveId, (moveId, move) => move.Power).ToList();

            Assert.Equal(2, powers.Count(power => power > 0));
            Assert.Equal(2, powers.Count(power => power == 0));

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#6
0
        public void AssignMovesForSketch()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 166
                },                                         // Sketch
            };
            var randoMoves = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 67
                },
                new PokemonMoveSetResult {
                    MoveId = 99
                },
                new PokemonMoveSetResult {
                    MoveId = 32
                },
                new PokemonMoveSetResult {
                    MoveId = 44
                }
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>());
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetRandomMoves(_config.Value.Configuration.RandomMoveMinPower, _config.Value.Configuration.RandomMoveMaxPower)).Returns(randoMoves);
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            Assert.Contains(poke.MoveIndex1, randoMoves.Select(move => move.MoveId));
            Assert.Contains(poke.MoveIndex2, randoMoves.Select(move => move.MoveId));
            Assert.Contains(poke.MoveIndex3, randoMoves.Select(move => move.MoveId));
            Assert.Contains(poke.MoveIndex4, randoMoves.Select(move => move.MoveId));

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#7
0
        public void AssignMovesForSpecialPokemon()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 67
                },
                new PokemonMoveSetResult {
                    MoveId = 99
                },
                new PokemonMoveSetResult {
                    MoveId = 32
                },
                new PokemonMoveSetResult {
                    MoveId = 44
                }
            };

            _config.Value.Configuration.SpecialPokemon.Add(poke.SpeciesId);

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>());
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var expected = movesForPokemon.Take(4).Select(t => t.MoveId).ToList();

            Assert.Contains(poke.MoveIndex1, expected);
            Assert.Contains(poke.MoveIndex2, expected);
            Assert.Contains(poke.MoveIndex3, expected);
            Assert.Contains(poke.MoveIndex4, expected);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#8
0
        public void AssignMovesDamageType(ushort spAttack, ushort attack, int delta)
        {
            // Set up
            _config.Value.Configuration.DamageTypeDelta = delta;

            var poke = new Pokemon
            {
                SpAttack = spAttack,
                Attack   = attack
            };
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, DamageType = "physical"
                },
                new PokemonMoveSetResult {
                    MoveId = 2, DamageType = "physical"
                },
                new PokemonMoveSetResult {
                    MoveId = 3, DamageType = "special"
                },
                new PokemonMoveSetResult {
                    MoveId = 4, DamageType = "special"
                },
                new PokemonMoveSetResult {
                    MoveId = 5, DamageType = "physical"
                },
                new PokemonMoveSetResult {
                    MoveId = 6, DamageType = "physical"
                },
                new PokemonMoveSetResult {
                    MoveId = 7, DamageType = "special"
                },
                new PokemonMoveSetResult {
                    MoveId = 8, DamageType = "special"
                },
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>());
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var type      = Math.Abs(spAttack - attack) < delta ? DamageType.Both : spAttack > attack ? DamageType.Special : DamageType.Physical;
            var expecteds = movesForPokemon
                            .Where(move => type == DamageType.Both ||
                                   (type == DamageType.Physical && move.DamageType.Equals("physical")) ||
                                   (type == DamageType.Special && move.DamageType.Equals("special")))
                            .Select(move => move.MoveId)
                            .ToList();

            Assert.Contains(poke.MoveIndex1, expecteds);
            Assert.Contains(poke.MoveIndex2, expecteds);
            Assert.Contains(poke.MoveIndex3, expecteds);
            Assert.Contains(poke.MoveIndex4, expecteds);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#9
0
        public void AssignMovesWeighsEffectFilters()
        {
            // Set up
            var poke            = new Pokemon();
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, Effect = "test1"
                },
                new PokemonMoveSetResult {
                    MoveId = 2, Effect = "test2"
                },
                new PokemonMoveSetResult {
                    MoveId = 3, Effect = "test3"
                },
                new PokemonMoveSetResult {
                    MoveId = 4, Effect = "test4"
                },
                new PokemonMoveSetResult {
                    MoveId = 5, Effect = "test5"
                },
                new PokemonMoveSetResult {
                    MoveId = 6, Effect = "test1"
                },
            };

            _config.Value.Configuration.MoveEffectFilters = new Dictionary <string, double>
            {
                ["test1"] = 1,
                ["test2"] = 0.2,
                ["test3"] = .1,
                ["test4"] = 0,
                ["test5"] = 0.5,
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>(0));
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(new List <string>());
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var expectedEffects = _config.Value.Configuration.MoveEffectFilters.OrderByDescending(pair => pair.Value).Take(4).Select(pair => pair.Key).ToList();
            var expectedMoves   = movesForPokemon.Join(expectedEffects, move => move.Effect, effect => effect, (move, effect) => move.MoveId).ToList();

            Assert.Contains(poke.MoveIndex1, expectedMoves);
            Assert.Contains(poke.MoveIndex2, expectedMoves);
            Assert.Contains(poke.MoveIndex3, expectedMoves);
            Assert.Contains(poke.MoveIndex4, expectedMoves);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }
示例#10
0
        public void AssignMovesWeighsTypes()
        {
            // Set up
            var poke = new Pokemon
            {
                Types = new List <string> {
                    "test2", "test5"
                }
            };
            var attackTypesToFavor = new List <string> {
                "test1"
            };
            var movesForPokemon = new List <PokemonMoveSetResult>
            {
                new PokemonMoveSetResult {
                    MoveId = 1, Type = "test1"
                },
                new PokemonMoveSetResult {
                    MoveId = 2, Type = "test2"
                },
                new PokemonMoveSetResult {
                    MoveId = 3, Type = "test3"
                },
                new PokemonMoveSetResult {
                    MoveId = 4, Type = "test4"
                },
                new PokemonMoveSetResult {
                    MoveId = 5, Type = "test5"
                },
                new PokemonMoveSetResult {
                    MoveId = 6, Type = "test1"
                },
            };

            // Mock
            _mockPokemonRepository.Setup(r => r.GetTMs()).Returns(new List <int>(0));
            _mockPokemonRepository.Setup(r => r.GetMovesForPokemon(poke.SpeciesId, _level)).Returns(movesForPokemon);
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Join(",", poke.Types))).Returns(new List <string>());
            _mockPokemonRepository.Setup(r => r.GetWeaknesses(string.Empty)).Returns(attackTypesToFavor);
            _mockProbabilityUtility.Setup(m => m.ChooseWithProbability(It.IsAny <IList <IChoice> >())).Returns((IList <IChoice> choices) =>
                                                                                                               choices.Select((choice, index) => new { choice, index })
                                                                                                               .OrderByDescending(item => item.choice.Probability)
                                                                                                               .First().index);

            // Run
            var target = new PokemonMoveProvider(_mockPokemonRepository.Object, _mockProbabilityUtility.Object, _config, _random);

            poke = target.AssignMoves(poke, _level);

            // Assert
            var expectedTypes = poke.Types.Union(attackTypesToFavor).ToList();
            var expectedMoves = movesForPokemon.Join(expectedTypes, move => move.Type, type => type, (move, type) => move.MoveId).ToList();

            Assert.Contains(poke.MoveIndex1, expectedMoves);
            Assert.Contains(poke.MoveIndex2, expectedMoves);
            Assert.Contains(poke.MoveIndex3, expectedMoves);
            Assert.Contains(poke.MoveIndex4, expectedMoves);

            // Verify
            _mockPokemonRepository.VerifyAll();
            _mockProbabilityUtility.VerifyAll();
        }