示例#1
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);
        }
示例#2
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);
        }
示例#3
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));
        }
示例#4
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);
        }
示例#5
0
        public void LoansAreHonored()
        {
            BoardState        state   = DataTest.SampleGame;
            ProposeLoanAction propose = new ProposeLoanAction {
                LoanAmount = 123m, PayBack = 999m, Period = state.Settings.YearLength, PlayerId = 0
            };

            state = Tick.Apply(state, new List <GameAction> {
                propose
            });

            int            loanId = state.Proposals.FindIndex(l => l.LoanAmount == 123m);
            TakeLoanAction loan   = new TakeLoanAction {
                LoanProposalId = loanId, PlayerId = 1
            };

            state = Tick.Apply(state, new List <GameAction> {
                loan
            });

            Thread.Sleep(state.Settings.YearLength);
            state = Tick.Apply(state, new List <GameAction> {
            });

            Assert.AreEqual(-1, state.Loans.FindIndex(l => l.Amount == 123m));
            Assert.That(500m < state.Players[0].Cash);
        }
示例#6
0
        public void GameStartsWithCorrectNumberOfUsers()
        {
            BoardState   game     = DataTest.SampleGame;
            GameSettings settings = game.Settings;

            settings.NumPlayers = 3;

            game.Settings = settings;
            game.State    = GameState.GameNotStarted;

            JoinAction join = new JoinAction {
                PlayerId = 3, PlayerName = "Player 3"
            };
            BoardState last = Tick.Apply(game, new List <GameAction> {
                join
            });

            Assert.AreEqual(GameState.Started, last.State);
            Assert.AreEqual(3, last.Players.Count);

            Player added = last.Players.First(p => p.PlayerId == 3);

            Assert.AreEqual(game.Settings.Factories, added.NumFactories);
            Assert.AreEqual(0, added.NextFactory);
            Assert.AreEqual(game.Settings.StartMoney, added.Cash);
        }
示例#7
0
        public void WorkersArePaidTheirWage()
        {
            BoardState game = DataTest.SampleGame;

            game.Workers[0].Wage = 10000m;
            Thread.Sleep(game.Settings.YearLength);

            game = Tick.Apply(game, new GameAction[0]);
            Assert.Less(game.Players[0].Cash, -9000m);
        }
示例#8
0
        public void FireWorkerActionWorks()
        {
            BoardState       game = DataTest.SampleGame;
            FireWorkerAction fire = new FireWorkerAction {
                PlayerId = 0
            };

            game = Tick.Apply(game, new List <GameAction> {
                fire
            });
            Assert.AreEqual(0, GameWorkersTest.GetPlayerWorkers(game, 0).Length);
        }
示例#9
0
        public void AssignWorkerHonored()
        {
            BoardState         game     = DataTest.SampleGame;
            int                workerId = game.Players[1].WorkerIds.First(w => game.Workers[w].Job == Job.Factory);
            AssignWorkerAction assign   = new AssignWorkerAction {
                PlayerId = 1, Work = Job.Research, WorkerId = workerId
            };

            game = Tick.Apply(game, new List <GameAction> {
                assign
            });
            Assert.AreEqual(Job.Research, game.Workers[workerId].Job);
        }
示例#10
0
        public void GameTicks()
        {
            BoardState game            = DataTest.SampleGame;
            DateTime   beforeTimestamp = game.LastTick;
            long       beforeTick      = game.GameTick;

            Thread.Sleep(50);
            game = Tick.Apply(game, new GameAction[0]);
            DateTime afterTimestamp = game.LastTick;
            long     afterTick      = game.GameTick;

            Assert.AreEqual(beforeTick + 1, afterTick);
            Assert.Greater((afterTimestamp - beforeTimestamp).Ticks, TimeSpan.FromMilliseconds(49).Ticks);
        }
示例#11
0
        public void FireWorkerChoosesHighestPaid()
        {
            BoardState       game = DataTest.SampleGame;
            decimal          highestWageBefore = game.Players[1].WorkerIds.Select(w => game.Workers[w]).Max(w => w.Wage);
            FireWorkerAction fire = new FireWorkerAction {
                PlayerId = 1
            };

            game = Tick.Apply(game, new List <GameAction> {
                fire
            });
            decimal highestWageAfter = game.Players[1].WorkerIds.Select(w => game.Workers[w]).Max(w => w.Wage);

            Assert.Greater(highestWageBefore, highestWageAfter);
        }
示例#12
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));
        }
示例#13
0
        public void GiveGiftHonored()
        {
            BoardState     state = DataTest.SampleGame;
            decimal        giftGiverCashBefore    = state.Players[1].Cash;
            decimal        giftReceiverCashBefore = state.Players[0].Cash;
            GiveGiftAction gift = new GiveGiftAction {
                PlayerId = 1, GiftAmount = 100m, ToPlayerId = 0
            };

            state = Tick.Apply(state, new List <GameAction> {
                gift
            });

            Assert.Greater(0, state.Players[1].Cash);
            Assert.Less(90, state.Players[0].Cash);
        }
示例#14
0
        public void DefaultLoanAlwaysShowsUpFirst()
        {
            BoardState state = DataTest.SampleGame;

            state.Proposals = new List <LoanProposal>();

            ProposeLoanAction loan = new ProposeLoanAction {
                PlayerId = 0, LoanAmount = 100m, PayBack = 101m, Period = state.Settings.YearLength
            };

            state = Tick.Apply(state, new List <GameAction> {
                loan
            });

            Assert.Greater(state.Proposals.Count, 1);
            Assert.AreEqual(-1, state.Proposals[0].PlayerId);
            Assert.AreEqual(state.Settings.YearLength.Ticks * state.Settings.DefaultLoanYears, state.Proposals[0].Period.Ticks);
        }
示例#15
0
        public void ProposeLoanShowsUp()
        {
            BoardState        state = DataTest.SampleGame;
            ProposeLoanAction loan  = new ProposeLoanAction {
                PlayerId = 0, LoanAmount = 123m, PayBack = 124m, Period = state.Settings.YearLength
            };

            state = Tick.Apply(state, new List <GameAction> {
                loan
            });

            LoanProposal prop = state.Proposals.First(l => l.LoanAmount == 123m);

            Assert.AreEqual(0, prop.PlayerId);
            Assert.AreEqual(123m, prop.LoanAmount);
            Assert.AreEqual(124m, prop.PayBack);
            Assert.AreEqual(state.Settings.YearLength, prop.Period);
        }
示例#16
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]);
            }
        }
示例#17
0
        public void CannotWithdrawSomeoneElsesProposal()
        {
            BoardState        state = DataTest.SampleGame;
            ProposeLoanAction loan  = new ProposeLoanAction {
                PlayerId = 0, LoanAmount = 123m, PayBack = 124m, Period = state.Settings.YearLength
            };

            state = Tick.Apply(state, new List <GameAction> {
                loan
            });

            int withdrawId = state.Proposals.FindIndex(p => p.LoanAmount == 123m);
            WithdrawProposalAction withdraw = new WithdrawProposalAction {
                PlayerId = 1, ProposalId = withdrawId
            };

            state = Tick.Apply(state, new List <GameAction> {
                withdraw
            });

            Assert.AreEqual(1, state.Proposals.Count(p => p.LoanAmount == 123m));
        }
示例#18
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);
        }
示例#19
0
        public void TakeLoanActionHonored()
        {
            BoardState        state   = DataTest.SampleGame;
            ProposeLoanAction propose = new ProposeLoanAction {
                LoanAmount = 123m, PayBack = 120m, Period = state.Settings.YearLength, PlayerId = 0
            };

            state = Tick.Apply(state, new List <GameAction> {
                propose
            });

            int            loanId = state.Proposals.FindIndex(l => l.LoanAmount == 123m);
            TakeLoanAction loan   = new TakeLoanAction {
                LoanProposalId = loanId, PlayerId = 1
            };

            state = Tick.Apply(state, new List <GameAction> {
                loan
            });

            Assert.Greater(-90, state.Players[0].Cash);
            Assert.Less(90, state.Players[1].Cash);
        }
示例#20
0
文件: Program.cs 项目: f00f-nyc/AllIn
        static void Main(string[] args)
        {
            Console.WriteLine("Starting game...");
#if DEBUG
            Console.WriteLine("Debug mode");

            while (true)
            {
                Program.PostState();
                Program.Wait();
                var actions = Program.GetActions(Program.game);
                Program.game = Tick.Apply(Program.game, actions);
                Console.WriteLine("Processed tick {0} at {1}", Program.game.GameTick, Program.game.LastTick);

                if (Program.game.State != GameState.Started)
                {
                    Console.WriteLine("! Game not started");
                }
                else
                {
                    Program.PrintState();
                }

                Console.WriteLine("");
            }
#else
            Console.WriteLine("Will read user actions from: ", Program.GetAddress);
            Console.WriteLine("Attempting to post state to: {0}", Program.PostAddress);

            while (true)
            {
                Program.PostState();
                Program.Wait()
                Program.game = Tick.Apply(Program.game, Program.GetActions());
            }
#endif
        }