Implemented piece logic
This commit is contained in:
1 parent
a117de01fc
commit
f14920f03a
7 files changed
+200
No files matched your search
@@ -0,0 +1,24 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
import static com.gitea.lin.model.Direction.*;
|
||||||
|
|
||||||
|
public final class Bishop extends Piece {
|
||||||
|
public Bishop(Color c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction[] getMoveDomain() {
|
||||||
|
return new Direction[] {NORTH_EAST, NORTH_WEST, SOUTH_EAST, SOUTH_WEST};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getMaximumStep() { return 7; }
|
||||||
|
@Override
|
||||||
|
public char getSymbol() { return 'B'; }
|
||||||
|
@Override
|
||||||
|
public Type getType() { return Type.BISHOP; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
import static com.gitea.lin.model.Direction.*;
|
||||||
|
|
||||||
|
public final class King extends Piece {
|
||||||
|
public King(Color c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction[] getMoveDomain() {
|
||||||
|
return new Direction[] {NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaximumStep() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char getSymbol() {
|
||||||
|
return 'K';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType() {
|
||||||
|
return Type.KING;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
import static com.gitea.lin.model.Direction.*;
|
||||||
|
|
||||||
|
public final class Knight extends Piece {
|
||||||
|
public Knight(Color c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction[] getMoveDomain() {
|
||||||
|
return new Direction[] {KNIGHT_ENE, KNIGHT_ESE, KNIGHT_NNE, KNIGHT_NNW, KNIGHT_SSE, KNIGHT_SSW, KNIGHT_WNW, KNIGHT_WSW};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getMaximumStep() { return 2; }
|
||||||
|
@Override
|
||||||
|
public char getSymbol() { return 'N'; }
|
||||||
|
@Override
|
||||||
|
public Type getType() { return Type.KNIGHT; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
import static com.gitea.lin.model.Direction.*;
|
||||||
|
|
||||||
|
public final class Pawn extends Piece {
|
||||||
|
public Pawn(Color c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction[] getMoveDomain() {
|
||||||
|
boolean isWhite = super.getColor() == Color.WHITE;
|
||||||
|
|
||||||
|
Direction forward = isWhite ? NORTH : SOUTH;
|
||||||
|
Direction forwardDouble = isWhite ? PAWN_DOUBLE_NORTH : PAWN_DOUBLE_SOUTH;
|
||||||
|
Direction hitLeft = isWhite ? NORTH_WEST : SOUTH_WEST;
|
||||||
|
Direction hitRight = isWhite ? NORTH_EAST : SOUTH_EAST;
|
||||||
|
|
||||||
|
if (super.hasMoved()) {
|
||||||
|
return new Direction[] {forward, hitLeft, hitRight};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Direction[] {forward, forwardDouble, hitLeft, hitRight};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaximumStep() {
|
||||||
|
return super.hasMoved() ? 1 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char getSymbol() {
|
||||||
|
return 'P';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType() {
|
||||||
|
return Type.PAWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
public abstract class Piece {
|
||||||
|
private Color pieceColor;
|
||||||
|
private boolean movedBefore;
|
||||||
|
|
||||||
|
public Piece(Color c) {
|
||||||
|
this.pieceColor = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Direction[] getMoveDomain();
|
||||||
|
public abstract int getMaximumStep(); // TODO: Update UML
|
||||||
|
public abstract char getSymbol();
|
||||||
|
public abstract Type getType();
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return this.pieceColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasMoved() {
|
||||||
|
return this.movedBefore;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
import static com.gitea.lin.model.Direction.*;
|
||||||
|
|
||||||
|
public final class Queen extends Piece {
|
||||||
|
public Queen(Color c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction[] getMoveDomain() {
|
||||||
|
return new Direction[] {NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getMaximumStep() { return 7; }
|
||||||
|
@Override
|
||||||
|
public char getSymbol() { return 'Q'; }
|
||||||
|
@Override
|
||||||
|
public Type getType() { return Type.QUEEN; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.gitea.lin.model.Piece;
|
||||||
|
|
||||||
|
import com.gitea.lin.model.Color;
|
||||||
|
import com.gitea.lin.model.Direction;
|
||||||
|
import com.gitea.lin.model.Type;
|
||||||
|
|
||||||
|
import static com.gitea.lin.model.Direction.*;
|
||||||
|
|
||||||
|
public final class Rook extends Piece {
|
||||||
|
public Rook(Color c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction[] getMoveDomain() {
|
||||||
|
return new Direction[] {NORTH, EAST, SOUTH, WEST};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getMaximumStep() { return 7; }
|
||||||
|
@Override
|
||||||
|
public char getSymbol() { return 'R'; }
|
||||||
|
@Override
|
||||||
|
public Type getType() { return Type.ROOK; }
|
||||||
|
}
|
||||||
Reference in new issue
Block a user