Ejemplo n.º 1
0
        public PendingAction GetPendingAction(GameState gameState)
        {
            var choices = gameState.Round.GetChoices(gameState);
            var activePlayer = gameState.Round.GetActivePlayer(gameState);

            return new PendingAction(activePlayer, choices.ToImmutableList());
        }
Ejemplo n.º 2
0
        public static GameState Pass(GameState gameState, PrivateAuctionRound round, Player passingPlayer)
        {                        
            if (round.CurrentAuction != null)
            {
                var newAuction = round.CurrentAuction.Pass(passingPlayer);
                if (newAuction.IsComplete)
                {                    
                    return CompleteAuction(gameState, round);
                }

                // auction continues                    
                round = round.Update(auction: newAuction, activePlayer: newAuction.GetNextPlayer());
                return gameState.WithRound(round);                    
            }            
            else if (round.ActivePlayer == round.LastToAct)
            {
                // Exit the auction round early as everyone passed
                var priorityDeal = round.Players.GetPlayerAfter(round.LastToAct);
                var newRound = StockRound.StartOfRound(round.Players, 1, priorityDeal);
                return new GameState(gameState.Game, newRound, priorityDeal, gameState.PlayerStates, gameState.CompanyStates);
            }
            else
            {
                // player elects not to put anything up for auction
                var newRound = round.Update( activePlayer: gameState.Game.Players.GetPlayerAfter(passingPlayer));
                return gameState.WithRound(newRound);
            }            
        }
Ejemplo n.º 3
0
        public static void ValidateIPOBid(GameState state, GameActionValidator validator, StockRound round, PlayerState actingPlayerState, Location selection, int bid)
        {
            var currentAuction = round.CurrentAuction;
            if (currentAuction != null)
            {
                validator.Validate(selection == currentAuction.Selection,
                    $"Bid on '{selection}' is not legal - there is already an auction for '{currentAuction.Selection}' in progress.");
                validator.Validate(bid > currentAuction.HighBid,
                    $"Bid of '{bid}' is not legal - the current high bid is '{currentAuction.HighBid}'.");
            }

            validator.ValidateMultipleOf(5, bid, $"Bid of '{bid}' is not legal - must be a multiple of 5.");
            validator.Validate(bid <= MaximumIPOBid, $"Bid of '{bid}' is not legal - the maximum IPO bid is $400.");            
            validator.Validate(bid <= actingPlayerState.Money, $"Bid of '{bid}' is not legal - player '{actingPlayerState.Player}' has only {actingPlayerState.Money} cash available.");
        }
Ejemplo n.º 4
0
        public static GameState MakeBid(GameState gameState, PrivateAuctionRound round, PlayerState biddingPlayerState, PrivateCompany selection, int bid)
        {            
            if (round.CurrentAuction == null)
            {
                // No auction is in progress so start a new auction for the selected private 
                round = round.StartAuction(biddingPlayerState.Player, selection, bid);
            }
            else
            {
                // Apply the new bid to the current auction
                var newAuction = round.CurrentAuction.MakeBid(selection, biddingPlayerState.Player, bid);
                round = round.Update(auction: newAuction, activePlayer: newAuction.GetNextPlayer());
            }

            if (bid == selection.Value)
            {
                // Maximum bid was made, auction terminates                                
                return CompleteAuction(gameState, round);
            }

            return gameState.WithRound(round);
        }
Ejemplo n.º 5
0
 public override Player GetActivePlayer(GameState gameState)
 {
     return ActivePlayer;
 }
Ejemplo n.º 6
0
 public OperatingRound(GameState gameState, Company activeCompany, int roundNumber, RoundMode mode)
     : base(activeCompany)
 {
     RoundNumber = roundNumber;
     RoundMode = mode;
 }
Ejemplo n.º 7
0
 public static void PlayerHasPrivate(GameState state, Player player, PrivateCompany company)
 {
     Assert.Contains(company, state.GetPlayerState(player).PrivateCompanies);
 }
Ejemplo n.º 8
0
 public static void PlayerHasPriority(GameState gameState, Player player)
 {
     Assert.Equal(player, gameState.PlayerWithPriority);
 }
Ejemplo n.º 9
0
 public static void PlayerHasMoney(GameState state, Player player, int money)
 {
     Assert.Equal(money, state.GetPlayerState(player).Money);
 }
Ejemplo n.º 10
0
 public override Player GetActivePlayer(GameState gameState)
 {
     return gameState.GetOwner(ActiveCompany);
 }
Ejemplo n.º 11
0
        private static void PrintState(GameState state, PendingAction pendingAction)
        {
            Console.Clear();

            Console.WriteLine($"Current Round: {state.Round.Description}");

            Console.WriteLine();
            Console.WriteLine("Players:");
            foreach (var p in state.Game.Players)
            {
                if (p == pendingAction.ActivePlayer)
                    Console.ForegroundColor = ConsoleColor.Yellow;

                var playerState = state.GetPlayerState(p);
                var privates = string.Join(", ", playerState.PrivateCompanies.Select(x => x.Name));
                var biddingPower = playerState.PrivateCompanies.Sum(x => x.Value) + playerState.Money;
                Console.WriteLine($"{p.Name.PadRight(10, ' ')} Cash: {playerState.Money}\t Bidding Power: {biddingPower}\t Privates: {privates} ");

                Console.ResetColor();
            }

            var privateAuctionRound = state.Round as PrivateAuctionRound;

            if(privateAuctionRound != null)
            {
                Console.WriteLine();
                Console.WriteLine($"Seed money: {privateAuctionRound.SeedMoney}");

                var currentAuction = (state.Round as PrivateAuctionRound)?.CurrentAuction;
                if (currentAuction != null)
                {
                    Console.WriteLine($"Current Auction: {currentAuction.Selection.Name}");
                    Console.WriteLine($"High bid: {currentAuction.HighBid} ({currentAuction.HighBidder.Name})");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Select an action - pass, undo, or pick a number:");
            foreach (var c in pendingAction.Choices)
            {
                Console.WriteLine($"{pendingAction.Choices.IndexOf(c)}. {c.Description}");
            }
        }
Ejemplo n.º 12
0
        public override IEnumerable<IChoice> GetChoices(GameState gameState)
        {
            var choices = new List<IChoice>();
            choices.Add(new PassChoice());

            var playerState = gameState.GetPlayerState(ActivePlayer);

            if (CurrentAuction != null)
            {                    
                choices.Add(GetLegalBid(playerState, CurrentAuction.Selection));
            }
            else
            {                
                foreach (var company in Privates)
                    choices.Add(GetLegalBid(playerState, company));
            }

            return choices.Where(c => c != null);
        }
Ejemplo n.º 13
0
        private static GameState CompleteAuction(GameState gameState, PrivateAuctionRound round)
        {
            var currentAuction = round.CurrentAuction;
            var stateForWinningPlayer = gameState.GetPlayerState(currentAuction.HighBidder);
            var winningPlayerPrivates = stateForWinningPlayer.PrivateCompanies.Add(currentAuction.Selection);

            var newPlayerStates = gameState.PlayerStates.Replace(stateForWinningPlayer, 
                new PlayerState(stateForWinningPlayer.Player, stateForWinningPlayer.Money - currentAuction.HighBid, winningPlayerPrivates));                

            var seedFunding = currentAuction.Selection.Value - currentAuction.HighBid;
            var remainingPrivates = round.Privates.Remove(currentAuction.Selection);
            var nextPlayer = round.Players.GetPlayerAfter(round.LastToAct);

            Round newRound;            
            if (remainingPrivates.IsEmpty)
            {
                newRound = StockRound.StartOfRound(round.Players, 1, nextPlayer);
                return new GameState(gameState.Game, newRound, nextPlayer, newPlayerStates, gameState.CompanyStates);
            }
            else
            {
                newRound = new PrivateAuctionRound(round.Players, remainingPrivates, null, nextPlayer, round.LastToAct, round.SeedMoney - seedFunding);
                return new GameState(gameState.Game, newRound, gameState.PlayerWithPriority, newPlayerStates, gameState.CompanyStates);
            }
            
            
        }
Ejemplo n.º 14
0
 private static GameState CompleteAuction(GameState gameState, StockRound round)
 {
     // Go into a state that requires the player to specify funding
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 public abstract Player GetActivePlayer(GameState gameState);
Ejemplo n.º 16
0
 public abstract IEnumerable<IChoice> GetChoices(GameState gameState);
Ejemplo n.º 17
0
 public static void ActivePlayerIs(GameState gameState, Player player)
 {
     Assert.Equal(player, gameState.Round.GetActivePlayer(gameState));
 }
Ejemplo n.º 18
0
 public override IEnumerable<IChoice> GetChoices(GameState gameState)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
 public static void CurrentRoundIs(GameState gameState, string roundDescription)
 {
     Assert.Equal(roundDescription, gameState.Round.Description);
 }