Repository navigation
Expand file tree
/
Copy pathChessGame.java
More file actions
63 lines (57 loc) · 2.56 KB
/
Copy pathChessGame.java
File metadata and controls
63 lines (57 loc) · 2.56 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
57
58
59
60
61
62
63
/**
* An interface that encodes specific rules for a version of chess.
*
* @author Harold Connamacher (enum Side, legalPieceToPlay(ChessPiece piece, int row, int column), makeMove(ChessPiece piece, int toRow, int toColumn))
* @author Peter Schlueter (getNumRows(), getNumColumns(), startGame(Chessboard board))
*
*/
public interface ChessGame {
/**
* The "side" or "team" or "player" the piece belongs to.
* The "players" are named by the compass positions around the board
*/
public enum Side {NORTH, SOUTH, EAST, WEST};
/**
* Determines if it is legal to play a given piece.
* @param piece the piece to be played
* @param row the row of the square the piece is on
* @param column the column of the square the piece is on
* @return true if the piece is allowed to move on this turn
*/
public boolean legalPieceToPlay(ChessPiece piece, int row, int column);
/**
* Moves a piece to a new position.
* @param piece the piece to move
* @param toRow the row of the square the piece is moving to
* @param toColumn the column of the square the piece is moving to
* @return true if the move was made, false if the move was not made
*/
public boolean makeMove(ChessPiece piece, int toRow, int toColumn);
/**
* Returns whether a user can choose a different piece from the one selected or if they have to move the selected piece.
* If this method returns false, then the <tt>legalPieceToPlay</tt> method must not return true if that piece has no
* legal moves. Otherwise the game could freeze with a player not permitted to change selection of a piece with no legal moves.
* @param piece the piece the user selected
* @param row the row of the square the piece is on
* @param column the column of the square the piece is on
* @return true if the player can change the piece they selected and false if they cannot and must move that piece
*/
public default boolean canChangeSelection(ChessPiece piece, int row, int column) {
return true;
}
/**
* Gets the number of rows in a board for this type of chess game
* @return the number of rows in a board for this type of chess game
*/
public int getNumRows();
/**
* Gets the number of columns in a board for this type of chess game
* @return the number of columns in a board for this type of chess game
*/
public int getNumColumns();
/**
* Starts the chess game of the board type that is inputted
* @param board the board whose game rules are used for this game
*/
public void startGame(ChessBoard board);
}