private void CalculatePuzzleBounds() { for (int i = PuzzleSize - 1; i < PuzzleEndState.Count; i += PuzzleSize) { RightList.Add(i); } for (int i = 0; i < PuzzleEndState.Count; i += PuzzleSize) { LeftList.Add(i); } for (int i = 0; i < PuzzleSize; i++) { UpList.Add(i); } for (int i = PuzzleEndState.Count - PuzzleSize; i < PuzzleEndState.Count; i++) { DownList.Add(i); } }
private Node Up(Node fromNode) { Node UpOfNode = new Node() { ParentNode = fromNode, Direction = Direction.Up, Length = fromNode.Length + 1, State = NodeState.Untested }; List <int> CurrentPuzzleState = fromNode.PuzzleState.ToList(); int Location = 0; int WhitePuzzlePieceLocation = new int(); int UpOfWhitePuzzlePieceLocation = new int(); foreach (int item in CurrentPuzzleState) { if (item == MoveablePiece) { WhitePuzzlePieceLocation = Location; UpOfWhitePuzzlePieceLocation = Location - PuzzleSize; } Location++; } if (!UpList.Contains(WhitePuzzlePieceLocation)) { CurrentPuzzleState = SwapLocation(CurrentPuzzleState, WhitePuzzlePieceLocation, UpOfWhitePuzzlePieceLocation); UpOfNode = SetNodeInfo(UpOfNode, CurrentPuzzleState); // Debug.WriteLine("Up"); } else { UpOfNode.IsMoveable = false; UpOfNode.State = NodeState.Closed; } if (CheckCompletion(CurrentPuzzleState) == true) { UpOfNode.Direction = Direction.None; EndingNode = UpOfNode; } return(UpOfNode); }