static void MoveHoleWithoutMovingBall(int x3, int y3, int ux, int uy, int[,] m, COOR[,] c, int step, COOR prevCoor) { m[ux, uy] = step; c[ux, uy] = prevCoor; COOR actCoor = new COOR(); actCoor.x = ux; actCoor.y = uy; if (m[ux + 1, uy] > step + 1) { MoveHoleWithoutMovingBall(x3, y3, ux + 1, uy, m, c, step + 1, actCoor); } if (m[ux - 1, uy] > step + 1) { MoveHoleWithoutMovingBall(x3, y3, ux - 1, uy, m, c, step + 1, actCoor); } if (m[ux, uy + 1] > step + 1) { MoveHoleWithoutMovingBall(x3, y3, ux, uy + 1, m, c, step + 1, actCoor); } if (m[ux, uy - 1] > step + 1) { MoveHoleWithoutMovingBall(x3, y3, ux, uy - 1, m, c, step + 1, actCoor); } }
static void MoveHoleWithoutMovingBall(int x1, int y1, int x2, int y2, int ux, int uy, int x3, int y3) { int[,] m = new int[11, 11]; COOR[,] c = new COOR[11, 11]; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { m[i, j] = Int32.MaxValue; } } m[x1, y1] = -1; for (int i = 0; i <= 10; i++) { m[0, i] = -1; m[10, i] = -1; m[i, 0] = -1; m[i, 10] = -1; } MoveHoleWithoutMovingBall(x3, y3, ux, uy, m, c, 0, null); List <COOR> path = new List <COOR>(); COOR q = c[x3, y3]; while (q != null) { path.Add(q); q = c[q.x, q.y]; } for (int i = path.Count - 2; i >= 0; i--) { PrintState(x1, y1, x2, y2, path[i].x, path[i].y); } PrintState(x1, y1, x2, y2, x3, y3); }