private void SetBoardStatus(PathManager manager, SquarePathStatus status) { for (int i = 0; i < manager.Path.Count; i++) { this.currentSquareBoard[manager.Path[i].X, manager.Path[i].Y].PathStatus = status; } }
private void SelectTreeNode(PathManager selectedManager) { SquarePathStatus status = SquarePathStatus.PATH; if (selectedManager.PathStatus == SquarePathStatus.CORRECT) { status = SquarePathStatus.CORRECT; } else if (selectedManager.PathStatus == SquarePathStatus.WRONG) { status = SquarePathStatus.WRONG; } PathManager tmpPathManager = selectedManager; while (prevPathManager != null) { SetBoardStatus(prevPathManager, SquarePathStatus.NONE); prevPathManager = prevPathManager.ParentPathManager; } while (selectedManager != null) { SetBoardStatus(selectedManager, status); selectedManager = selectedManager.ParentPathManager; } prevPathManager = tmpPathManager; this.Refresh(); }
public void ResetSquare() { // set type to square this.innerType_ = SquareType.SQUARE; // set square to empty this.innerStatus_ = SquareStatus.EMPTY; // no path information this.innerPathStatus_ = SquarePathStatus.NONE; // also no owners this.Owners.Clear(); }
public PathManager(PathManager parentPathManager, int subIndex, Square startPoint, Square sourceSquare, Square targetSquare, SquareBoard board, bool isRoot) { // assign square board this.innerBoard_ = board; // which square this manager starts? this.startPointSquare_ = startPoint; // is this a root manager? this.isRoot_ = isRoot; // parent manager of this manager this.parentPathManager_ = parentPathManager; // total cost of this manager if we decide to take it this.totalCost_ = 0; this.innerThreadCount_ = 0; this.totalSolutions_ = 0; this.innerPathSquares_ = new SquareCollection(); // sub mangers collections this.subPathManagers_ = new PathManagerCollection(); this.innerSolutions_ = new PathManagerCollection(); // which path are we looking for a solution? this.sourceSquare_ = sourceSquare; this.targetSquare_ = targetSquare; this.endPointSquare_ = null; this.pathStatus_ = SquarePathStatus.PATH; // assign a unique name to the manager if (isRoot) { this.managerName_ = "0"; } else { this.managerName_ = parentPathManager.Name + subIndex.ToString(); } }
private void EndManagePath(Square endPointSquare, bool noMoreNeighBour) { SelectSquare(endPointSquare); // if no more solution found then indicate that this is a wrong path if (noMoreNeighBour) { this.endPointSquare_ = endPointSquare; if (this.endPointSquare_.X == this.TargetSquare.X && this.endPointSquare_.Y == this.TargetSquare.Y) { // we have found the solution this.pathStatus_ = SquarePathStatus.CORRECT; // found the solution this.SolutionFound = true; // also indicate that we have found the solution for parent managers and add it to the solution list PathManager tmpManager = this; while (tmpManager != null) { tmpManager.SolutionFound = true; tmpManager.Solutions.Add(this); tmpManager = tmpManager.ParentPathManager; } } else { // we have not found the solution this.pathStatus_ = SquarePathStatus.WRONG; // found the solution this.SolutionFound = false; } } this.endManagePath_ = true; }