Yes.
This commit is contained in:
@@ -19,6 +19,15 @@ class Loc {
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loc up() { return new Loc(this.x, this.y - 1); }
|
||||||
|
Loc down() { return new Loc(this.x, this.y + 1); }
|
||||||
|
Loc right() { return new Loc(this.x + 1, this.y); }
|
||||||
|
Loc left() { return new Loc(this.x - 1, this.y); }
|
||||||
|
Loc up(PieceCol col) { return new Loc(this.x, this.y - 1 * col.n()); }
|
||||||
|
Loc down(PieceCol col) { return new Loc(this.x, this.y + 1 * col.n()); }
|
||||||
|
Loc right(PieceCol col) { return new Loc(this.x + 1, this.y * col.n()); }
|
||||||
|
Loc left(PieceCol col) { return new Loc(this.x - 1, this.y * col.n()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// The color a chess piece may assume.
|
// The color a chess piece may assume.
|
||||||
@@ -30,7 +39,29 @@ enum PieceCol {
|
|||||||
return this.equals(BLACK) ? new Color(0, 0, 0)
|
return this.equals(BLACK) ? new Color(0, 0, 0)
|
||||||
: new Color(255, 255, 255);
|
: new Color(255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int n() { return this.equals(WHITE) ? 1 : -1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// The sort of piece.
|
// The sort of piece.
|
||||||
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING }
|
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING }
|
||||||
|
|
||||||
|
abstract class Piece {
|
||||||
|
Loc loc;
|
||||||
|
PieceType type;
|
||||||
|
PieceCol col;
|
||||||
|
|
||||||
|
Piece(Loc loc, PieceType type, PieceCol col) {
|
||||||
|
this.loc = loc;
|
||||||
|
this.type = type;
|
||||||
|
this.col = col;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Loc> moves() { return List.of(this.loc.up(this.col)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pawn extends Piece {
|
||||||
|
Pawn(Loc loc, PieceType type, PieceCol col) { super(loc, type, col); }
|
||||||
|
|
||||||
|
List<Loc> moves() {}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user