001    import java.io.*;
002    import java.lang.*;
003    import java.util.*;
004    
005    
006    public class Node {
007            private int iTop=-1,iRight=-1,iBottom=-1,iLeft=-1;
008            private Point pPoint;
009            private int iG=0, iH=0;
010            private double dF;
011            private Node nParent;
012    
013            /**
014             *      The no-arg constructor only declares the coordinates.
015             */     
016            public Node(){
017                    pPoint          = new Point();
018            }
019    
020    
021            public Node(Node _nNode){
022                    pPoint.x        = _nNode.getX();
023                    pPoint.y        = _nNode.getY();
024                    iG                      = _nNode.getG();
025                    iH                      = _nNode.getH();
026                    nParent         = _nNode.getParent();
027                    iTop            = _nNode.getTop();
028                    iRight          = _nNode.getRight();
029                    iBottom         = _nNode.getBottom();
030                    iLeft           = _nNode.getLeft();
031            }
032                    
033            /**
034             *      Instantiates the coordinates of the Node.
035             *
036             *      @param _pPoint location of the gridcoordinate
037             */
038            public Node(Point _pPoint){
039                    pPoint          = new Point();
040                    pPoint.x        = _pPoint.x;
041                    pPoint.y        = _pPoint.y;
042                    pPoint.z        = 0;
043            }
044            
045            /**
046             *      Instantiates the coordinates of the Node.
047             *
048             *      @param _iX the X value of the coordinate
049             *      @param _iY the Y value of the coordinate
050             */
051            public Node(int _iX, int _iY){
052                    pPoint          = new Point();
053                    pPoint.x        = _iX;
054                    pPoint.y        = _iY;
055            }
056            
057            /**
058             * The full contructor, instantiates the coordinate and wall booleans on the four side's of the coordinate
059             *      @param _pPoint  location of the gridcoordinate
060             *      @param _iTop    Wall yes or no at Top of gridcoordinate
061             *      @param _iRight  Wall yes or no at Right of gridcoordinate
062             *      @param _iBottom Wall yes or no at Bottom of gridcoordinate
063             *      @param _iLeft   Wall yes or no at Left of gridcoordinate
064             */
065            public Node(Point _pPoint,int _iTop,int _iRight,int _iBottom,int _iLeft){
066                    pPoint          = new Point();
067                    pPoint.x        = _pPoint.x;
068                    pPoint.x        = _pPoint.x;
069                    iTop            = _iTop;
070                    iBottom         = _iBottom;
071                    iRight          = _iRight;
072                    iLeft           = _iLeft;
073            }
074            
075            /**
076             * The full contructor, instantiates the coordinate and wall booleans on the four side's of the coordinate
077             *      @param _iX the X value of the coordinate
078             *      @param _iY the Y value of the coordinate
079             *      @param _iTop    Wall yes or no at Top of gridcoordinate
080             *      @param _iRight  Wall yes or no at Right of gridcoordinate
081             *      @param _iBottom Wall yes or no at Bottom of gridcoordinate
082             *      @param _iLeft   Wall yes or no at Left of gridcoordinate
083             */
084            public Node(int _iX, int _iY, int _iTop,int _iRight,int _iBottom,int _iLeft){
085                    pPoint          = new Point();
086                    pPoint.x        = _iX;
087                    pPoint.y        = _iY;
088                    iTop            = _iTop;
089                    iBottom         = _iBottom;
090                    iRight          = _iRight;
091                    iLeft           = _iLeft;
092            }
093    
094    
095    
096            /**
097             *      Checks wheter two Nodes have the same Coordinate
098             *      @param _nNode The Node that the current Node is compared with
099             *      @return true if the coordinates are the same
100             */
101            public boolean isPointEqual(Node _nNode){
102                    if((pPoint.x == _nNode.getX()) && (pPoint.y == _nNode.getY())){
103                            return true;
104                    }
105                    return false;   
106            }
107    
108            /**
109             *      Checks wheter a border exist at a given loaction
110             *      @param _iDirection The direction we are looking at (1=top,2=right,3=left,4=left)
111             *      @return true if the border exists
112             */
113            public int borderValue(int _iDirection){
114                    if(_iDirection == 0){return iTop;}
115                    else if(_iDirection == 1){return iRight;}
116                    else if(_iDirection == 2){return iBottom;}
117                    else if(_iDirection == 3){return iLeft;}
118                    return -2;
119            }
120    
121    
122            public boolean allBordersKnown()        {
123                    return ((iTop!=-1) && (iRight!=-1) && (iBottom!=-1) && (iLeft!=-1));
124            }
125            
126            public int bordersUnknownCount()        {
127                    int i=0;
128                    if(iTop== -1) i++;
129                    if(iRight== -1) i++;
130                    if(iBottom== -1) i++;
131                    if(iLeft== -1) i++;
132                    return i;
133            }
134    
135            public int bordersFalseCount()  {
136                    int i=0;
137                    if(iTop<= 0) i++;
138                    if(iRight<= 0) i++;
139                    if(iBottom<= 0) i++;
140                    if(iLeft<= 0) i++;
141                    return i;
142            }
143            
144            /*----------- GETTERS ----------- */
145            /**
146             *      @return The integer X coordinate
147             */
148            public int getX() {
149                    return (int)pPoint.x;
150            }
151            
152            /**
153             *      @return The integer Y coordinate
154             */
155            public int getY() {
156                    return (int)pPoint.y;
157            }
158    
159            /**
160             *      @return The integer h(n) value
161             */
162            public int getH() {
163                    return iH;
164            }
165    
166            /**
167             *      @return The integer g(n) value
168             */
169            public int getG() {
170                    return iG;
171            }
172    
173            
174            /**
175             *      @return The integer f(n) value
176             */
177            public double getF() {
178                    dF = iG+iH;
179                    return dF;
180            }
181                    
182            /**
183             * @return The int value containing a wall at Topside of the coordinaat
184             */
185            public int getTop(){
186                    return iTop;
187            }
188            
189            /**
190             * @return The int value containing a wall at Rightside of the coordinaat
191             */
192            public int getRight(){
193                    return iRight;
194            }
195    
196            /**
197             * @return The int value containing a wall at Bottomside of the coordinaat
198             */
199            public int getBottom(){
200                    return iBottom;
201            }
202            
203            /**
204             * @return The int value containing a wall at Leftside of the coordinaat
205             */
206            public int getLeft(){
207                    return iLeft;
208            }
209    
210            /**
211             *      @return The parent-Node
212             */     
213            public Node getParent(){
214                    return nParent;
215            }
216    
217    
218            /*----------- SETTERS ----------- */
219            /**
220             * Sets the X coordinate
221             * @param _iX the X value of the coordinate
222             */
223            public void setX(int _iX) {
224                    pPoint.x = _iX;
225            }
226    
227            /**
228             * Sets the Y coordinate
229             * @param _iY the Y value of the coordinate
230             */
231            public void setY(int _iY) {
232                    pPoint.y = _iY;
233            }
234    
235            /**
236             * Sets the Wall yes or no at Top of gridcoordinate
237             *      @param _iTop    Wall yes or no at Top of gridcoordinate
238             */
239            public void setBorder(int _iDirection, int _iValue) {
240                    if(_iDirection == 0){iTop = _iValue;}
241                    if(_iDirection == 1){iRight = _iValue;}
242                    if(_iDirection == 2){iBottom = _iValue;}
243                    if(_iDirection == 3){iLeft = _iValue;}
244            }
245            
246            /**
247             * Sets the Wall yes or no at Top of gridcoordinate
248             *      @param _iTop    Wall yes or no at Top of gridcoordinate
249             */
250            public void setTop(int _iTop) {
251                    iTop = _iTop;
252            }
253    
254            /**
255             * Sets the Wall yes or no at Right of gridcoordinate
256             *      @param _iRight  Wall yes or no at Right of gr_iTopidcoordinate
257             */
258            public void setRight(int _iRight) {
259                    iRight = _iRight;
260            }
261    
262            /**
263             * Sets the Wall yes or no at Bottom of gridcoordinate
264             *      @param _iBottom         Wall yes or no at Bottom of gridcoordinate
265             */
266            public void setBottom(int _iBottom) {
267                    iBottom = _iBottom;
268            }
269    
270            /**
271             * Sets the Wall yes or no at Left of gridcoordinate
272             *      @param _iLeft   Wall yes or no at Left of gridcoordinate
273             */
274            public void setLeft(int _iLeft) {
275                    iLeft = _iLeft;
276            }
277    
278            /**
279             * Sets the g(n) value
280             * @param _iG g(n)
281             */
282            public void setG(int _iG) {
283                    iG = _iG;
284            }
285            
286            /**
287             * Sets the h(n) value
288             * @param _iH h(n)
289             */
290            public void setH(int _iH) {
291                    iH = _iH;
292            }
293            /**
294             *      Sets the parent Node value
295             *      @param p A Node holding the parent-Node
296             */
297            public void setParent(Node _nNode) {
298                    nParent = _nNode;
299            }
300    
301            
302            /**
303             *      @return A String with the coordinates placed in brackets.
304             */             
305            public String toString(){
306                    return "[ " + pPoint.x + ", " + pPoint.y + " ]";
307            }
308    
309                    
310    }