-
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.
fix: remove pawn moves dependency on the turn and remove capture move…
…s with no adversaries
- Loading branch information
1 parent
ec60220
commit 28bea0d
Showing
9 changed files
with
128 additions
and
37 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
29 changes: 29 additions & 0 deletions
29
chess/src/main/scala/io/github/chess/model/moves/DoubleMove.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,29 @@ | ||
/* | ||
* 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.moves | ||
|
||
import io.github.chess.model.Position | ||
|
||
/** Represents the moving of a pawn by two steps forward. */ | ||
trait DoubleMove extends Move | ||
|
||
/** Factory for [[DoubleMove]] instances. */ | ||
object DoubleMove: | ||
|
||
/** | ||
* Creates a double move, using the two needed positions. | ||
* | ||
* @param from source [[Position]] | ||
* @param to target [[Position]] | ||
* @return a new [[DoubleMove]] | ||
*/ | ||
def apply(from: Position, to: Position): DoubleMove = PawnDoubleMove(from, to) | ||
|
||
private case class PawnDoubleMove( | ||
override val from: Position, | ||
override val to: Position | ||
) extends DoubleMove |
26 changes: 26 additions & 0 deletions
26
chess/src/main/scala/io/github/chess/model/rules/chess/BaseCaptureRule.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,26 @@ | ||
/* | ||
* 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.chess | ||
|
||
import io.github.chess.model.moves.{CaptureMove, Move} | ||
import io.github.chess.model.rules.chess.ChessRule | ||
import io.github.chess.model.{ChessGameStatus, Position, Team} | ||
|
||
/** Mixin that checks in which positions, among the found moves, there are enemy pieces, to perform the capture. */ | ||
trait BaseCaptureRule extends ChessRule: | ||
|
||
abstract override def findMoves(position: Position, status: ChessGameStatus): Set[Move] = | ||
super | ||
.findMoves(position, status) | ||
.filter(move => | ||
status.chessBoard.pieces.get(position) match | ||
case Some(piece) => | ||
piece.team match | ||
case Team.WHITE => status.chessBoard.blackPieces.contains(move.to) | ||
case Team.BLACK => status.chessBoard.whitePieces.contains(move.to) | ||
case None => false | ||
) |
24 changes: 24 additions & 0 deletions
24
chess/src/main/scala/io/github/chess/model/rules/chess/pawn/PawnCaptureMoves.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,24 @@ | ||
/* | ||
* 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.chess.pawn | ||
|
||
import io.github.chess.model.moves.Move | ||
import io.github.chess.model.rules.chess.{ChessRule, RuleShorthands} | ||
import io.github.chess.model.rules.prolog.{BlackPawnCaptureRule, WhitePawnCaptureRule} | ||
import io.github.chess.model.{ChessGameStatus, Position, Team, moves} | ||
|
||
/** Finds all moves with which a pawn can capture an adversary piece. */ | ||
class PawnCaptureMoves extends ChessRule with RuleShorthands: | ||
|
||
override def findMoves(position: Position, status: ChessGameStatus): Set[Move] = | ||
status.chessBoard.pieces.get(position) match | ||
case Some(piece) => | ||
(piece.team match | ||
case Team.WHITE => WhitePawnCaptureRule() | ||
case Team.BLACK => BlackPawnCaptureRule() | ||
).findPositions(position).map(Move(position, _)).toSet | ||
case None => Set.empty |
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
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