CheckIfSafe(0, null, missionaries, cannibals, boat));
It tells me that the array index was out of bounds. I don't see how that's possible.
int missionaries = NUMBER_OF_MISSIONARIES;
int cannibals = NUMBER_OF_CANNIBALS;
int boat = ON_THIS_SIDE;
/// Node array to keep track of different states, and
/// the Queue that helps solve the problem.
private static Node[, ,] states = new Node
[NUMBER_OF_MISSIONARIES + 1,
NUMBER_OF_CANNIBALS + 1,
private static Queue queue = new Queue();
/// NOT MAGIC NUMBERS!!
private static readonly bool SAFE = true;
private static readonly bool NOT_SAFE = false;
private static readonly int ON_THIS_SIDE = 0;
private static readonly int ON_OTHER_SIDE = 1;
private static readonly int NUMBER_OF_MISSIONARIES = 3;
private static readonly int NUMBER_OF_CANNIBALS = 3;
private static readonly int NUMBER_OF_SHORES = 2;
private static Node CheckIfSafe(int l, Node b, int m, int c, int boat)
bool isSafe = SAFE;
if ((c > m && m != 0) || ((NUMBER_OF_CANNIBALS - c)
> (NUMBER_OF_MISSIONARIES - m)
&& m!=NUMBER_OF_MISSIONARIES)) isSafe = NOT_SAFE;
string toString = "" + m;
toString += c;
if (boat == ON_THIS_SIDE) toString += "b";
toString += "|" + (NUMBER_OF_MISSIONARIES - m);
toString += (NUMBER_OF_CANNIBALS - c);
if (boat == ON_OTHER_SIDE) toString += "b";
return new Node(l, b, isSafe, toString);
I made the array bigger but I'm still getting the exception. WTF?! HELP!
I don't think anyone quite understands how much I appreciate my brother. Thanks, Alex!