diff --git a/MavenChess/MavenChess/src/main/java/model/Giant.java b/MavenChess/MavenChess/src/main/java/model/Giant.java new file mode 100644 index 0000000000000000000000000000000000000000..91fd8797195d7b7067887933d783e82083cf0b35 --- /dev/null +++ b/MavenChess/MavenChess/src/main/java/model/Giant.java @@ -0,0 +1,99 @@ +package model; + +import java.util.ArrayList; + +public class Giant extends Piece{ + protected Giant(Position p, int color) { + super(p, color); + } + + + @Override + public ArrayList<Position> getAvailableMoves(Board b) { + + ArrayList<Position> moves = new ArrayList<Position>(); + + Position arrival; + int i = 1; + boolean left = false; + boolean right = false; + boolean top = false; + boolean down = false; + + while (i < 4) { + + //left + + arrival = new Position(p.getX() + (i*2), p.getY()); + if (Position.isCorrect(arrival)) { + if (!left) { + if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + + if (b.isKing(arrival)) { + moves.add(arrival); + + } + } + if (!b.isFree(arrival)) { + left = true; + } + } + + //right + arrival = new Position(p.getX() - (i*2), p.getY()); + if (Position.isCorrect(arrival)) { + if (!right) { + if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + if (b.isKing(arrival)) { + moves.add(arrival); + } + } + + if (!b.isFree(arrival)) { + + right = true; + } + } + + + arrival = new Position(p.getX(), p.getY() + (i*2)); + if (Position.isCorrect(arrival)) { + if (!top) { + if (b.isEnnemy(arrival, p)|| b.isFree(arrival)) { + moves.add(arrival); + } + } + + if (!b.isFree(arrival)) { + + top = true; + } + } + + + + arrival = new Position(p.getX(), p.getY() - (i*2)); + if (Position.isCorrect(arrival)) { + if (!down) { + if (b.isEnnemy(arrival, p)|| b.isFree(arrival)) { + moves.add(arrival); + } + } + + if (!b.isFree(arrival)) { + + top = true; + } + } + + i++; + } + + return moves; + + } +} diff --git a/MavenChess/MavenChess/src/main/java/model/Kamikaze.java b/MavenChess/MavenChess/src/main/java/model/Kamikaze.java new file mode 100644 index 0000000000000000000000000000000000000000..ff30aaadbc6a8f1f088fb0754bb4f5bba35c5c0d --- /dev/null +++ b/MavenChess/MavenChess/src/main/java/model/Kamikaze.java @@ -0,0 +1,51 @@ +package model; + +import java.util.ArrayList; + +public class Kamikaze extends Pawn { + public Kamikaze(Position p, int color) { + super(p, color); + } + + @Override + public ArrayList<Position> getAvailableMoves(Board b) { + + + ArrayList<Position> moves = new ArrayList<Position>(); + Position arrival; + + + // Self-Detonation Position no need for checks as the Kamikaze is already in place + arrival = new Position(p.getX(),p.getY()); + moves.add(arrival); + + if(color == Piece.WHITE) { // black and white have an opposite direction behavior + + if(this.p.getID() == this.original.getID()){ + + arrival = new Position(p.getX(),p.getY()+2); + if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);} + + } + + arrival = new Position(p.getX(),p.getY()+1); + if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);} + + } + else { + + + if(this.p.getID() == this.original.getID()){ + + arrival = new Position(p.getX(),p.getY()-2); + if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);} + + } + + arrival = new Position(p.getX(),p.getY()-1); + if(Position.isCorrect(arrival) && b.isFree(arrival)) {moves.add(arrival);} + + } + return moves; + } +} diff --git a/MavenChess/MavenChess/src/main/java/model/Magician.java b/MavenChess/MavenChess/src/main/java/model/Magician.java new file mode 100644 index 0000000000000000000000000000000000000000..72c1bae72257048cfa1d7c73f5000c373180b773 --- /dev/null +++ b/MavenChess/MavenChess/src/main/java/model/Magician.java @@ -0,0 +1,20 @@ +package model; + +import java.util.ArrayList; + +public class Magician extends Piece{ + + private Piece CopiedPiece; + protected Magician(Position p, int color) { + super(p, color); + } + + + public void setCopiedPiece(Piece copiedPiece) { + this.CopiedPiece = copiedPiece; + } + public void setPosition(Position p) { + this.p = p; + CopiedPiece.setPosition(p); + } +} diff --git a/MavenChess/MavenChess/src/main/java/model/Nwap.java b/MavenChess/MavenChess/src/main/java/model/Nwap.java new file mode 100644 index 0000000000000000000000000000000000000000..f6f5a4a1deb59177a93ca490993543e7b80428a6 --- /dev/null +++ b/MavenChess/MavenChess/src/main/java/model/Nwap.java @@ -0,0 +1,76 @@ +package model; + +import java.util.ArrayList; + +public class Nwap extends Pawn { + public Nwap(Position p, int color) { + super(p, color); + } + + @Override + public ArrayList<Position> getAvailableMoves(Board b) { + + + ArrayList<Position> moves = new ArrayList<Position>(); + Position arrival; + + + if(color == Piece.WHITE) { // black and white have an opposite direction behavior + + if(this.p.getID() == this.original.getID()){ + + // up left 2 + arrival = new Position(p.getX()-2, p.getY() +2); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + + // up left 2 + arrival = new Position(p.getX()+2, p.getY() +2); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + } + // up left 1 + arrival = new Position(p.getX()-1, p.getY() +1); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + + // up left 1 + arrival = new Position(p.getX()+1, p.getY() +1); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + arrival = new Position(p.getX(),p.getY()+1); + if(b.isEnnemy(arrival,p)) {moves.add(arrival);} + + } + else { + + + if(this.p.getID() == this.original.getID()){ + + // up left 2 + arrival = new Position(p.getX()-2, p.getY() -2); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + + // up left 2 + arrival = new Position(p.getX()+2, p.getY() -2); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + } + // up left 1 + arrival = new Position(p.getX()-1, p.getY() -1); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + + // up left 1 + arrival = new Position(p.getX()+1, p.getY() -1); + if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + + + arrival = new Position(p.getX(),p.getY()-1); + if(b.isEnnemy(arrival,p)) {moves.add(arrival);} + + } + return moves; + } +}