-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the finding of all moving positions of a Pawn
- Loading branch information
1 parent
be93e3f
commit 330e591
Showing
8 changed files
with
106 additions
and
27 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
chess/src/main/scala/io/github/chess/model/rules/PresenceRule.scala
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 @@ | ||
/* | ||
* MIT License | ||
* Copyright (c) 2023 Cesario Jahrim Gabriele & Derevyanchenko Maxim & Felice Mirko & Kentpayeva Madina | ||
* | ||
* Full license description available at: https://github.com/jahrim/PPS-22-chess/blob/master/LICENSE | ||
*/ | ||
package io.github.chess.model.rules | ||
|
||
import io.github.chess.model.rules.ChessRule | ||
import io.github.chess.model.{ChessGameStatus, Move, Position} | ||
|
||
/** Chess rule mixin that checks the presence of a piece in the destination position after finding it. */ | ||
trait PresenceRule extends ChessRule: | ||
|
||
abstract override def findMoves(position: Position, status: ChessGameStatus): Set[Move] = | ||
super.findMoves(position, status).filter(move => !status.chessBoard.pieces.contains(move.to)) |
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
25 changes: 25 additions & 0 deletions
25
chess/src/main/scala/io/github/chess/model/rules/pawn/PawnMovementRule.scala
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,25 @@ | ||
/* | ||
* MIT License | ||
* Copyright (c) 2023 Cesario Jahrim Gabriele & Derevyanchenko Maxim & Felice Mirko & Kentpayeva Madina | ||
* | ||
* Full license description available at: https://github.com/jahrim/PPS-22-chess/blob/master/LICENSE | ||
*/ | ||
package io.github.chess.model.rules.pawn | ||
|
||
import io.github.chess.model.{ChessGameStatus, Move, Position, Rank, Team} | ||
import io.github.chess.model.rules.ChessRule | ||
|
||
/** Set of Pawn movement rules. */ | ||
class PawnMovementRule extends ChessRule: | ||
|
||
override def findMoves(position: Position, status: ChessGameStatus): Set[Move] = | ||
val firstStep = ForwardOneRule().findMoves(position, status) | ||
if firstStep.nonEmpty && isFirstMove(position, status) then | ||
firstStep ++ DoubleMoveRule().findMoves(position, status) | ||
else firstStep | ||
|
||
private def isFirstMove(position: Position, status: ChessGameStatus): Boolean = | ||
position.rank == (status.currentTurn match | ||
case Team.WHITE => Rank._2 | ||
case Team.BLACK => Rank._7 | ||
) |
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
23 changes: 23 additions & 0 deletions
23
chess/src/main/scala/io/github/chess/model/rules/pawn/SingleStepRule.scala
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,23 @@ | ||
/* | ||
* MIT License | ||
* Copyright (c) 2023 Cesario Jahrim Gabriele & Derevyanchenko Maxim & Felice Mirko & Kentpayeva Madina | ||
* | ||
* Full license description available at: https://github.com/jahrim/PPS-22-chess/blob/master/LICENSE | ||
*/ | ||
package io.github.chess.model.rules.pawn | ||
|
||
import io.github.chess.model.{ChessGameStatus, Move, Position, Team} | ||
import io.github.chess.model.rules.ChessRule | ||
|
||
/** Implementation of a chess rule that makes move a piece one step forward in the column. */ | ||
class SingleStepRule extends ChessRule: | ||
|
||
override def findMoves(position: Position, status: ChessGameStatus): Set[Move] = | ||
Set( | ||
Move( | ||
position, | ||
status.currentTurn match | ||
case Team.WHITE => position.rankUp() | ||
case Team.BLACK => position.rankDown() | ||
) | ||
) |
23 changes: 23 additions & 0 deletions
23
chess/src/main/scala/io/github/chess/model/rules/pawn/TwoStepRule.scala
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,23 @@ | ||
/* | ||
* MIT License | ||
* Copyright (c) 2023 Cesario Jahrim Gabriele & Derevyanchenko Maxim & Felice Mirko & Kentpayeva Madina | ||
* | ||
* Full license description available at: https://github.com/jahrim/PPS-22-chess/blob/master/LICENSE | ||
*/ | ||
package io.github.chess.model.rules.pawn | ||
|
||
import io.github.chess.model.rules.ChessRule | ||
import io.github.chess.model.{ChessGameStatus, Move, Position, Team} | ||
|
||
/** Implementation of a chess rule that makes move a piece two positions forward in the column. */ | ||
class TwoStepRule extends ChessRule: | ||
|
||
override def findMoves(position: Position, status: ChessGameStatus): Set[Move] = | ||
Set( | ||
Move( | ||
position, | ||
status.currentTurn match | ||
case Team.WHITE => position.rankUp().rankUp() | ||
case Team.BLACK => position.rankDown().rankDown() | ||
) | ||
) |
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