Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWang18 committed Dec 22, 2020
1 parent 406980d commit ca8a508
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/main/java/domain/Logic/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ public boolean displayError() { //no movement

ImmutablePair<Pair, Boolean> testCheck = moveMakesCheck(start, end);

if (Boolean.TRUE == testCheck.right) {
if (Boolean.TRUE == testCheck.right) {

//pass in the Kings position to see if mate, ends game if true
//pass in the Kings position and piece to see if mate, ends game if true
if(isCheckMate(testCheck.left)){
over = true;
return false;
Expand Down Expand Up @@ -429,21 +429,21 @@ private ImmutablePair<Pair, Boolean> moveMakesCheck(Square start, Square end) {
}

private boolean isCheckMate(Pair currentKingXY) {

int x = currentKingXY.getX();
int y = currentKingXY.getY();
int GIRTH = Board.getSize();
List<Pair> possibleKingPos = new ArrayList<>(8);
int size = Board.getSize();

List<Pair> possibleKingPos = new ArrayList<>(8);

//Adding possible moves for the passed king
if((y + 1) < GIRTH){ //upper level

if((y + 1) < size){ //upper level
possibleKingPos.add(new Pair(x, y + 1));
if(x - 1 >= 0){
possibleKingPos.add(new Pair(x-1, y+1));
}
if(x + 1 < GIRTH){
if(x + 1 < size){
possibleKingPos.add(new Pair(x+1, y+1));
}
}
Expand All @@ -453,25 +453,24 @@ private boolean isCheckMate(Pair currentKingXY) {
if(x - 1 >= 0){
possibleKingPos.add(new Pair(x-1, y-1));
}
if(x + 1 < GIRTH){
if(x + 1 < size){
possibleKingPos.add(new Pair(x+1, y-1));
}
}

if(x - 1 >= 0){ //same level
possibleKingPos.add(new Pair(x-1,y));
}
if(x + 1 < GIRTH){
if(x + 1 < size){
possibleKingPos.add(new Pair(x+1,y));
}

//get rid of the moves that have pieces already occupying it, than filter the remaining if it is being attacked

List<? extends Pair> validKingMoves = possibleKingPos.stream().filter(m->!board.getBoard()[m.getY()][m.getX()].hasPiece()).
List<? extends Pair> validKingPos = possibleKingPos.stream().filter(m->!board.getBoard()[m.getY()][m.getX()].hasPiece()).
filter(p -> !isPieceBeingAttkd(p).right).collect(Collectors.toList());

//if list is empty than there is no valid place for the king to go
return validKingMoves.isEmpty();
return validKingPos.isEmpty(); //if list is empty than there is no valid place for the king to go
}

private Pair getKingPos(Square[][] bd) {
Expand Down Expand Up @@ -545,7 +544,7 @@ private Message checkPiecesPath(List<Pair> path, Pair startXY, Pair endXY) { //c

return flag;
}

private boolean squareIsOccupied(Square[][] bd, Pair pair, Pair startXY, Pair endXY) {
// Ignore the start and ending position of the path - irrelevant to the
//validity of the path
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/domain/Pieces/King.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package domain.Pieces;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -8,6 +9,8 @@
import domain.Logic.Color.ColorType;
import domain.Pieces.Visitor.Visitor;


/* should i put possible Positions in here, return a list of possible pos based on the pair passed? */
public class King extends Piece {

public static final PieceType TYPE = PieceType.KING;
Expand Down
Binary file modified target/classes/domain/Logic/Game.class
Binary file not shown.
Binary file modified target/classes/domain/Pieces/King.class
Binary file not shown.

0 comments on commit ca8a508

Please sign in to comment.