Commits

Alex Kulikoff committed 5a35d22

Во-втором уровне замени isBloc() на isBad() отладь изБэд и протестируй

  • Participants
  • Parent commits 296d5ee

Comments (0)

Files changed (6)

File src/Banker/Banker.suo

Binary file modified.

File src/Banker/Banker/Form1.cs

             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, 3); 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 (isBlock() && !isOver()&&isBad()); 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()
         {
-            return isBlock();
+            if (isBlock()) return true;
+            int max1=0, 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; }
+                    break;
+        }
+                return true;
         }
 
         bool isOver()
             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) 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 3: return true; break;
 
             }
             else 
             {
                 MessageBox.Show("Ресурс не выделен");
-                temp = new int[3, 5] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } }; 
-                switch (level)
-                {
-                    case 1: cur.m.CopyTo(rezerv,0); break;
-                    case 2: cur.m.CopyTo(rezerv, 0); break;
-                    case 3: cur.m.CopyTo(rezerv, 0); break;
-                }
+                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();
                 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();
                 reSet();
             }
             genQ();

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.