public void Normal()
        {
            GameState g    = MockGameState.GetMockState();
            int       cost = g.ResourceMarket.GetCost(ResourceType.Coal);

            string    preGameStateString = JsonConvert.SerializeObject(g);
            GameState preGameState       = JsonConvert.DeserializeObject <GameState>(preGameStateString);

            Game.BuyResource(preGameState.Players.First.Value, ResourceType.Coal, 1);
            GameState postGameState = MockGameState.GetMockState();

            Assert.Equal(preGameState.Players.First.Value.Money, postGameState.Players.First.Value.Money + cost);
        }
        public void NoMoney()
        {
            GameState g = MockGameState.GetMockState();

            g.Players.First.Value.Money = 0;
            string    preGameStateString = JsonConvert.SerializeObject(g);
            GameState preGameState       = JsonConvert.DeserializeObject <GameState>(preGameStateString);

            Game.BuyResource(preGameState.Players.First.Value, ResourceType.Coal, 1);
            GameState postGameState = MockGameState.GetMockState();

            Assert.Equal(preGameState.Players.First.Value.Money, postGameState.Players.First.Value.Money);
            Assert.Equal(JsonConvert.SerializeObject(preGameState.ResourceMarket), JsonConvert.SerializeObject(postGameState.ResourceMarket));
        }
        public void NoResources()
        {
            for (int i = 0; i <= (int)ResourceType.Nuclear; i++)
            {
                GameState g = MockGameState.GetMockState();
                g.ResourceMarket.Resources.AvailableResources[i] = 0;
                string    preGameStateString = JsonConvert.SerializeObject(g);
                GameState preGameState       = JsonConvert.DeserializeObject <GameState>(preGameStateString);

                Game.BuyResource(preGameState.Players.First.Value, (ResourceType)i, 1);
                GameState postGameState = MockGameState.GetMockState();
                Assert.Equal(preGameState.Players.First.Value.Money, postGameState.Players.First.Value.Money);
                Assert.Equal(JsonConvert.SerializeObject(preGameState.ResourceMarket), JsonConvert.SerializeObject(postGameState.ResourceMarket)); Assert.Equal(JsonConvert.SerializeObject(preGameState.ResourceMarket), JsonConvert.SerializeObject(postGameState.ResourceMarket));
            }
        }
Beispiel #4
0
        public void TestFullGame()
        {
            var gameState = MockGameState.GetMockState();
            var cards     = MockGameState.Cards.ToList();

            var red    = gameState.Players.ToList()[0];
            var blue   = gameState.Players.ToList()[1];
            var green  = gameState.Players.ToList()[2];
            var yellow = gameState.Players.ToList()[3];
            var purple = gameState.Players.ToList()[4];
            var white  = gameState.Players.ToList()[5];

            var actualPath   = "D:\\Workspace\\PowerGrid\\PowerGrid.Tests\\data\\actual\\";
            var expectedPath = "D:\\Workspace\\PowerGrid\\PowerGrid.Tests\\data\\expected\\";

            Setup(gameState, cards, red, blue, green, yellow, purple, white);
            Round1(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround1.json");
            Assert.True(File.ReadLines($"{actualPath}endofround1.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround1.json")));
            Round2(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround2.json");
            Assert.True(File.ReadLines($"{actualPath}endofround2.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround2.json")));
            Round3(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround3.json");
            Assert.True(File.ReadLines($"{actualPath}endofround3.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround3.json")));
            Round4(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround4.json");
            Assert.True(File.ReadLines($"{actualPath}endofround4.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround4.json")));
            Round5(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround5.json");
            Assert.True(File.ReadLines($"{actualPath}endofround5.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround5.json")));
            Round6(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround6.json");
            Assert.True(File.ReadLines($"{actualPath}endofround6.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround6.json")));
            Round7(gameState, cards, red, blue, green, yellow, purple, white);
            Game.ExportGameStateToJsonFile($"{actualPath}endofround7.json");
            Assert.True(File.ReadLines($"{actualPath}endofround7.json").SequenceEqual(File.ReadLines($"{expectedPath}endofround7.json")));
        }
        public void BuyAllResources()
        {
            GameState g = MockGameState.GetMockState();

            g.Players.First.Value.Money = int.MaxValue; // "infinite money"

            for (int i = 0; i <= (int)ResourceType.Nuclear; i++)
            {
                int maxSupply = g.ResourceMarket.GetMaxSuppy((ResourceType)i);
                g.ResourceMarket.Resources.AvailableResources[i] = maxSupply;
                for (int j = 0; j < maxSupply; j++)
                {
                    string    preGameStateString = JsonConvert.SerializeObject(g);
                    GameState preGameState       = JsonConvert.DeserializeObject <GameState>(preGameStateString);
                    int       cost = g.ResourceMarket.GetCost((ResourceType)i);

                    Game.BuyResource(preGameState.Players.First.Value, (ResourceType)i, 1);
                    GameState postGameState = MockGameState.GetMockState();
                    Assert.Equal(preGameState.Players.First.Value.Money, postGameState.Players.First.Value.Money + cost);
                    Assert.Equal(preGameState.ResourceMarket.Resources.AvailableResources[i], postGameState.ResourceMarket.Resources.AvailableResources[i] + 1);
                }
            }
        }