-
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 Pawn rule that lets it move one step forward.
- Loading branch information
1 parent
660030a
commit 4142951
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
chess/src/main/scala/io/github/chess/model/rules/pawn/ForwardOneRule.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,15 @@ | ||
/* | ||
* 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.{Move, Position} | ||
import io.github.chess.model.rules.ChessRule | ||
|
||
/** Implementation of the Pawn rule that makes it move one step forward. */ | ||
class ForwardOneRule extends ChessRule: | ||
|
||
override def findMoves(position: Position): Set[Move] = Set(Move(position, position.rankUp())) |
23 changes: 23 additions & 0 deletions
23
chess/src/test/scala/io/github/chess/model/rules/pawn/PawnRulesSpec.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.AbstractSpec | ||
import io.github.chess.model.Position | ||
|
||
/** Test suit for all Pawn movement rules. */ | ||
class PawnRulesSpec extends AbstractSpec: | ||
|
||
val pawnInitialPosition: Position = (0, 1) | ||
val pawnNextPosition: Position = (0, 2) | ||
|
||
"The Forward rule" should "let move the pawn only to the following rank, without changing its file" in { | ||
val oneStepRule = ForwardOneRule() | ||
val moves = oneStepRule.findMoves(pawnInitialPosition) | ||
moves should have size 1 | ||
all(moves) should have(Symbol("to")(pawnNextPosition)) | ||
} |