Beispiel #1
0
        /// <summary>
        /// プレイヤーのピック条件
        /// </summary>
        /// <param name="selection"></param>
        /// <returns></returns>
        public static IPlayerSelect getPicker(this SelectionPatternEnum selection)
        {
            switch (selection)
            {
            case SelectionPatternEnum.RandomCall:
            case SelectionPatternEnum.DefaultCall:
                return(new DefaultPick());

            case SelectionPatternEnum.MixCall:
                return(new MixPick());

            default: return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// プレイヤーの組み合わせ条件
        /// </summary>
        /// <param name="selection"></param>
        /// <returns></returns>
        public static IPairSelect getSelecter(this SelectionPatternEnum selection)
        {
            switch (selection)
            {
            case SelectionPatternEnum.RandomCall:
                return(new RandomPairSelect());

            case SelectionPatternEnum.DefaultCall:
                return(new DefaultPairSelect());

            case SelectionPatternEnum.MixCall:
                return(new MixCall());

            default: return(null);
            }
        }
Beispiel #3
0
        public SkillResponse2 callNextGame(ILambdaContext context, string uid, SelectionPatternEnum pattern)
        {
            Random rnd = new Random(DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second);

            // ***** データ読み込み *****
            this.loadPracticeData(out Practices practice, out List <Results> resultList, out List <Users> userList);

            // 全ゲームに参加したユーザー情報(回数カウント用)
            List <int>     gamePlayerLog = new List <int>();
            List <int>     lastGameUser  = new List <int>();
            List <Results> lastGames     = new List <Results>();

            if (resultList.Any())
            {
                int maxMatchId = resultList.Select(r => r.match_id).Max();
                foreach (var r in resultList.OrderByDescending(r => r.match_id))
                {
                    gamePlayerLog.Add(r.user1);
                    gamePlayerLog.Add(r.user2);
                    if (r.match_id == maxMatchId)
                    {
                        lastGameUser.Add(r.user1);
                        lastGameUser.Add(r.user2);
                        lastGames.Add(r);
                    }
                }
                ;
            }
            // 各ユーザーにランダム値と試合率、直前の試合有無を設定
            userList.ForEach(user => {
                user.randomInt       = rnd.Next(9999999);
                user.playPercentage  = (user.count ?? 0) == 0 ? 1 : gamePlayerLog.Count(obj => obj == user.id) / (decimal)user.count;
                user.ContinuousCount = lastGameUser.Count(obj => obj == user.id);
            });

            // コート数取得。最大3コート
            int coatCount = getCoat(userList);

            // 次ゲームの参加者決め
            List <Users> gamePlayers = pattern.getPicker().playerSelect(userList, resultList, coatCount);

            List <Results> addMatchesAndResults;
            bool           decision;

            do
            {
                decision = false;
                // 各ユーザーのランダム値更新
                gamePlayers.ForEach(user => { user.randomInt = rnd.Next(9999999); });
                // ペア決め
                addMatchesAndResults = pattern.getSelecter().getPairList(gamePlayers, resultList, coatCount);
                addMatchesAndResults.ForEach(r => decision = decision || lastGames.Select(l => l.pairCheckStr).Contains(r.pairCheckStr));
            } while (decision);

            // DB更新
            this.saveData(addMatchesAndResults, gamePlayers, practice, userList);

            (string msg, SimpleCard card)msgCard = createAlexaResponse(addMatchesAndResults, gamePlayers);
            SkillResponse2 skillResponse = new SkillResponse2();

            skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech()
            {
                Text = msgCard.msg
            };
            skillResponse.Response.Card             = msgCard.card;
            skillResponse.Response.ShouldEndSession = null;

            return(skillResponse);
        }