Everything.
This commit is contained in:
@@ -1,67 +1,3 @@
|
|||||||
package chess;
|
package chess;
|
||||||
|
|
||||||
import java.awt.Color;
|
class Main {}
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.swing.Action;
|
|
||||||
|
|
||||||
// A chessboard.
|
|
||||||
class Board {
|
|
||||||
Map<Loc, Piece> board;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A location on the board. Measured from top left corner.
|
|
||||||
class Loc {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
|
|
||||||
Loc(int x, int y) {
|
|
||||||
this.x = x;
|
|
||||||
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.
|
|
||||||
enum PieceCol {
|
|
||||||
BLACK,
|
|
||||||
WHITE;
|
|
||||||
|
|
||||||
Color mk() {
|
|
||||||
return this.equals(BLACK) ? new Color(0, 0, 0)
|
|
||||||
: new Color(255, 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
int n() { return this.equals(WHITE) ? 1 : -1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// The sort of piece.
|
|
||||||
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