-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support hurdles in path while moving
- Loading branch information
Udit Agarwal
committed
Jul 17, 2020
1 parent
927bbf6
commit 004181c
Showing
19 changed files
with
229 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
*.iml | ||
*.iml | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/uditagarwal/chess/conditions/PieceCellOccupyBlocker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.uditagarwal.chess.conditions; | ||
|
||
import com.uditagarwal.chess.model.Board; | ||
import com.uditagarwal.chess.model.Cell; | ||
import com.uditagarwal.chess.model.Piece; | ||
|
||
/** | ||
* This check tells whether a piece can occupy a given cell in the board or not. | ||
*/ | ||
public interface PieceCellOccupyBlocker { | ||
|
||
boolean isCellNonOccupiableForPiece(Cell cell, Piece piece, Board board); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/uditagarwal/chess/conditions/PieceCellOccupyBlockerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.uditagarwal.chess.conditions; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.uditagarwal.chess.model.Piece; | ||
|
||
import java.util.List; | ||
|
||
public class PieceCellOccupyBlockerFactory { | ||
|
||
public static List<PieceCellOccupyBlocker> defaultBlockers() { | ||
return ImmutableList.of(new PieceCellOccupyBlockerSelfPiece(), new PieceCellOccupyBlockerKingCheck()); | ||
} | ||
|
||
public static List<PieceCellOccupyBlocker> kingCheckEvaluationBlockers() { | ||
return ImmutableList.of(new PieceCellOccupyBlockerSelfPiece()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/uditagarwal/chess/conditions/PieceCellOccupyBlockerKingCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.uditagarwal.chess.conditions; | ||
|
||
import com.uditagarwal.chess.model.Board; | ||
import com.uditagarwal.chess.model.Cell; | ||
import com.uditagarwal.chess.model.Piece; | ||
import com.uditagarwal.chess.model.PieceType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.uditagarwal.chess.conditions.PieceCellOccupyBlockerFactory.kingCheckEvaluationBlockers; | ||
|
||
/** | ||
* This tells whether making piece move to a cell will attract check for king. | ||
*/ | ||
public class PieceCellOccupyBlockerKingCheck implements PieceCellOccupyBlocker { | ||
|
||
@Override | ||
public boolean isCellNonOccupiableForPiece(final Cell cell, final Piece piece, final Board board) { | ||
Cell pieceOriginalCell = piece.getCurrentCell(); | ||
piece.setCurrentCell(cell); | ||
boolean playerGettingCheckByMove = board.isPlayerOnCheck(piece.getPlayer()); | ||
piece.setCurrentCell(pieceOriginalCell); | ||
return playerGettingCheckByMove; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/uditagarwal/chess/conditions/PieceCellOccupyBlockerSelfPiece.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.uditagarwal.chess.conditions; | ||
|
||
import com.uditagarwal.chess.model.Board; | ||
import com.uditagarwal.chess.model.Cell; | ||
import com.uditagarwal.chess.model.Piece; | ||
|
||
public class PieceCellOccupyBlockerSelfPiece implements PieceCellOccupyBlocker { | ||
|
||
@Override | ||
public boolean isCellNonOccupiableForPiece(Cell cell, Piece piece, Board board) { | ||
if (cell.isFree()) { | ||
return false; | ||
} | ||
return cell.getCurrentPiece().getColor() == piece.getColor(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/uditagarwal/chess/conditions/PieceMoveFurtherCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.uditagarwal.chess.conditions; | ||
|
||
import com.uditagarwal.chess.model.Board; | ||
import com.uditagarwal.chess.model.Cell; | ||
import com.uditagarwal.chess.model.Piece; | ||
|
||
public interface PieceMoveFurtherCondition { | ||
|
||
boolean canPieceMoveFurtherFromCell(Piece piece, Cell cell, Board board); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/uditagarwal/chess/conditions/PieceMoveFurtherConditionDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.uditagarwal.chess.conditions; | ||
|
||
import com.uditagarwal.chess.model.Board; | ||
import com.uditagarwal.chess.model.Cell; | ||
import com.uditagarwal.chess.model.Piece; | ||
|
||
public class PieceMoveFurtherConditionDefault implements PieceMoveFurtherCondition { | ||
|
||
@Override | ||
public boolean canPieceMoveFurtherFromCell(Piece piece, Cell cell, Board board) { | ||
return cell.isFree(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/uditagarwal/chess/exceptions/PieceNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.uditagarwal.chess.exceptions; | ||
|
||
public class PieceNotFoundException extends RuntimeException { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,7 @@ public class Cell { | |
private Piece currentPiece; | ||
|
||
|
||
public boolean isFree() { | ||
return currentPiece == null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.uditagarwal.chess.model; | ||
|
||
public enum PieceType { | ||
KING, | ||
QUEEN, | ||
ROOK, | ||
KNIGHT, | ||
BISHOP, | ||
PAWN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.