public Operations[] Solve(int n, int startX, int startY, int[] numbers, int targetX, int targetY, int value) { this.n = n; this.grid = new Dictionary <int, CubeState> [n, n]; CubeState currentCubeState = new CubeState(numbers, startX, startY, 0, Operations.Stop, null); pushState(currentCubeState); CubeState[] newCubeStates; Queue <CubeState> queue = new Queue <CubeState>(); queue.Enqueue(currentCubeState); while (queue.Count > 0) { currentCubeState = queue.Dequeue(); if (currentCubeState.X == targetX && currentCubeState.Y == targetY && currentCubeState.Numbers[CubeState.BACK] == value) { return(this.MakePath(currentCubeState)); } newCubeStates = new CubeState[4] { currentCubeState.Up(), currentCubeState.Down(), currentCubeState.Left(), currentCubeState.Right() }; foreach (CubeState newCubeState in newCubeStates) { if (newCubeState.Check(n) && this.CheckState(newCubeState)) { pushState(newCubeState); queue.Enqueue(newCubeState); } } } return(null); }
public CubeState(int[] numbers, int x, int y, int distance, Operations operation, CubeState previous) { this.Numbers = (int[])numbers.Clone(); this.X = x; this.Y = y; this.Distance = distance; this.Operation = operation; this.Previous = previous; }