-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
56 lines (52 loc) · 1.31 KB
/
Knight.java
File metadata and controls
56 lines (52 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package puzzleSolver;
/**
* Knight.java
*
* File:
* $Id: Knight.java,v 1.1 2013/05/03 22:27:17 cas5420 Exp $
*
* Revisions:
* $Log: Knight.java,v $
* Revision 1.1 2013/05/03 22:27:17 cas5420
* Finished Puzzle solver, just need to comment.
*
* Revision 1.3 2013/05/03 13:52:09 cas5420
* Completed chess solver, debugging
*
*/
import java.util.HashSet;
/**
* Defines Knight piece.
* @author Chris Sleys
*
*/
public class Knight extends Piece{
/**
* Initializes inherited values.
* @param name Name of Knight
* @param X Length of the board on x-axis
* @param Y Length of the board on y-axis
*/
public Knight(String name, int X, int Y) {
super(name, X, Y);
}
/**
* Returns every L shaped endpoint with bounds checked.
*/
@Override
public HashSet<Point> getMoves(Point init) {
HashSet<Point> moves = new HashSet<Point>();
int x = init.getX();
int y = init.getY();
moves.add(new Point(x+1, y-2)); // north east
moves.add(new Point(x-1, y-2)); // north west
moves.add(new Point(x+1, y+2)); // south east
moves.add(new Point(x-1, y+2)); // south west
moves.add(new Point(x+2, y-1)); // east north
moves.add(new Point(x+2, y+1)); // east south
moves.add(new Point(x-2, y-1)); // west north
moves.add(new Point(x-2, y+1)); // west south
super.checkBounds(moves);
return moves;
}
}