public void InteractiveSolveForMoreThanNine(int target) { var gridLength = target / 3; if (target % 3 != 0) { gridLength++; } Grid = new bool[gridLength, 3]; GopherResult result = GopherResult.error; //Force the loop to run at least once. int currentCentreStrip = 2; int currentLeftStrip = currentCentreStrip - 1; int leftStripCount = 0; Tuple <int, int> currentTarget = Tuple.Create(currentCentreStrip, 2); while (result != GopherResult.complete) { var output = SendAndReceive(currentTarget); result = output.Item2; var hit = output.Item1; if (result == GopherResult.repeatTarget) { continue; } if (result == GopherResult.complete) { continue; } if (result == GopherResult.newTarget) { if (hit.Item1 == currentLeftStrip) { leftStripCount++; while (leftStripCount == 3 && currentCentreStrip < gridLength - 1) //stop stepping forwards when either (there's a left hand cell to fill) or (we've reached the right hand limit of the grid) { currentCentreStrip++; currentLeftStrip++; currentTarget = Tuple.Create(currentCentreStrip, 2); leftStripCount = (GetGridBool(currentLeftStrip, 1) ? 1 : 0) + (GetGridBool(currentLeftStrip, 2) ? 1 : 0) + (GetGridBool(currentLeftStrip, 3) ? 1 : 0); } } } if (testMode) { var isComplete = (GridCount == 3 * gridLength); result = isComplete ? GopherResult.complete : result; } } }
public void InteractiveSolveForLessThanNine() { Grid = new bool[3, 3]; GopherResult result = GopherResult.error; //Force the loop to run at least once. while (result != GopherResult.complete) { result = SendAndReceive(initialTarget).Item2; if (testMode && GridCount >= 9) { result = GopherResult.complete; } } }