Skip to content

Commit

Permalink
feat: add Pawn rule that lets it move one step forward.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-derevyanchenko authored and mirko-felice committed Feb 20, 2023
1 parent 660030a commit 4142951
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
@@ -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()))
@@ -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))
}

0 comments on commit 4142951

Please sign in to comment.