public QueryAndRevealState(Lobby lobby, List <Q> objectsToQuery, List <User> usersToQuery = null, TimeSpan?queryTime = null) { this.Lobby = lobby; this.Objects = objectsToQuery; StateChain VoteAndRevealChainGenerator() { StateChain voteAndRevealStateChain = new StateChain(stateGenerator: (int counter) => { if (counter == 0) { this.Lobby.ResetScores(Score.Scope.Reveal); return(new QueryGameState <Q, T>( lobby: lobby, queryObjects: this.Objects, queriedUsers: usersToQuery, queryUserPromptGenerator: QueryPromptGenerator, answerExtractor: AnswerExtractor, queryExitListener: QueryExitListener, queryUnityView: QueryUnityViewGenerator(), queryTime: queryTime)); } else if (counter == 1) { var revealGameState = new RevealGameState( lobby: lobby, promptTitle: Prompts.Text.ShowScores, revealUnityView: RevealUnityViewGenerator()); revealGameState.AddPerUserExitListener((User user) => user.ScoreHolder.ResetScore(Score.Scope.Reveal)); return(revealGameState); } else { return(null); } }); voteAndRevealStateChain.Transition(this.Exit); return(voteAndRevealStateChain); } this.Entrance.Transition(VoteAndRevealChainGenerator); }
public VoteAndRevealState(Lobby lobby, List <T> objectsToVoteOn, List <User> votingUsers = null, TimeSpan?votingTime = null) { this.Lobby = lobby; this.Objects = objectsToVoteOn; StateChain VoteAndRevealChainGenerator() { StateChain voteAndRevealStateChain = new StateChain(stateGenerator: (int counter) => { if (counter == 0) { this.Lobby.ResetScores(Score.Scope.Reveal); return(new VotingGameState <T>( lobby: lobby, votingObjects: this.Objects, votingUsers: votingUsers, votingUserPromptGenerator: VotingPromptGenerator, votingExitListener: VoteCountManager, votingUnityView: VotingUnityViewGenerator(), votingTime: votingTime)); } else if (counter == 1) { var revealGameState = new VoteRevealGameState( lobby: lobby, promptTitle: Prompts.Text.ShowScores, voteRevealUnityView: RevealUnityViewGenerator()); revealGameState.AddPerUserExitListener((User user) => user.ScoreHolder.ResetScore(Score.Scope.Reveal)); return(revealGameState); } else { return(null); } }); voteAndRevealStateChain.Transition(this.Exit); return(voteAndRevealStateChain); } this.Entrance.Transition(VoteAndRevealChainGenerator); }
public TwoToneDrawingGameMode(Lobby lobby, List <ConfigureLobbyRequest.GameModeOptionRequest> gameModeOptions, StandardGameModeOptions standardOptions) { this.Lobby = lobby; GameDuration duration = standardOptions.GameDuration; int maxPossibleTeamCount = 8; // Can go higher than this in extreme circumstances. bool useSingleColor = (bool)gameModeOptions[(int)GameModeOptionsEnum.useSingleColor].ValueParsed; int numLayers = (int)gameModeOptions[(int)GameModeOptionsEnum.numLayers].ValueParsed; int numPlayers = lobby.GetAllUsers().Count(); if (numLayers * 2 > numPlayers) { numLayers = numPlayers / 2; } int numRounds = Math.Min(TwoToneDrawingConstants.MaxNumRounds[duration], numPlayers); int numDrawingsPerPlayer = Math.Min(TwoToneDrawingConstants.DrawingsPerPlayer[duration], numRounds); int numTeamsLowerBound = Math.Max(2, 1 * numPlayers / (numRounds * numLayers)); // Lower bound. int numTeamsUpperBound = Math.Min(maxPossibleTeamCount, numDrawingsPerPlayer * numPlayers / (numRounds * numLayers)); // Upper bound. int numTeams = Math.Max(numTeamsLowerBound, numTeamsUpperBound); // Possible for lower bound to be higher than upper bound. that is okay. //int drawingsPerPlayer = numRounds * numLayers * numTeams / numPlayers; TimeSpan?setupTimer = null; TimeSpan?drawingTimer = null; TimeSpan?votingTimer = null; if (standardOptions.TimerEnabled) { setupTimer = TwoToneDrawingConstants.SetupTimer[duration]; drawingTimer = TwoToneDrawingConstants.PerDrawingTimer[duration].MultipliedBy(numDrawingsPerPlayer); votingTimer = TwoToneDrawingConstants.VotingTimer[duration]; } Setup = new Setup_GS( lobby: lobby, challengeTrackers: this.SubChallenges, useSingleColor: useSingleColor, numLayersPerTeam: numLayers, numTeamsPerPrompt: numTeams, numRounds: numRounds, setupTimer: setupTimer, drawingTimer: drawingTimer); StateChain GamePlayLoopGenerator() { List <ChallengeTracker> challenges = SubChallenges.Keys.OrderBy(_ => Rand.Next()).ToList(); StateChain chain = new StateChain( stateGenerator: (int counter) => { if (counter < challenges.Count) { return(new StateChain(stateGenerator: (int i) => { switch (i) { case 0: return GetVotingAndRevealState(challenges[counter], votingTimer); case 1: return ((counter == challenges.Count - 1) ? new ScoreBoardGameState(lobby, "Final Scores") : new ScoreBoardGameState(lobby)); default: return null; } })); } else { return(null); } }); chain.Transition(this.Exit); return(chain); } Setup.Transition(GamePlayLoopGenerator); this.Entrance.Transition(Setup); }
public ImposterDrawingGameMode(Lobby lobby, List <ConfigureLobbyRequest.GameModeOptionRequest> gameModeOptions, StandardGameModeOptions standardOptions) { this.Lobby = lobby; TimeSpan? writingTimer = null; TimeSpan? drawingTimer = null; TimeSpan? votingTimer = null; GameDuration duration = standardOptions.GameDuration; if (standardOptions.TimerEnabled) { writingTimer = ImposterDrawingConstants.WritingTimer[duration]; drawingTimer = ImposterDrawingConstants.DrawingTimer[duration]; votingTimer = ImposterDrawingConstants.VotingTimer[duration]; } List <Prompt> prompts = new List <Prompt>(); int numRounds = Math.Min(ImposterDrawingConstants.MaxNumRounds[duration], this.Lobby.GetAllUsers().Count); int numDrawingsPerUser = Math.Min(ImposterDrawingConstants.MaxDrawingsPerPlayer[duration], numRounds - 1); numRounds = Math.Min(numRounds, (this.Lobby.GetAllUsers().Count - 1) * numDrawingsPerUser / ImposterDrawingConstants.MinNumPlayersPerRound); int playersPerPrompt = Math.Min(ImposterDrawingConstants.MaxNumPlayersPerRound, this.Lobby.GetAllUsers().Count - 1); playersPerPrompt = Math.Min(playersPerPrompt, this.Lobby.GetAllUsers().Count *numDrawingsPerUser / numRounds + 1); Setup = new Setup_GS( lobby: lobby, promptsToPopulate: prompts, writingTimeDuration: writingTimer, drawingTimeDuration: drawingTimer, numDrawingsPerUser: numDrawingsPerUser, numRounds: numRounds, maxPlayersPerPrompt: playersPerPrompt); StateChain CreateGamePlayLoop() { List <State> stateList = new List <State>(); foreach (Prompt prompt in prompts) { stateList.Add(GetImposterLoop(prompt, prompt == prompts.Last())); } StateChain gamePlayChain = new StateChain(states: stateList); gamePlayChain.Transition(this.Exit); return(gamePlayChain); } this.Entrance.Transition(Setup); Setup.Transition(CreateGamePlayLoop); StateChain GetImposterLoop(Prompt prompt, bool lastRound = false) { return(new StateChain( stateGenerator: (int counter) => { if (counter == 0) { return GetVotingAndRevealState(prompt, (prompt.UsersToDrawings.Values.Any(val => val == null)), votingTimer); } if (counter == 1) { if (lastRound) { return new ScoreBoardGameState(lobby, "Final Scores"); } else { return new ScoreBoardGameState(lobby); } } else { return null; } })); } }
public BattleReadyGameMode(Lobby lobby, List <ConfigureLobbyRequest.GameModeOptionRequest> gameModeOptions, StandardGameModeOptions standardOptions) { GameDuration duration = standardOptions.GameDuration; this.Lobby = lobby; int numRounds = BattleReadyConstants.NumRounds[duration]; int numPlayers = lobby.GetAllUsers().Count(); TimeSpan?setupDrawingTimer = null; TimeSpan?setupPromptTimer = null; TimeSpan?creationTimer = null; TimeSpan?votingTimer = null; int numOfEachPartInHand = (int)gameModeOptions[(int)GameModeOptionsEnum.NumEachPartInHand].ValueParsed; int numPromptsPerRound = Math.Min(numPlayers, BattleReadyConstants.MaxNumSubRounds[duration]); int minDrawingsRequired = numOfEachPartInHand * 3; // the amount to make one playerHand to give everyone int expectedPromptsPerUser = (int)Math.Ceiling(1.0 * numPromptsPerRound * numRounds / lobby.GetAllUsers().Count); int expectedDrawingsPerUser = Math.Max((minDrawingsRequired / numPlayers + 1) * 2, BattleReadyConstants.NumDrawingsPerPlayer[duration]); if (standardOptions.TimerEnabled) { setupDrawingTimer = BattleReadyConstants.SetupPerDrawingTimer[duration]; setupPromptTimer = BattleReadyConstants.SetupPerPromptTimer[duration]; creationTimer = BattleReadyConstants.PerCreationTimer[duration]; votingTimer = BattleReadyConstants.VotingTimer[duration]; } SetupDrawings_GS setupDrawing = new SetupDrawings_GS( lobby: lobby, drawings: this.Drawings, numExpectedPerUser: expectedDrawingsPerUser, setupDurration: setupDrawingTimer * expectedDrawingsPerUser); SetupPrompts_GS setupPrompt = new SetupPrompts_GS( lobby: lobby, prompts: Prompts, numExpectedPerUser: expectedPromptsPerUser, setupDuration: setupPromptTimer); List <Prompt> battlePrompts = new List <Prompt>(); IReadOnlyList <PeopleUserDrawing> headDrawings = new List <PeopleUserDrawing>(); IReadOnlyList <PeopleUserDrawing> bodyDrawings = new List <PeopleUserDrawing>(); IReadOnlyList <PeopleUserDrawing> legsDrawings = new List <PeopleUserDrawing>(); setupDrawing.AddExitListener(() => { // Trim extra prompts/drawings. headDrawings = Drawings.ToList().FindAll((drawing) => drawing.Type == BodyPartType.Head); bodyDrawings = Drawings.ToList().FindAll((drawing) => drawing.Type == BodyPartType.Body); legsDrawings = Drawings.ToList().FindAll((drawing) => drawing.Type == BodyPartType.Legs); }); int numPromptsPerUserPerRound = 0; // Set during below exit listener. setupPrompt.AddExitListener(() => { battlePrompts = MemberHelpers <Prompt> .Select_Ordered(Prompts.OrderBy(prompt => prompt.CreationTime).ToList(), numPromptsPerRound * numRounds); numRounds = (battlePrompts.Count - 1) / numPromptsPerRound + 1; numPromptsPerRound = (int)Math.Ceiling(1.0 * battlePrompts.Count / numRounds); numPromptsPerUserPerRound = Math.Max(1, numPromptsPerRound / 2); int maxNumUsersPerPrompt = Math.Min(12, (int)Math.Ceiling(1.0 * numPlayers * numPromptsPerUserPerRound / numPromptsPerRound)); foreach (Prompt prompt in battlePrompts) { prompt.MaxMemberCount = maxNumUsersPerPrompt; } }); List <GameState> creationGameStates = new List <GameState>(); List <GameState> votingGameStates = new List <GameState>(); List <GameState> voteRevealedGameStates = new List <GameState>(); List <GameState> scoreboardGameStates = new List <GameState>(); int countRounds = 0; #region GameState Generators GameState CreateContestantCreationGamestate() { RoundTracker.ResetRoundVariables(); List <Prompt> prompts = battlePrompts.Take(numPromptsPerRound).ToList(); battlePrompts.RemoveRange(0, prompts.Count); List <IGroup <User> > assignments = MemberHelpers <User> .Assign( prompts.Cast <IConstraints <User> >().ToList(), lobby.GetAllUsers().ToList(), duplicateMembers : (int)Math.Ceiling((1.0 * prompts.Count / numPromptsPerRound) * numPromptsPerUserPerRound)); var pairings = prompts.Zip(assignments); foreach ((Prompt prompt, IGroup <User> users) in pairings) { foreach (User user in users.Members) { prompt.UsersToUserHands.TryAdd(user, new Prompt.UserHand { // Users have even probabilities regardless of how many drawings they submitted. HeadChoices = MemberHelpers <PeopleUserDrawing> .Select_DynamicWeightedRandom(headDrawings, numOfEachPartInHand), BodyChoices = MemberHelpers <PeopleUserDrawing> .Select_DynamicWeightedRandom(bodyDrawings, numOfEachPartInHand), LegChoices = MemberHelpers <PeopleUserDrawing> .Select_DynamicWeightedRandom(legsDrawings, numOfEachPartInHand), Owner = user }); if (!RoundTracker.UsersToAssignedPrompts.ContainsKey(user)) { RoundTracker.UsersToAssignedPrompts.Add(user, new List <Prompt>()); } RoundTracker.UsersToAssignedPrompts[user].Add(prompt); } } GameState toReturn = new ContestantCreation_GS( lobby: lobby, roundTracker: RoundTracker, creationDuration: creationTimer); toReturn.Transition(CreateVotingGameStates(prompts)); return(toReturn); } Func <StateChain> CreateVotingGameStates(List <Prompt> roundPrompts) { return(() => { StateChain voting = new StateChain( stateGenerator: (int counter) => { if (counter < roundPrompts.Count) { Prompt roundPrompt = roundPrompts[counter]; return GetVotingAndRevealState(roundPrompt, votingTimer); } else { // Stops the chain. return null; } }); voting.Transition(CreateScoreGameState(roundPrompts)); return voting; }); } Func <GameState> CreateScoreGameState(List <Prompt> roundPrompts) { return(() => { List <Person> winnersPeople = roundPrompts.Select((prompt) => (Person)prompt.UsersToUserHands[prompt.Winner]).ToList(); countRounds++; GameState displayPeople = new DisplayPeople_GS( lobby: lobby, title: "Here are your winners", peopleList: winnersPeople, imageTitle: (person) => roundPrompts[winnersPeople.IndexOf(person)].Text, imageHeader: (person) => person.Name ); if (battlePrompts.Count <= 0) { GameState finalScoreBoard = new ScoreBoardGameState( lobby: lobby, title: "Final Scores"); displayPeople.Transition(finalScoreBoard); finalScoreBoard.Transition(this.Exit); } else { GameState scoreBoard = new ScoreBoardGameState( lobby: lobby); displayPeople.Transition(scoreBoard); scoreBoard.Transition(CreateContestantCreationGamestate); } return displayPeople; }); } #endregion this.Entrance.Transition(setupDrawing); setupDrawing.Transition(setupPrompt); setupPrompt.Transition(CreateContestantCreationGamestate); }