Skip to content

Commit

Permalink
fix: solve pawns not being able to capture on File H
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-derevyanchenko committed Feb 27, 2023
1 parent 7523a32 commit 6a0f937
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Expand Up @@ -9,4 +9,4 @@ package io.github.chess.model.rules.prolog
import io.github.chess.model.rules.prolog.PrologRule

/** Class representing the prolog rule that finds all capture moves of a black pawn. */
class BlackPawnCaptureRule extends PrologRule("black_pawn_capture") with InsideBoardRule()
class BlackPawnCaptureRule extends PrologRule("black_pawn_capture") with InsideBoardFilterRule()
@@ -0,0 +1,19 @@
/*
* 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.prolog

import io.github.chess.model.Position

/**
* Represents an alternative rule to [[InsideBoardRule]] rule that limits
* the positions inside the board by filtering.
*/
trait InsideBoardFilterRule(private val maxX: Int = 7, private val maxY: Int = 7)
extends PrologRule:

abstract override def findPositions(position: Position): LazyList[(Int, Int)] =
super.findPositions(position).filter((x, y) => x >= 0 && x <= maxX && y >= 0 && y <= maxY)
Expand Up @@ -9,4 +9,4 @@ package io.github.chess.model.rules.prolog
import io.github.chess.model.rules.prolog.PrologRule

/** Class representing the prolog rule that finds all capture moves of a white pawn. */
class WhitePawnCaptureRule extends PrologRule("white_pawn_capture") with InsideBoardRule()
class WhitePawnCaptureRule extends PrologRule("white_pawn_capture") with InsideBoardFilterRule()

0 comments on commit 6a0f937

Please sign in to comment.