-
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: create diagonal rules + create bishop
- Loading branch information
1 parent
db6013f
commit 44a78ce
Showing
8 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
south_east(Xs, Ys, X, Y) :- south_east(Xs, Ys, 1, X, Y) . | ||
|
||
south_east(Xs, Ys, N, X, Y) :- X is Xs + N, Y is Ys - N . | ||
|
||
south_east(Xs, Ys, N, X, Y) :- N1 is N + 1, south_east(Xs, Ys, N1, X, Y) . |
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,5 @@ | ||
south_west(Xs, Ys, X, Y) :- south_west(Xs, Ys, 1, X, Y) . | ||
|
||
south_west(Xs, Ys, N, X, Y) :- X is Xs - N, Y is Ys - N . | ||
|
||
south_west(Xs, Ys, N, X, Y) :- N1 is N + 1, south_west(Xs, Ys, N1, X, Y) . |
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,28 @@ | ||
/* | ||
* 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 | ||
|
||
import io.github.chess.model.rules.{ChessRule, DiagonalRule} | ||
|
||
/** Represents the particular piece of the bishop. */ | ||
trait Bishop extends Piece | ||
|
||
/** Factory for [[Bishop]] instances. */ | ||
object Bishop: | ||
|
||
/** | ||
* Creates a new bishop. | ||
* @return a new [[Bishop]] | ||
*/ | ||
def apply(): Bishop = SimpleBishop() | ||
|
||
private case class SimpleBishop() extends Bishop: | ||
|
||
override val rule: ChessRule = DiagonalRule() | ||
|
||
// TODO da rimuovere | ||
override def findMoves(position: Position): Set[Position] = ??? |
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
32 changes: 32 additions & 0 deletions
32
chess/src/main/scala/io/github/chess/model/rules/DiagonalRule.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,32 @@ | ||
/* | ||
* 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.{Move, Position} | ||
|
||
/** Represents the chess rule that can find all the moves in diagonal directions, analyzing the status. */ | ||
class DiagonalRule extends ChessRule: | ||
|
||
private val northWestRule = NWPrologRule() | ||
private val northEastRule = NEPrologRule() | ||
private val southWestRule = SouthWestRule() | ||
private val southEastRule = SouthEastRule() | ||
|
||
override def findMoves(position: Position): Set[Move] = | ||
reduceInsideBoard(northWestRule.findPositions(position), position) ++ | ||
reduceInsideBoard(northEastRule.findPositions(position), position) ++ | ||
reduceInsideBoard(southWestRule.findPositions(position), position) ++ | ||
reduceInsideBoard(southEastRule.findPositions(position), position) | ||
|
||
private def reduceInsideBoard( | ||
infiniteDirectionPositions: LazyList[(Int, Int)], | ||
position: Position | ||
): Set[Move] = | ||
infiniteDirectionPositions | ||
.takeWhile((x, y) => x >= 0 && x <= 7 && y >= 0 && y <= 7) | ||
.map(Move(position, _)) | ||
.toSet |
12 changes: 12 additions & 0 deletions
12
chess/src/main/scala/io/github/chess/model/rules/SouthEastRule.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,12 @@ | ||
/* | ||
* 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.PrologEngine | ||
|
||
/** Represents the prolog rule to find all the coordinates in the south east direction from a starting position. */ | ||
class SouthEastRule extends PrologRule("south_east") |
12 changes: 12 additions & 0 deletions
12
chess/src/main/scala/io/github/chess/model/rules/SouthWestRule.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,12 @@ | ||
/* | ||
* 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.PrologEngine | ||
|
||
/** Represents the prolog rule to find all the coordinates in the south west direction from a starting position. */ | ||
class SouthWestRule extends PrologRule("south_west") |