public static void Main()
for (int j = 1; j < 1001; j++)
for (int i = 1; i < 101; i++)
Prisoner prisonerRand = new(i, false, 50);
if (prisonerRand.Search(room.Boxes))
Prisoner prisonerLoop = new(i, true, 50);
if (!prisonerLoop.Search(room.Boxes))
Console.WriteLine($"Random strategy: {randWinTotal / randCycles}");
Console.WriteLine($"Loop strategy: {loopWinTotal / loopCycles}");
public Room(int weight = 100)
for(int i = 0; i < Boxes.Length; i++)
for (int i = Boxes.Length - 1; i >= 1; i--)
int j = rand.Next(i + 1);
public int AtteptsAmount;
public int PrisonerNumber;
public Prisoner(int prisonerNumber, bool loopSearch = true, int atteptsNum = 50)
AtteptsAmount = atteptsNum;
PrisonerNumber = prisonerNumber;
public bool Search(int[] boxes)
int[] WathedBoxes = boxes.ToArray();
for(int i = 0; i < this.AtteptsAmount; i++)
selectedBox = rand.Next(1, boxes.Length);
if (WathedBoxes[selectedBox - 1] == -1)
if (this.PrisonerNumber != boxes[selectedBox - 1])
WathedBoxes[selectedBox - 1] = -1;
int firstBox = PrisonerNumber;
if (boxes[firstBox - 1] == PrisonerNumber)
nextBox = boxes[firstBox - 1];
for (int i = 0; i < this.AtteptsAmount; i++)
if (boxes[nextBox - 1] == PrisonerNumber)
nextBox = boxes[nextBox - 1];