Example #1
0
        public void UnmortgageProperties_ByPreference()
        {
            var geneticCode = new GeneticCode();

            _player = new Player(geneticCode);

            geneticCode.SetGeneExpression(GeneType.PropertyValue, _assetManager.FleetStreet, 0.1f);
            geneticCode.SetGeneExpression(GeneType.PropertyValue, _assetManager.TrafalgarSquare, 0.2f);
            geneticCode.SetGeneExpression(GeneType.PropertyValue, _assetManager.TheStrand, 0.3f);

            _player.PurchaseAsset(_assetManager.FleetStreet);
            _player.PurchaseAsset(_assetManager.TheStrand);
            _player.PurchaseAsset(_assetManager.TrafalgarSquare);

            // mortgage the properties
            _player.SetCashTotal(0);
            _player.Pay(250, _bank, _bank);

            // enough to unmortgage one
            _player.SetCashTotal(160);

            _player.ConsiderUnmortgaging();

            Assert.IsFalse(_assetManager.TheStrand.Mortgaged);
            Assert.IsTrue(_assetManager.FleetStreet.Mortgaged);
            Assert.IsTrue(_assetManager.TrafalgarSquare.Mortgaged);
        }
Example #2
0
        public void SellsBuildings_ByPreference()
        {
            var geneticCode = new GeneticCode();

            _player = new Player(geneticCode);

            geneticCode.SetGeneExpression(GeneType.ImprovementValue, _assetManager.FleetStreet, 0.1f);
            geneticCode.SetGeneExpression(GeneType.ImprovementValue, _assetManager.TrafalgarSquare, 0.2f);
            geneticCode.SetGeneExpression(GeneType.ImprovementValue, _assetManager.TheStrand, 0.3f);

            _player.SetCashTotal(5000);

            _player.PurchaseAsset(_assetManager.FleetStreet);
            _player.PurchaseAsset(_assetManager.TheStrand);
            _player.PurchaseAsset(_assetManager.TrafalgarSquare);

            _player.PurchaseBuilding(_assetManager.FleetStreet);
            _player.PurchaseBuilding(_assetManager.TheStrand);
            _player.PurchaseBuilding(_assetManager.TrafalgarSquare);
            _player.PurchaseBuilding(_assetManager.FleetStreet);
            _player.PurchaseBuilding(_assetManager.TheStrand);
            _player.PurchaseBuilding(_assetManager.TrafalgarSquare);

            // need to sell all but one house

            _player.SetCashTotal(0);
            _player.Pay(75 * 5, _bank, _bank);

            Assert.AreEqual(1, _assetManager.TheStrand.BuildingCount);
            Assert.AreEqual(0, _assetManager.FleetStreet.BuildingCount);
            Assert.AreEqual(0, _assetManager.TrafalgarSquare.BuildingCount);
        }
Example #3
0
        public GeneticCode Cross(GeneticCode partner, double mutatationRate = 0.5d)
        {
            var offspringGenes = new GeneticCode(Math.Max(this.Generation, partner.Generation) + 1);

            foreach (var genotype in this.Genes.Keys)
            {
                if (partner.Genes.ContainsKey(genotype))
                {
                    if (CrossingProcess == CrossProcess.Average)
                    {
                        offspringGenes.Genes[genotype] = (this.Genes[genotype] + partner.Genes[genotype]) / 2f;
                    }
                    else
                    {
                        var rnd = Utils.GetRandomNumber(0, 2);
                        offspringGenes.Genes[genotype] = rnd == 0 ? this.Genes[genotype] : partner.Genes[genotype];
                    }
                }
                else
                {
                    offspringGenes.Genes[genotype] = this.Genes[genotype];
                }
            }

            foreach (var genotype in partner.Genes.Keys)
            {
                if (this.Genes.ContainsKey(genotype))
                {
                    if (offspringGenes.Genes.Keys.DoesNotContain(genotype))
                    {
                        if (CrossingProcess == CrossProcess.Average)
                        {
                            offspringGenes.Genes[genotype] = (this.Genes[genotype] + partner.Genes[genotype]) / 2f;
                        }
                        else
                        {
                            var rnd = Utils.GetRandomNumber(0, 2);
                            offspringGenes.Genes[genotype] = rnd == 0 ? this.Genes[genotype] : partner.Genes[genotype];
                        }
                    }
                }
                else
                {
                    offspringGenes.Genes[genotype] = partner.Genes[genotype];
                }
            }

            if (offspringGenes.Genes.Count > 0 && (Utils.GetRandomDouble() > mutatationRate))
            {
                var rnd  = Utils.GetRandomNumber(0, offspringGenes.Genes.Count);
                var list = new List <GeneIdentifier>(offspringGenes.Genes.Keys);
                offspringGenes.Genes[list[rnd]] = Utils.GetRandomDouble();
            }

            return(offspringGenes);
        }
Example #4
0
 public Player(GeneticCode genetics)
 {
     Assets   = new List <Asset>();
     Genetics = genetics;
     GetOutOfJailFreeCards = new Queue <Card>();
     TurnsInJail           = 0;
     Money          = (2 * 500) + (2 * 100) + (2 * 50) + (6 * 20) + (5 * 10) + (5 * 5) + (5 * 1);
     Status         = PlayerStatus.Normal;
     LastTurnEvents = new List <string>();
     ID             = Guid.NewGuid();
 }
Example #5
0
        public void ConsiderPurchase_ByPreference()
        {
            var geneticCode = new GeneticCode();

            _player = new Player(geneticCode);

            geneticCode.SetGeneExpression(GeneType.PropertyValue, _assetManager.FleetStreet, 0.2f);
            geneticCode.SetGeneExpression(GeneType.PropertyValue, _assetManager.TrafalgarSquare, 0.2f);
            geneticCode.SetGeneExpression(GeneType.PropertyValue, _assetManager.TheStrand, 0.9f);

            _player.SetCashTotal(300);
            _player.ConsiderPurchase(_assetManager.TrafalgarSquare);
            _player.SetCashTotal(300);
            _player.ConsiderPurchase(_assetManager.FleetStreet);
            _player.SetCashTotal(300);
            _player.ConsiderPurchase(_assetManager.TheStrand);

            Assert.AreEqual(_player, _assetManager.TheStrand.Owner);
            Assert.AreEqual(_bank, _assetManager.FleetStreet.Owner);
            Assert.AreEqual(_bank, _assetManager.TrafalgarSquare.Owner);
        }
Example #6
0
        public void ConsiderBuilding_ByPreference()
        {
            var geneticCode = new GeneticCode();

            _player = new Player(geneticCode);

            geneticCode.SetGeneExpression(GeneType.ImprovementValue, _assetManager.FleetStreet, 0.1f);
            geneticCode.SetGeneExpression(GeneType.ImprovementValue, _assetManager.TrafalgarSquare, 0.2f);
            geneticCode.SetGeneExpression(GeneType.ImprovementValue, _assetManager.TheStrand, 0.3f);

            _player.PurchaseAsset(_assetManager.FleetStreet);
            _player.PurchaseAsset(_assetManager.TheStrand);
            _player.PurchaseAsset(_assetManager.TrafalgarSquare);

            // enough for 1 house
            _player.SetCashTotal(200);

            _player.ConsiderBuilding();

            Assert.AreEqual(1, _assetManager.TheStrand.BuildingCount);
            Assert.AreEqual(0, _assetManager.FleetStreet.BuildingCount);
            Assert.AreEqual(0, _assetManager.TrafalgarSquare.BuildingCount);
        }
Example #7
0
        public void Cross_SwapsGenes()
        {
            var geneticCode1 = new GeneticCode(10);
            var geneticCode2 = new GeneticCode(14);

            geneticCode1.SetGeneExpression(GeneType.Mortgage, AssetReference.BondStreet, 0.2f);
            geneticCode2.SetGeneExpression(GeneType.Mortgage, AssetReference.RegentStreet, 0.8f);
            geneticCode1.SetGeneExpression(GeneType.Mortgage, AssetReference.OldKentRoad, 0.7f);
            geneticCode2.SetGeneExpression(GeneType.Mortgage, AssetReference.OldKentRoad, 0.3f);
            geneticCode1.SetGeneExpression(GeneType.Mortgage, AssetReference.Whitehall, 0.1f);
            geneticCode2.SetGeneExpression(GeneType.Mortgage, AssetReference.Whitehall, 0.3f);
            geneticCode1.SetGeneExpression(GeneType.Mortgage, AssetReference.Mayfair, 0.4f);
            geneticCode2.SetGeneExpression(GeneType.Mortgage, AssetReference.Mayfair, 0.4f);

            var offspring = geneticCode1.Cross(geneticCode2, false);

            Assert.AreEqual(15, offspring.Generation);
            Assert.IsTrue(0.7f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.OldKentRoad) || 0.3f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.OldKentRoad));
            Assert.IsTrue(0.1f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.Whitehall) || 0.3f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.Whitehall));
            Assert.IsTrue(0.4f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.Mayfair));
            Assert.IsTrue(0.2f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.BondStreet));
            Assert.IsTrue(0.8f == offspring.GetGeneExpression(GeneType.Mortgage, AssetReference.RegentStreet));
        }