示例#1
0
        public void CannotHireIfGameIsNotStarted()
        {
            BoardState game = DataTest.SampleGame;
            game.State = GameState.GameNotStarted;
            HireWorkerAction hire = new HireWorkerAction { PlayerId = 0 };

            int workersBefore = GameWorkersTest.UnhiredWorkersCount(game);
            game = Tick.Apply(game, new List<GameAction> { hire });
            Assert.AreEqual(workersBefore, GameWorkersTest.UnhiredWorkersCount(game));
        }
示例#2
0
        public void CannotHireWorkerJustFied()
        {
            BoardState game = DataTest.SampleGame;
            HireWorkerAction hire = new HireWorkerAction() { PlayerId = 1 };
            game = Tick.Apply(game, new List<GameAction> { hire, hire });

            Assert.AreEqual(0, GameWorkersTest.UnhiredWorkersCount(game), "This test relies on the fact that there are exactly two unhired workers");
            FireWorkerAction fire = new FireWorkerAction() { PlayerId = 1 };
            game = Tick.Apply(game, new List<GameAction> { fire });

            Assert.That(game.Players[1].RecentWorkers.Count > 0);
            Assert.AreEqual(1, GameWorkersTest.UnhiredWorkersCount(game));
            game = Tick.Apply(game, new List<GameAction> { hire });
            Assert.AreEqual(1, GameWorkersTest.UnhiredWorkersCount(game));
        }
示例#3
0
        public void SerializeItAll()
        {
            JoinAction join = new JoinAction { PlayerId = 1, PlayerName = "Test Player" };
            HireWorkerAction hire = new HireWorkerAction { PlayerId = 2 };
            FireWorkerAction fire = new FireWorkerAction { PlayerId = 3 };
            ProposeLoanAction propose = new ProposeLoanAction { PlayerId = 4, Period = TimeSpan.FromMinutes(1.0), PayBack = 20m, LoanAmount = 15m };
            WithdrawProposalAction withdraw = new WithdrawProposalAction { PlayerId = 5, ProposalId = 2 };
            GiveGiftAction gift = new GiveGiftAction { PlayerId = 6, ToPlayerId = 2, GiftAmount = 10.2m };
            AssignWorkerAction research = new AssignWorkerAction { PlayerId = 7, Work = Job.Research, WorkerId = 1 };
            AssignWorkerAction factory = new AssignWorkerAction { PlayerId = 8, Work = Job.Factory, WorkerId = 2 };
            TakeLoanAction loan = new TakeLoanAction { PlayerId = 9, LoanProposalId = 1 };

            StringBuilder sb = new StringBuilder();
            sb.Append("{\"gameJson\": ");
            sb.Append(DataTest.SampleGame.ToJson());
            sb.Append("\n, \"NoOp\": ");
            sb.Append(new NoOpAction().ToJson());
            sb.Append("\n \"JoinGame\": ");
            sb.Append(join.ToJson());
            sb.Append("\n \"HireWorker\": ");
            sb.Append(hire.ToJson());
            sb.Append("\n \"FireWorker\": ");
            sb.Append(fire.ToJson());
            sb.Append("\n \"ProposeLoan\": ");
            sb.Append(propose.ToJson());
            sb.Append("\n \"WithdrawProposal\": ");
            sb.Append(withdraw.ToJson());
            sb.Append("\n \"GiveGift\": ");
            sb.Append(gift.ToJson());
            sb.Append("\n \"AssignWorkerResearch\": ");
            sb.Append(research.ToJson());
            sb.Append("\n \"AssignWorkerFactory\": ");
            sb.Append(factory.ToJson());
            sb.Append("\n \"TakeLoan\": ");
            sb.Append(loan.ToJson());

            List<GameAction> actions = new List<GameAction> { hire, fire, loan };
            string json = GameAction.SerializeList(actions);
            List<GameAction> fromJson = GameAction.DeserializeList(json);

            List<GameAction> empty = new List<GameAction>();
            json = GameAction.SerializeList(empty);
            fromJson = GameAction.DeserializeList(json);
        }
示例#4
0
        public void HiringAFiredWorkerRemovesRecentWorkerIndicator()
        {
            BoardState game = DataTest.SampleGame;
            HireWorkerAction player1Hire = new HireWorkerAction() { PlayerId = 1 };
            game = Tick.Apply(game, new List<GameAction> { player1Hire, player1Hire });

            Assert.AreEqual(0, GameWorkersTest.UnhiredWorkersCount(game), "This test relies on the fact that there are exactly two unhired workers");
            FireWorkerAction fire = new FireWorkerAction() { PlayerId = 1 };
            game = Tick.Apply(game, new List<GameAction> { fire });

            HireWorkerAction player0Hire = new HireWorkerAction() { PlayerId = 0 };
            game = Tick.Apply(game, new List<GameAction> { player0Hire });
            Assert.AreEqual(0, game.Players[1].RecentWorkers.Count);
        }
示例#5
0
        public void WorkersFromPoolHiredAtSetWage()
        {
            BoardState game = DataTest.SampleGame;
            List<int> unhiredWokerIds = new List<int>();
            for (int i=0; i<game.Workers.Length; i++)
            {
                if (game.Workers[i].Job == Job.Unemployed)
                {
                    unhiredWokerIds.Add(i);
                }
            }
            Assert.AreEqual(2, unhiredWokerIds.Count, "The test is written based on the assumption that there are exactly 2 workers free in the pool.");

            HireWorkerAction hire = new HireWorkerAction() { PlayerId = 0 };
            game = Tick.Apply(game, new List<GameAction> { hire, hire });

            Worker hiredWorker = game.Workers[unhiredWokerIds[0]];
            Assert.AreEqual(Job.Factory, hiredWorker.Job);
            Assert.AreEqual(game.Settings.WorkerInitialWage, hiredWorker.Wage);
        }
示例#6
0
        public void WorkersAreHiredFromPoolFirst()
        {
            BoardState game = DataTest.SampleGame;
            HireWorkerAction hire = new HireWorkerAction() { PlayerId = 0 };

            int workersBefore = GameWorkersTest.UnhiredWorkersCount(game);
            Assert.AreEqual(2, workersBefore, "The test is written based on the assumption that there are exactly 2 workers free in the pool.");

            game = Tick.Apply(game, new List<GameAction> { hire });
            game = Tick.Apply(game, new List<GameAction> { hire });
            Assert.AreEqual(0, GameWorkersTest.UnhiredWorkersCount(game));

            Worker[] player2WorkersBefore = GameWorkersTest.GetPlayerWorkers(game, 1);
            game = Tick.Apply(game, new List<GameAction> { hire });
            Worker[] player2WorkersAfter = GameWorkersTest.GetPlayerWorkers(game, 1);

            Assert.AreEqual(player2WorkersBefore.Length - 1, player2WorkersAfter.Length);
        }
示例#7
0
        public void HiringFromAnotherPlayerHonorsSettings()
        {
            BoardState game = DataTest.SampleGame;
            HireWorkerAction hire = new HireWorkerAction() { PlayerId = 1 };
            game = Tick.Apply(game, new List<GameAction> { hire, hire });

            int wId = game.Players[0].WorkerIds[0];
            decimal wageBefore = game.Workers[wId].Wage;
            game = Tick.Apply(game, new List<GameAction> { hire });
            decimal wageAfter = game.Workers[wId].Wage;

            Assert.AreEqual(wageBefore * game.Settings.WorkerLureWageMultiplier, wageAfter);
        }
示例#8
0
        public void HiringAllWorkers()
        {
            BoardState game = DataTest.SampleGame;
            HireWorkerAction hire = new HireWorkerAction() { PlayerId = 0 };
            List<GameAction> hireList = game.Workers.Select(w => hire).Cast<GameAction>().ToList();
            game = Tick.Apply(game, hireList);

            List<decimal> currentWagesBefore = game.Workers.Select(w => w.Wage).ToList();
            Tick.Apply(game, hireList);
            List<decimal> currentWagesAfter = game.Workers.Select(w => w.Wage).ToList();

            for (int i = 0; i < currentWagesAfter.Count; i++)
            {
                Assert.AreEqual(currentWagesBefore[i], currentWagesAfter[i]);
            }
        }