public GameState GetCurrentState() { var validator = new GameActionValidator(); var state = Game.GetLastValidState(LastAction, validator); if (validator.IsValid == false) throw new Exception(validator.GetSummary()); return state; }
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."); }
public static void ValidateBid(GameActionValidator validator, PrivateAuctionRound round, PlayerState actingPlayerState, PrivateCompany 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 <= selection.Value, $"Bid of '{bid}' is not legal - overbidding is not permitted."); validator.Validate(round.SeedMoney >= selection.Value - bid, $"Bid of '{bid}' is not legal - not enough seed money."); validator.Validate(bid <= actingPlayerState.Money, $"Bid of '{bid}' is not legal - player '{actingPlayerState.Player}' has only {actingPlayerState.Money} cash available."); }
public GameState GetLastValidState(IGameAction finalAction, GameActionValidator validator) { GameState state = GetInitialState(); if (finalAction == null) return state; foreach (var gameAction in finalAction.Sequence) { var newState = gameAction.TryApply(state, validator); if (validator.IsValid) state = newState; else { break; } } return state; }
private static void RunGameLoop() { while (true) { var validator = new GameActionValidator(); var state = Game.GetLastValidState(LastAction, validator); if (validator.IsValid) { var pendingAction = Game.GetPendingAction(state); PrintState(state, pendingAction); LastAction = PromptUser(pendingAction); } else { PrintError(validator); LastAction = LastAction.Parent; } } }
private static void PrintError(GameActionValidator validator) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(validator.GetSummary()); Console.ResetColor(); Console.ReadLine(); }