- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathChessPosition.java
More file actions
Latest commit
39 lines (29 loc) Β· 774 Bytes
/
Copy pathChessPosition.java
File metadata and controls
39 lines (29 loc) Β· 774 Bytes
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
packagechess;
importboardgame.Position;
publicclassChessPosition {
privatecharcolumn;
privateintrow;
publicChessPosition(charcolumn, introw) {
if(column < 'a' || column > 'h' || row < 1 || row > 8) {
thrownewChessException("Error instantiang ChessPosition. Valid values are from a1 to h8.");
}
this.column = column;
this.row = row;
}
publicchargetColumn() {
returncolumn;
}
publicintgetRow() {
returnrow;
}
protectedPositiontoPosition() {
returnnewPosition(8 - row, column - 'a');
}
protectedstaticChessPositionfromPosition(Positionposition) {
returnnewChessPosition((char)('a' + position.getColumn()), 8 - position.getRow());
}
@Override
publicStringtoString() {
return"" + column + row;
}
}