Exemple #1
0
        /// <summary>
        /// 重複ありで全体の抽選を行う関数
        /// </summary>
        async public Task playWithDuplicate()
        {
            // ホワイトリストが存在する場合、ホワイトリストだけの抽選を先に行う
            if (this.white.Count > 0)
            {
                // ホワイトグループのデータ数と当選対象者数を比較する
                if (this.sumTotal <= this.white.Count)
                {
                    // ホワイトグループの人数が当選対象者数以上の場合、当選対象者をホワイトグループに限定して抽選する
                    this.all = this.white;
                }
                else
                {
                    // ホワイトグループの人数が当選対象者数より少ない場合、等級別に当選者を配分する
                    this.white.shuffleItems();
                    playWhiteFirst();
                }
            }

            // 応募対象者のリスト要素をシャッフルする
            this.all.shuffleItems();

            // 応募者全員に対する抽選処理
            Random random = new Random();

            foreach (Group group in this.winners)
            {
                int defaultNum = group.Count; // 等級別のグループリストの要素数を取得する

                // すべての応募者が格納されているリストを臨時のリストにコピーする(allの再利用のため)
                List <Applicant> tempAll = new List <Applicant>(this.all);

                // 既に各等級グループに当選者がいる場合、同じ等級内での重複は禁止するために抽選対象の応募者全員から事前に除く
                if (defaultNum > 0)
                {
                    for (int i = 0; i < defaultNum; i++)
                    {
                        tempAll.RemoveAll(el => el.number.Equals(group[i].number));
                    }
                }

                // 抽選人数分抽選処理を繰り返す
                for (int i = 0; i < group.number - defaultNum; i++)
                {
                    int       index     = random.Next(0, tempAll.Count);
                    Applicant applicant = tempAll[index];
                    group.Add(applicant);

                    // 重複不可の場合、抽選された結果をすべての応募者の配列から削除していく
                    tempAll.Remove(applicant);
                }

                // 当選リストの整列(応募者番号の昇順)
                group.Sort();

                // リストビューに結果を表示するための処理
                group.listView.Enabled = true;
                foreach (Applicant applicant in group)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = applicant.number;
                    item.SubItems.Add(applicant.name);
                    group.listView.Items.Add(item);
                }

                // 演出のために各等級別の処理に時間差を置く
                await Task.Delay(500);
            }
        }
Exemple #2
0
        /// <summary>
        /// 重複なしで全体の抽選を行う関数
        /// </summary>
        async public Task playWithoutDuplicate()
        {
            // ホワイトリストが存在する場合、ホワイトリストだけの抽選を先に行う
            if (this.white.Count > 0)
            {
                // ホワイトリストの抽選は別で行うため、全体から除く
                foreach (Applicant applicant in this.white)
                {
                    this.all.RemoveAll(el => el.number.Equals(applicant.number));
                }

                // ホワイトグループのデータ数と当選対象者数を比較する
                if (this.sumTotal <= this.white.Count)
                {
                    // ホワイトグループの人数が当選対象者数以上の場合、当選対象者をホワイトグループに限定して抽選する
                    this.all = this.white;
                }
                else
                {
                    // ホワイトグループの人数が当選対象者数より少ない場合、等級別に当選者を配分する
                    this.white.shuffleItems();
                    playWhiteFirst();
                }
            }

            this.all.shuffleItems();

            // 応募者全員に対する抽選処理
            Random random = new Random();

            int defaultNum;

            foreach (Group group in this.winners)
            {
                defaultNum = group.Count; // 等級別のグループリストの要素数を取得する

                // 抽選人数分抽選処理を繰り返す
                for (int i = 0; i < group.number - defaultNum; i++)
                {
                    int       index     = random.Next(0, this.all.Count);
                    Applicant applicant = this.all[index];
                    group.Add(applicant);

                    // 重複不可の場合、抽選された結果をすべての応募者の配列から削除していく
                    this.all.Remove(applicant);
                }

                // 当選リストの整列(応募者番号の昇順)
                group.Sort();

                // リストビューに結果を表示するための処理
                group.listView.Enabled = true;
                foreach (Applicant applicant in group)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = applicant.number;
                    item.SubItems.Add(applicant.name);
                    group.listView.Items.Add(item);
                }

                // 演出のために各等級別の処理に時間差を置く
                await Task.Delay(500);
            }
        }