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); } }
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; }
public GameState(Game game, Round round, Player priority, ImmutableList<PlayerState> playerStates, ImmutableList<CompanyState> companyStates) { Game = game; Round = round; PlayerWithPriority = priority; PlayerStates = playerStates; CompanyStates = companyStates; }
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."); }
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!"); } } }
public static void PlayerHasMoney(GameState state, Player player, int money) { Assert.Equal(money, state.GetPlayerState(player).Money); }
public static void PlayerHasPriority(GameState gameState, Player player) { Assert.Equal(player, gameState.PlayerWithPriority); }
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);
public static void ActivePlayerIs(GameState gameState, Player player) { Assert.Equal(player, gameState.Round.GetActivePlayer(gameState)); }
private StockRound Update(Auction<Location> auction = null, Player activePlayer = null, Player lastToAct = null) => new StockRound(Players, auction ?? CurrentAuction, RoundNumber, activePlayer ?? ActivePlayer, lastToAct ?? LastToAct);
public PlayerState GetPlayerState(Player player) => PlayerStates.Single(s => s.Player == player);
public static StockRound StartOfRound(ImmutableList<Player> players, int roundNumber, Player priority) => new StockRound(players, null, roundNumber, priority, null);
public static Player GetPlayerAfter(this ImmutableList<Player> players, Player p) => players[(players.IndexOf(p) + 1) % players.Count];
public static void PlayerHasPrivate(GameState state, Player player, PrivateCompany company) { Assert.Contains(company, state.GetPlayerState(player).PrivateCompanies); }
public PlayerState(Player player, int money) : this(player, money, ImmutableList<PrivateCompany>.Empty) { }
public void PlayerStartsAnIPO(Player player, Location location, int bid) { LastAction = new PlayerIPOBidAction(LastAction, player, location, bid); }
public IGameAction PlayerBidsOnPrivate(Player player, PrivateCompany privateCompany, int bid) { LastAction = new PlayerPrivateBidAction(LastAction, player, privateCompany, bid); return LastAction; }
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); }
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); }
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);
public PlayerState(Player player, int money, ImmutableList<PrivateCompany> privateCompanies) { Player = player; Money = money; PrivateCompanies = privateCompanies; }
public PendingAction(Player player, ImmutableList<IChoice> choices) { ActivePlayer = player; Choices = choices; }
public PlayerRound(ImmutableList<Player> players, Player activePlayer, Player lastToAct) { Players = players; ActivePlayer = activePlayer; LastToAct = lastToAct; }
public StockRound(ImmutableList<Player> players, Auction<Location> currentAuction, int roundNumber, Player priority, Player lastToAct) : base(players, priority, lastToAct) { CurrentAuction = currentAuction; RoundNumber = roundNumber; }