Ejemplo n.º 1
0
        public override void Initialize(int gridSize, IRuleChooser ruleChooser)
        {
            if (!(ruleChooser is ElementalRuleChooser))
            {
                throw new ArgumentException("You must use the ElementalRuleChooser with this game");
            }
            base.Initialize(gridSize, ruleChooser);

            //List<string> ruleNames = new List<string> { "B3/S45678", "JustFriends", "Life", "Seeds" };
            //List<string> ruleNames = new List<string> { "B3/S45678", "Life", "JustFriends", "Seeds" };
            //List<string> ruleNames = new List<string> { "B3/S45678", "Seeds", "Life", "JustFriends" };
            //List<string> ruleNames = new List<string> { "B3/S45678", "JustFriends", "Seeds", "Life" };
            List <string> ruleNames = new List <string> {
                "JustFriends", "B3/S45678", "Life", "Seeds"
            };

            foreach (string ruleName in ruleNames)
            {
                AllRules.Add(RuleFactory.GetRuleByName(ruleName));
            }

            ICARule earth      = AllRules[0];
            ICARule air        = AllRules[1];
            ICARule water      = AllRules[2];
            ICARule fire       = AllRules[3];
            ICARule airFire    = RuleFactory.GetStrengthenRule(air, fire);
            ICARule earthWater = RuleFactory.GetStrengthenRule(earth, water);
            ICARule airEarth   = RuleFactory.GetWeakenRule(air, earth);
            ICARule fireWater  = RuleFactory.GetWeakenRule(fire, water);

            AllRules.Add(airFire);
            AllRules.Add(earthWater);
            AllRules.Add(airEarth);
            AllRules.Add(fireWater);

            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(earth, new ElementalCombo(Element.Earth));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(air, new ElementalCombo(Element.Air));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(water, new ElementalCombo(Element.Water));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(fire, new ElementalCombo(Element.Fire));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(airFire, new ElementalCombo(Element.Air, Element.Fire));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(earthWater, new ElementalCombo(Element.Earth, Element.Water));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(airEarth, new ElementalCombo(Element.Air, Element.Earth));
            ((ElementalRuleChooser)_ruleChooser).RuleElements.Add(fireWater, new ElementalCombo(Element.Fire, Element.Water));

            _ruleChooser.SetRuleRank(RuleFactory.GetRuleByName("B3/S45678"), 1);
            _ruleChooser.SetRuleRank(RuleFactory.GetRuleByName("JustFriends"), 1);
            _ruleChooser.SetRuleRank(RuleFactory.GetRuleByName("Life"), 0);
            _ruleChooser.SetRuleRank(RuleFactory.GetRuleByName("Seeds"), 3);
            _ruleChooser.SetRuleRank(airFire, 2);
            _ruleChooser.SetRuleRank(earthWater, 0);
            _ruleChooser.SetRuleRank(airEarth, 6);
            _ruleChooser.SetRuleRank(fireWater, 6);

            CAPattern pattern;
            Point     insertPoint;

            pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/JustFriendsBox50.rle");
            insertPoint = new Point(25, 25);
            InsertPattern(pattern, insertPoint);

            pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/coral.rle");
            insertPoint = new Point(5, 5);
            InsertPattern(pattern, insertPoint);

            //pattern = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/GliderGunNE.rle");
            //insertPoint = new Point(48, 31);
            //InsertPattern(pattern, insertPoint);

            pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/GliderGunNE.rle");
            insertPoint = new Point(95, 95);
            InsertPattern(pattern, insertPoint);

            pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/SeedsSmall.rle");
            insertPoint = new Point(90, 90);
            InsertPattern(pattern, insertPoint);
        }
Ejemplo n.º 2
0
        public override ICARule Choose(Random random, IHazGame game, List <Point> nPoints)
        {
            Dictionary <ICARule, int> localRules = nPoints.Select(p => game.RulePoints.TryGetValue(p, out ICARule r) ? r : RuleFactory.DefaultRule)
                                                   .GroupBy(r => r)
                                                   .ToDictionary(g => g.Key, g => g.Count());

            localRules.Remove(RuleFactory.DefaultRule);
            if (!localRules.Any())
            {
                return(game.AllRules[0]);
            }
            else if (localRules.Count == 1)
            {
                return(localRules.First().Key);
            }

            // Neutral
            int            ruleInfluenceMinRank = localRules.Min(k => _ruleInfluenceValues[RulesRankDictionary[k.Key], k.Value - 1]);
            List <ICARule> choices = localRules.Where(k => _ruleInfluenceValues[RulesRankDictionary[k.Key], k.Value - 1] == ruleInfluenceMinRank)
                                     .Select(r => r.Key)
                                     .ToList();

            if (choices.Count == 1)
            {
                return(choices[0]);
            }
            else
            {
                ICARule        air   = RuleElements.FirstOrDefault(kvp => kvp.Value.Air && kvp.Value.ElementCount == 1).Key;
                ICARule        earth = RuleElements.FirstOrDefault(kvp => kvp.Value.Earth && kvp.Value.ElementCount == 1).Key;
                ICARule        fire  = RuleElements.FirstOrDefault(kvp => kvp.Value.Fire && kvp.Value.ElementCount == 1).Key;
                ICARule        water = RuleElements.FirstOrDefault(kvp => kvp.Value.Water && kvp.Value.ElementCount == 1).Key;
                ElementalCombo ec    = new ElementalCombo(localRules.SelectMany(kvp => RuleElements[kvp.Key].Elements).ToArray());
                switch (ec.ElementCount)
                {
                case 1:
                    throw new Exception("Not possible");

                case 2:
                    if (ec.Air && ec.Fire)
                    {
                        return(RuleFactory.GetStrengthenRule(air, fire));
                    }
                    if (ec.Earth && ec.Water)
                    {
                        return(RuleFactory.GetStrengthenRule(earth, water));
                    }
                    if (ec.Air && ec.Earth)
                    {
                        return(RuleFactory.GetWeakenRule(air, earth));
                    }
                    if (ec.Fire && ec.Water)
                    {
                        return(RuleFactory.GetWeakenRule(fire, water));
                    }
                    // others are Neutral
                    break;

                case 3:
                    if (ec.Air && ec.Fire && ec.Water)
                    {
                        return(air);
                    }
                    if (ec.Earth && ec.Fire && ec.Water)
                    {
                        return(earth);
                    }
                    if (ec.Air && ec.Earth && ec.Water)
                    {
                        return(water);
                    }
                    if (ec.Air && ec.Earth && ec.Fire)
                    {
                        return(fire);
                    }
                    break;

                case 4:
                    // pick something
                    break;

                default:
                    throw new Exception("too many elements.");
                }
            }

            return(choices[random.Next(0, choices.Count - 1)]);
        }