Commits

Alex Kulikoff  committed 0635b9b

пртестируй второй уровень в режиме тестирования

  • Participants
  • Parent commits 5a35d22

Comments (0)

Files changed (6)

File src/Banker/Banker.suo

Binary file modified.

File src/Banker/Banker/Form1.cs

         #region Глобальные переменные
         Stack<int> blockProc=new Stack<int>(); // стек содержащий индексы выполненых процессов
         Stack<int> blockRes = new Stack<int>();  // стек содержащий индексы ресурсов выполненых процессов
+        Stack<int> endStack = new Stack<int>(); 
 
         int proc = 0; // индекс процесса
         int res = 0; // индекса ресурса
             switch (level) 
             {
                 case 1:  do { proc = rnd.Next(1, 4); res = 1; } while (isBlock()&&!isOver()); label1.Text = "Процесс " + proc + " просит ресурс " + res; break;
-                case 2: do { proc = rnd.Next(1, 5); res = rnd.Next(1, 3); } while (isBlock() && !isOver()&&isBad()); label1.Text = "Процесс " + proc + " просит ресурс " + res; break;
+                case 2: do { proc = rnd.Next(1, 5); res = rnd.Next(1, 3); } while (isBad() && !isOver()); label1.Text = "Процесс " + proc + " просит ресурс " + res; break;
                 case 3: do { proc = rnd.Next(1, 6); res = rnd.Next(1, 4); } while (isBlock() && !isOver()); label1.Text = "Процесс " + proc + " просит ресурс " + res; break;
             }
             if (radioButton2.Checked) if (isExist()) label8.Text = "Дать"; else label8.Text = "Не дать";
         bool isBad()
         {
             if (isBlock()) return true;
-            int max1=0, max2=0, max3=0;
+            int max1=rnd.Next(0,4), max2=0, max3=0;
 
             switch(level){
                 case 2:
+                    //for (int j = 0; j < 4; j++)
+                    //{
+                    //    if (!isBlock(j + 1, 1)) if (max[0, j] - temp[0, j] < max[0, max1] - temp[0, max1]) max1 = j;
+                    //    if (!isBlock(j + 1, 2)) if (max[1, j] - temp[1, j] < max[1, max2] - temp[1, max2]) max2 = j;
+                    //}
+                    //if (res == 1) { if (proc == max1 + 1)return false; } else { if (proc == max2 + 1)return false; }
+                    //if (res == 1) { if (temp[0, proc - 1] + max[0, max1] >= max[0, proc - 1])return false; } else { if (temp[1, proc - 1] + max[1, max2] >= max[1, proc - 1])return false; }
+
                     for (int j = 0; j < 4; j++)
                     {
-                        if (!isBlock(j + 1, 1)) if (max[0, j] - temp[0, j] < max[0, max1] - temp[0, max1]) max1 = j;
-                        if (!isBlock(j + 1, 2)) if (max[1, j] - temp[1, j] < max[1, max2] - temp[1, max2]) max2 = j;
+                      if(!endStack.Contains(j))  if (max[0, j] - temp[0, j] <= max[0, max1] - temp[0, max1]&&max[1, j] - temp[1, j] <= max[1, max1] - temp[1, max1])  max1 = j;
+                         
                     }
-                    if (res == 1) { if (proc == max1 + 1)return false; } else { if (proc == max2 + 1)return false; }
-                    if (res == 1) { if (temp[0, proc - 1] + max[0, max1] >= max[0, proc - 1])return false; } else { if (temp[1, proc - 1] + max[1, max2] >= max[1, proc - 1])return false; }
+                    if (proc - 1 == max1 || (temp[0, proc - 1] + max[0, max1]+1 >= max[0, proc - 1]) && (temp[1, proc - 1] + max[1, max1] >= max[1, proc - 1])) return false;
                     break;
         }
                 return true;
             switch (level)
             {
                 case 1: if (max[0, 0] == 0 && max[0, 1] == 0 && max[0, 2] == 0) return true; break;
-                case 2: if (max[0, 0] == 0 && max[0, 1] == 0 && max[0, 2] == 0 && max[1, 0] == 0 && max[1, 1] == 0 && max[1, 2] == 0 && max[0, 3] == 0 && max[1, 3] == 0) { max[0, 0] = 1; unblck(); reSet(); return true; } break;
+                case 2: if (max[0, 0] == 0 && max[0, 1] == 0 && max[0, 2] == 0 && max[1, 0] == 0 && max[1, 1] == 0 && max[1, 2] == 0 && max[0, 3] == 0 && max[1, 3] == 0) {  unblck(); reSet(); return true; } break;
                 case 3: return true; break;
 
             }
                 rezerv[res - 1] -= 1;
                 temp[res - 1, proc - 1] += 1;
                 cmp();
-                if(isOver()) {  MessageBox.Show(level +" уровень закончен"); }
+                if(isOver())
+                {  MessageBox.Show(level +" уровень закончен"); }
                 reSet();
                 if (isOver()) if (radioButton1.Checked) nextLevel(); else { unblck(); }
             }
                 temp = new int[3, 5] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
                 max=cur.t;
                 cur.m.CopyTo(rezerv, 0);
-                blockProc.Clear(); blockRes.Clear();
+                blockProc.Clear(); blockRes.Clear(); endStack.Clear();
                 reSet();
             }
             genQ();
                 temp = new int[3, 5] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
                 copy(max, cur.t);
                 cur.m.CopyTo(rezerv, 0);
-                blockProc.Clear(); blockRes.Clear();
+                blockProc.Clear(); blockRes.Clear(); endStack.Clear();
                 reSet();
             }
             genQ();
         {
             switch (level) 
             {
-                case 1: level2(var2[rnd.Next(9)]); level += 1; break;
-                case 2: level3(var3[rnd.Next(9)]); level+=1; break;
+                case 1: level += 1; level2(var2[rnd.Next(9)]); break;
+                case 2: level += 1; level3(var3[rnd.Next(9)]); break;
                 case 3: genOut(); break;
             }
         }
                             rezerv[1] += max[1, j];
                             temp[0, j] = max[0, j] = temp[1, j] = max[1, j] = 0;
                             reSet();
+                            endStack.Push(j);
 
                         }
                     }

File src/Banker/Banker/bin/Debug/Banker.exe

Binary file modified.

File src/Banker/Banker/bin/Debug/Banker.pdb

Binary file modified.

File src/Banker/Banker/obj/x86/Debug/Banker.exe

Binary file modified.

File src/Banker/Banker/obj/x86/Debug/Banker.pdb

Binary file modified.