Ejemplo n.º 1
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.º 2
0
 private PrivateAuctionRound(ImmutableList<Player> players, ImmutableList<PrivateCompany> privates, Auction<PrivateCompany> auction, Player activePlayer, Player lastToAct, int seedMoney)
     : base(players, activePlayer, lastToAct)
 {            
     Privates = privates;
     CurrentAuction = auction;
     SeedMoney = seedMoney;
 }
Ejemplo n.º 3
0
 public GameState(Game game, Round round, Player priority, ImmutableList<PlayerState> playerStates, ImmutableList<CompanyState> companyStates)
 {
     Game = game;
     Round = round;
     PlayerWithPriority = priority;
     PlayerStates = playerStates;
     CompanyStates = companyStates;
 }
Ejemplo n.º 4
0
        private static IGameAction GetActionForChoice(Player activePlayer, IChoice choice)
        {
            if (choice is PassChoice)
                return new PlayerPassAction(LastAction, activePlayer);

            if (choice is BidChoice<PrivateCompany>)
                return GetActionForChoice(activePlayer, choice as BidChoice<PrivateCompany>);

            throw new Exception($"Choice of type '{choice.GetType()}' not recognized.");
        }
Ejemplo n.º 5
0
        private static PlayerPrivateBidAction GetActionForChoice(Player activePlayer, BidChoice<PrivateCompany> choice)
        {
            int price = -1;

            while (true)
            {
                Console.Write("Enter price:");
                string priceInput = Console.ReadLine();

                if (int.TryParse(priceInput, out price))
                {
                    return new PlayerPrivateBidAction(LastAction, activePlayer, choice.Target, price);
                }
                else
                {
                    Console.WriteLine("Unexpected input!");
                }
            }
        }
Ejemplo n.º 6
0
 public static void PlayerHasMoney(GameState state, Player player, int money)
 {
     Assert.Equal(money, state.GetPlayerState(player).Money);
 }
Ejemplo n.º 7
0
 public static void PlayerHasPriority(GameState gameState, Player player)
 {
     Assert.Equal(player, gameState.PlayerWithPriority);
 }
Ejemplo n.º 8
0
 private GameState Update(Round round = null, Player playerWithPriority = null, ImmutableList<PlayerState> playerStates = null, ImmutableList<CompanyState> companyStates = null) =>
     new GameState(Game, round ?? Round, playerWithPriority ?? PlayerWithPriority, playerStates ?? PlayerStates, companyStates ?? CompanyStates);        
Ejemplo n.º 9
0
 public static void ActivePlayerIs(GameState gameState, Player player)
 {
     Assert.Equal(player, gameState.Round.GetActivePlayer(gameState));
 }
Ejemplo n.º 10
0
 private StockRound Update(Auction<Location> auction = null, Player activePlayer = null, Player lastToAct = null) =>
     new StockRound(Players, auction ?? CurrentAuction, RoundNumber, activePlayer ?? ActivePlayer, lastToAct ?? LastToAct);
Ejemplo n.º 11
0
 public PlayerState GetPlayerState(Player player) => PlayerStates.Single(s => s.Player == player);
Ejemplo n.º 12
0
 public static StockRound StartOfRound(ImmutableList<Player> players, int roundNumber, Player priority) =>
     new StockRound(players, null, roundNumber, priority, null);
Ejemplo n.º 13
0
 public static Player GetPlayerAfter(this ImmutableList<Player> players, Player p) => players[(players.IndexOf(p) + 1) % players.Count];
Ejemplo n.º 14
0
 public static void PlayerHasPrivate(GameState state, Player player, PrivateCompany company)
 {
     Assert.Contains(company, state.GetPlayerState(player).PrivateCompanies);
 }
Ejemplo n.º 15
0
 public PlayerState(Player player, int money) : this(player, money, ImmutableList<PrivateCompany>.Empty)
 {
 }
Ejemplo n.º 16
0
 public void PlayerStartsAnIPO(Player player, Location location, int bid)
 {
     LastAction = new PlayerIPOBidAction(LastAction, player, location, bid);
 }
Ejemplo n.º 17
0
 public IGameAction PlayerBidsOnPrivate(Player player, PrivateCompany privateCompany, int bid)
 {
     LastAction = new PlayerPrivateBidAction(LastAction, player, privateCompany, bid);
     return LastAction;
 }
Ejemplo n.º 18
0
 private StockRound StartAuction(Player biddingPlayer, Location selection, int bid)
 {
     var auction = new Auction<Location>(selection, biddingPlayer, bid, Players);
     return Update(auction: auction, activePlayer: Players.GetPlayerAfter(biddingPlayer), lastToAct: biddingPlayer);
 }
Ejemplo n.º 19
0
 private PrivateAuctionRound StartAuction(Player biddingPlayer, PrivateCompany selection, int bid)
 {
     var auction = new Auction<PrivateCompany>(selection, biddingPlayer, bid, Players);
     return Update(auction: auction, activePlayer: Players.GetPlayerAfter(biddingPlayer), lastToAct: biddingPlayer);            
 }
Ejemplo n.º 20
0
 private PrivateAuctionRound Update(ImmutableList<PrivateCompany> privates = null, Auction<PrivateCompany> auction = null, Player activePlayer = null, Player lastToAct = null, int? seedMoney = null) =>
     new PrivateAuctionRound(Players, privates ?? Privates, auction ?? CurrentAuction, activePlayer ?? ActivePlayer, lastToAct ?? LastToAct, seedMoney ?? SeedMoney);        
Ejemplo n.º 21
0
 public PlayerState(Player player, int money, ImmutableList<PrivateCompany> privateCompanies)
 {
     Player = player;
     Money = money;
     PrivateCompanies = privateCompanies;
 }
Ejemplo n.º 22
0
 public PendingAction(Player player, ImmutableList<IChoice> choices)
 {
     ActivePlayer = player;
     Choices = choices;
 }
Ejemplo n.º 23
0
 public PlayerRound(ImmutableList<Player> players, Player activePlayer, Player lastToAct)
 {
     Players = players;
     ActivePlayer = activePlayer;
     LastToAct = lastToAct;
 }
Ejemplo n.º 24
0
 public StockRound(ImmutableList<Player> players, Auction<Location> currentAuction, int roundNumber, Player priority, Player lastToAct) : base(players, priority, lastToAct)
 {
     CurrentAuction = currentAuction;
     RoundNumber = roundNumber;
 }