Exemplo n.º 1
0
        private static HashSet <Player> PickATeam(GameModel model, Player player)
        {
            LogicalModel <Player> logicalModel =
                new LogicalModel <Player>(
                    new HashSet <Player>(model.Players),
                    GameRules.GetGoodCount(model.Players.Length));

            logicalModel.FilterContainsElement(player);

            foreach (Mission mission in model.Missions)
            {
                if (mission != null && mission.MissionResult == MissionResult.Fail)
                {
                    logicalModel.AddDirtySet(mission.Team);
                }
            }
            //Mission[] reverseMissions = model.Missions.Reverse()
            foreach (Mission mission in model.Missions)
            {
                if (mission != null && mission.MissionResult == MissionResult.Succeed &&
                    !model.Missions.Any(ms => ms != null && ms.MissionResult == MissionResult.Fail &&
                                        mission.Team.IsProperSubsetOf(ms.Team)) &&
                    logicalModel.PossibleTeams.Any(pt => mission.Team.IsSubsetOf(pt)))
                {
                    logicalModel.AddCleanSet(mission.Team);
                }
            }

            HashSet <Player> pickedTeam =
                Utilities.PickRandom(logicalModel.PossibleTeams);

            return(pickedTeam);
        }
Exemplo n.º 2
0
        public static PickTeamCommand GeneratePickTeamCommand(GameModel model, Player leader)
        {
            if (model.GamePhase != GamePhase.TeamPicking)
            {
                throw new GamePhaseException();
            }
            if (model.CurrentLeader != leader)
            {
                throw new NotLeaderException();
            }
            HashSet <Player> pickedTeam = PickATeam(model, leader);

            LogicalModel <Player> logicalModel = new LogicalModel <Player>(pickedTeam, model.CurrentTeamLength);

            HashSet <Player> finalTeam =
                Utilities.PickRandom(logicalModel.PossibleTeams);

            HashSet <int> finalTeamIds = new HashSet <int>(finalTeam.Select(plr => plr.Id));

            PickTeamCommand command = new PickTeamCommand(leader.Id, finalTeamIds, model.Players.Length);

            return(command);
        }