Class Coordinates

java.lang.Object
  |
  +--PrintSuperClass
        |
        +--Coordinates

public class Coordinates
extends PrintSuperClass

Used to check, create and move the board location row,column;

Uses the constants Board.MAXROWS and Board.MAXCOLS

since board can have multiple coordinates, and since a coordinate may not always be tied to a board didn't use inheritance

See Also:
Board

Field Summary
 int col
          public variables a Coordinates is row, column
 int row
          public variables a Coordinates is row, column
 
Constructor Summary
Coordinates()
           
Coordinates(Coordinates c)
           
Coordinates(int i)
          sets Coordinate to the i where i = row*MAXCOLS + col
Coordinates(int r, int c)
           
 
Method Summary
 void copy(Coordinates c)
           
 int distance(Coordinates c)
          computes the horizontal or vertical distance between two points
 boolean down()
          takes current coordinate object and moves is down one row
 boolean equals(Coordinates c)
           
 boolean isLegal()
           
 boolean isLegalCol()
           
 boolean isLegalRow()
           
 boolean left()
          takes current coordinate object and moves it left one coordinate
 Coordinates max(Coordinates c)
           
 Coordinates min(Coordinates c)
           
 Coordinates next()
          takes current coordinate object and moves it to the next location when coordinate reaches end of board is starts over at 0,0
 void print(java.io.PrintWriter pw)
           
 void println(java.io.PrintWriter pw)
           
 boolean right()
          takes current coordinate object and moves it right one coordinate
 Coordinates set(Coordinates c)
          sets current Coordinate object to location c
 Coordinates set(int i)
          sets current Coordinate object to singleton i where i = row*MAXCOLS + col
 Coordinates set(int r, int c)
          sets current Coordinate object to r, c
 Coordinates setLegal(int r, int c)
          sets Coordinate object's row and col to the closest boards legal values of r, c
 int singleton()
           
 java.lang.String toString()
           
 boolean up()
          takes current coordinate object and moves it up one row
 
Methods inherited from class PrintSuperClass
print, print, print, println, println, println
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

row

public int row
public variables a Coordinates is row, column

col

public int col
public variables a Coordinates is row, column
Constructor Detail

Coordinates

public Coordinates()

Coordinates

public Coordinates(int r,
                   int c)

Coordinates

public Coordinates(Coordinates c)

Coordinates

public Coordinates(int i)
sets Coordinate to the i where i = row*MAXCOLS + col
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

print

public void print(java.io.PrintWriter pw)
Overrides:
print in class PrintSuperClass

println

public void println(java.io.PrintWriter pw)
Overrides:
println in class PrintSuperClass

copy

public void copy(Coordinates c)

set

public Coordinates set(int r,
                       int c)
sets current Coordinate object to r, c
Returns:
this coordinate position

set

public Coordinates set(Coordinates c)
sets current Coordinate object to location c
Returns:
return this pointer

set

public Coordinates set(int i)
sets current Coordinate object to singleton i where i = row*MAXCOLS + col
Returns:
this Coordinate position

setLegal

public Coordinates setLegal(int r,
                            int c)
sets Coordinate object's row and col to the closest boards legal values of r, c

up

public boolean up()
takes current coordinate object and moves it up one row
Returns:
true if new position is legal

down

public boolean down()
takes current coordinate object and moves is down one row
Returns:
true if position is still on board

left

public boolean left()
takes current coordinate object and moves it left one coordinate
Returns:
true if new position exists on board

right

public boolean right()
takes current coordinate object and moves it right one coordinate
Returns:
true if new position exists on board

next

public Coordinates next()
takes current coordinate object and moves it to the next location when coordinate reaches end of board is starts over at 0,0
Returns:
this new Coordinate

isLegalRow

public boolean isLegalRow()
Returns:
true if row is legal, exists on board

isLegalCol

public boolean isLegalCol()

isLegal

public boolean isLegal()
Returns:
true if coordinate is a legal board position

singleton

public int singleton()
Returns:
integer representing col*Board.MAXROWS + row

max

public Coordinates max(Coordinates c)

min

public Coordinates min(Coordinates c)

distance

public int distance(Coordinates c)
computes the horizontal or vertical distance between two points

Limitation: Doesn't compute diagonal distance

Returns:
distance between the parameter c and the calling object

equals

public boolean equals(Coordinates c)
Returns:
true if both Coordinates are the same