예제 #1
0
파일: QuestSheet.cs 프로젝트: nauhtnn/sQz
        public static List <int[]> DBCountItemGroupByModule(Level lv)
        {
            IUx[] IUs_by_Lv        = MultiChoiceItem.GetIUs(lv);
            int[] n_difficultItems = new int[IUs_by_Lv.Length];
            int[] n_allItems       = new int[IUs_by_Lv.Length];
            int   j = -1;

            foreach (IUx i in IUs_by_Lv)
            {
                n_allItems[++j] = DBConnect.Count("sqz_question", "id",
                                                  "moid=" + (int)i + " AND del=0");
                if (n_allItems[j] < 0)
                {
                    n_allItems[++j] = 0;
                }
                n_difficultItems[j] = DBConnect.Count("sqz_question", "id",
                                                      "moid=" + (int)i + " AND diff=1 AND del=0");
                if (n_difficultItems[j] < 0)
                {
                    n_difficultItems[j] = 0;
                }
            }
            List <int[]> n = new List <int[]>();

            n.Add(n_allItems);
            n.Add(n_difficultItems);
            return(n);
        }
예제 #2
0
        public MultiChoiceItem RandomizeDeepCopy(Random rand)
        {
            MultiChoiceItem q = new MultiChoiceItem();

            q.ID_in_DB    = ID_in_DB;
            q.Stem        = Stem;
            q.mIU         = mIU;
            q.IsDifficult = IsDifficult;
            //randomize
            q.Options = new NonnullRichText[N_OPTIONS];
            q.Keys    = new bool[N_OPTIONS];
            List <int> l = new List <int>();

            for (int i = 0; i < N_OPTIONS; ++i)
            {
                l.Add(i);
            }
            int n = N_OPTIONS;

            while (0 < n)
            {
                int lidx = rand.Next() % n;
                int idx  = l[lidx];
                l.RemoveAt(lidx);
                --n;
                q.Options[n]         = Options[idx];
                q.Keys[n]            = Keys[idx];
                q.PermutedOptions[n] = idx;
            }
            return(q);
        }
예제 #3
0
파일: QuestSheet.cs 프로젝트: nauhtnn/sQz
        void ParseQueue(Queue <NonnullRichTextBuilder> richTexts)
        {
            Questions.Clear();
            int stride = 1 + MultiChoiceItem.N_OPTIONS;

            while (richTexts.Count > 0)
            {
                Questions.Add(MultiChoiceItem.NewWith(richTexts));
            }
        }
예제 #4
0
        public static MultiChoiceItemView NewWith(MultiChoiceItem model, int idx, double idxHeight, double questionWidth, StackPanel UI_Container)
        {
            MultiChoiceItemView question = new MultiChoiceItemView();

            question.Model         = model;
            question.Idx           = idx;
            question.IdxHeight     = idxHeight;
            question.QuestionWidth = questionWidth;
            question.UI_Container  = UI_Container;
            return(question);
        }
예제 #5
0
        public List <QuestSheet> GenQPack3(int n, int[] vn, int[] vndiff)
        {
            //string emsg;
            Random            rand = new Random();
            List <QuestSheet> l    = new List <QuestSheet>();
            QuestSheet        qs0  = new QuestSheet();
            //qs0.bAlt = bAlt;
            int j = -1;

            foreach (IUx i in MultiChoiceItem.GetIUs(Lv))
            {
                ++j;
                if (qs0.DBSelect(rand, i, vn[j] - vndiff[j], Difficulty.Easy))
                {
                    //WPopup.s.ShowDialog(emsg);
                    return(new List <QuestSheet>());
                }
                if (qs0.DBSelect(rand, i, vndiff[j], Difficulty.Difficult))
                {
                    //WPopup.s.ShowDialog(emsg);
                    return(new List <QuestSheet>());
                }
            }
            while (0 < n)
            {
                --n;
                QuestSheet qs = qs0.RandomizeDeepCopy(rand);
                qs.Lv = Lv;
                if (!qs.UpdateCurQSId())//todo: better error handle
                {
                    Sheets.Add(qs.uId, qs);
                    l.Add(qs);
                }
            }
            if (DBIns(mDt, l) == null)
            {
                return(l);
            }
            return(new List <QuestSheet>());
        }
예제 #6
0
파일: QuestSheet.cs 프로젝트: nauhtnn/sQz
        public List <int[]> CountItemGroupByModule()
        {
            IUx[] IUs_by_Lv        = MultiChoiceItem.GetIUs(Lv);
            int[] n_difficultItems = new int[IUs_by_Lv.Length];
            int[] n_allItems       = new int[IUs_by_Lv.Length];
            foreach (MultiChoiceItem i in Questions)
            {
                int module;
                switch (i.mIU)
                {
                case IUx._7:
                    module = 0;
                    break;

                case IUx._8:
                    module = 1;
                    break;

                case IUx._9:
                    module = 2;
                    break;

                default:
                    module = (int)i.mIU;
                    break;
                }
                ++n_allItems[module];
                if (i.IsDifficult)
                {
                    ++n_difficultItems[module];
                }
            }
            List <int[]> n = new List <int[]>();

            n.Add(n_allItems);
            n.Add(n_difficultItems);
            return(n);
        }
예제 #7
0
        public MultiChoiceItem DeepCopy()
        {
            MultiChoiceItem q = new MultiChoiceItem();

            q.ID_in_DB = ID_in_DB;
            q.Stem     = Stem;
            q.mIU      = mIU;
            q.Options  = new NonnullRichText[N_OPTIONS];
            for (int i = 0; i < N_OPTIONS; ++i)
            {
                q.Options[i] = Options[i];
            }
            q.Keys = new bool[N_OPTIONS];
            for (int i = 0; i < N_OPTIONS; ++i)
            {
                q.Keys[i] = Keys[i];
            }
            q.PermutedOptions = new int[N_OPTIONS];
            for (int i = 0; i < N_OPTIONS; ++i)
            {
                q.PermutedOptions[i] = PermutedOptions[i];
            }
            return(q);
        }
예제 #8
0
        public List <QuestSheet> Genegrate2(int n, int[] vn, int[] vndiff)
        {
            List <QuestSheet> l = new List <QuestSheet>();
            int i;

            for (i = 0; i < n; ++i)
            {
                l.Add(new QuestSheet());
            }
            //foreach (QuestSheet qs in l)
            //    qs.bAlt = bAlt;
            i = 0;
            Random rand = new Random();

            foreach (IUx iu in MultiChoiceItem.GetIUs(Lv))
            {
                //
                QuestSheet qs0 = new QuestSheet();
                //qs0.bAlt = bAlt;
                qs0.DBSelect(iu, Difficulty.Easy);
                //
                foreach (QuestSheet qs in l)
                {
                    List <MultiChoiceItem> vq = qs0.ShallowCopy();
                    int ni = vn[i] - vndiff[i];
                    while (0 < ni)
                    {
                        int idx = rand.Next() % ni;
                        qs.Add(vq.ElementAt(idx).DeepCopy());
                        vq.RemoveAt(idx);
                        --ni;
                    }
                }
                //
                qs0 = new QuestSheet();
                //qs0.bAlt = bAlt;
                qs0.DBSelect(iu, Difficulty.Difficult);
                //
                foreach (QuestSheet qs in l)
                {
                    List <MultiChoiceItem> vq = qs0.ShallowCopy();
                    int ni = vndiff[i];
                    while (0 < ni)
                    {
                        int idx = rand.Next() % ni;
                        qs.Add(vq.ElementAt(idx).DeepCopy());
                        vq.RemoveAt(idx);
                        --ni;
                    }
                }
                //
                ++i;
            }
            List <int> eidx = new List <int>();

            i = -1;
            foreach (QuestSheet qs in l)
            {
                qs.Lv = Lv;
                qs.Randomize(rand);
                if (!qs.UpdateCurQSId())//todo: better error handle
                {
                    Sheets.Add(qs.uId, qs);
                }
                else
                {
                    eidx.Add(++i);
                }
            }
            foreach (int idx in eidx)
            {
                l.RemoveAt(idx);
            }

            if (DBIns(mDt, l) == null)
            {
                return(l);
            }
            return(new List <QuestSheet>());
        }
예제 #9
0
파일: QuestSheet.cs 프로젝트: nauhtnn/sQz
 public void Add(MultiChoiceItem q)
 {
     Questions.Add(q);
 }
예제 #10
0
        //static int ReadNOptions()
        //{
        //    //if (System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory() + "\\3.txt"))
        //    //    return 3;
        //    return 4;
        //}

        public static MultiChoiceItem NewWith(Queue <NonnullRichTextBuilder> richTexts)
        {
            MultiChoiceItem question   = new MultiChoiceItem();
            MultiChoiceData questTexts = new MultiChoiceData(richTexts, N_OPTIONS);
            string          stem       = questTexts.Stem.FirstStringOrDefault();

            if (stem[0] == '*')
            {
                question.IsDifficult = true;
                questTexts.Stem.Trunc1AtLeft();
            }
            else if (1 < stem.Length && stem[0] == '\\' &&
                     (stem[1] == '*' || stem[1] == '\\'))
            {
                question.IsDifficult = false;
                questTexts.Stem.Trunc1AtLeft();
            }
            else
            {
                question.IsDifficult = false;
            }
            question.Stem = new NonnullRichText(questTexts.Stem);

            question.Options         = new NonnullRichText[N_OPTIONS];
            question.Keys            = new bool[N_OPTIONS];
            question.PermutedOptions = new int[N_OPTIONS];
            for (int i = 0; i < N_OPTIONS; ++i)
            {
                string isKey = questTexts.Options[i].FirstStringOrDefault();
                if (isKey == null)
                {
                    question.Keys[i] = false;
                }
                else if (isKey[0] == '\\')
                {
                    if (isKey.Length == 1)
                    {
                        if (questTexts.Options[i].Runs.Count == 1)
                        {
                            question.Keys[i] = false;
                        }
                        else
                        {
                            question.Keys[i] = true;
                            questTexts.Options[i].Runs.RemoveAt(0);
                        }
                    }
                    else
                    {
                        if (isKey[1] != '\\')
                        {
                            question.Keys[i] = true;
                        }
                        else
                        {
                            question.Keys[i] = false;
                        }
                        questTexts.Options[i].Trunc1AtLeft();
                    }
                }
                else
                {
                    question.Keys[i] = false;
                }
                question.Options[i] = new NonnullRichText(questTexts.Options[i]);

                question.PermutedOptions[i] = i;
            }
            bool noAnswer = true;

            for (int i = 0; i < N_OPTIONS; ++i)
            {
                if (question.Keys[i])
                {
                    noAnswer = false;
                }
            }
            if (noAnswer)
            {
                throw new ArgumentNullException();
            }
            return(question);
        }