🛡️ Implement isValid() in rules
continuous-integration/drone/push Build is passing Details

main
Alexis Drai 2 years ago
parent 8406201908
commit 4af5705e4f

@ -12,22 +12,35 @@ public struct BasicDefaultsNoDiag : IRules {
withMinNbCols minNbCols: Int = 5,
withMaxNbCols maxNbCols: Int = 15,
withNbChipsToAlign nbChipsToAlign: Int = 4) {
guard (
minNbRows >= 3
&& minNbCols >= 3
&& maxNbRows >= minNbRows
&& maxNbCols >= minNbCols
&& nbChipsToAlign >= 2
&& nbChipsToAlign <= minNbCols
&& nbChipsToAlign <= minNbRows
) else { return nil }
self.minNbRows = minNbRows
self.maxNbRows = maxNbRows
self.minNbCols = minNbCols
self.maxNbCols = maxNbCols
self.nbChipsToAlign = nbChipsToAlign
guard (isValid(
withMinNbRows: minNbRows,
withMaxNbRows: maxNbRows,
withMinNbCols: minNbCols,
withMaxNbCols: maxNbCols,
withNbChipsToAlign: nbChipsToAlign
)) else { return nil }
}
public func isValid(withMinNbRows minNbRows: Int = 5,
withMaxNbRows maxNbRows: Int = 15,
withMinNbCols minNbCols: Int = 5,
withMaxNbCols maxNbCols: Int = 15,
withNbChipsToAlign nbChipsToAlign: Int = 4)
-> Bool {
return minNbRows >= 3
&& minNbCols >= 3
&& maxNbRows >= minNbRows
&& maxNbCols >= minNbCols
&& nbChipsToAlign >= 2
&& nbChipsToAlign <= minNbCols
&& nbChipsToAlign <= minNbRows
}
public func isGameOver(byPlayer playerId: Int, onGrid grid: [[Int?]])

@ -6,12 +6,18 @@ public protocol IRules {
var minNbCols: Int { get }
var maxNbCols: Int { get }
var nbChipsToAlign: Int { get }
func isGameOver(byPlayer playerId: Int, onGrid grid: [[Int?]]) -> (isOver: Bool, result: Result)
// TODO plug in the EnumResult
// and
// getNextPlayer(c) -> Int
// isValid(c) -> Bool
func isGameOver(byPlayer playerId: Int,
onGrid grid: [[Int?]])
-> (isOver: Bool, result: Result)
func isValid(withMinNbRows: Int,
withMaxNbRows: Int,
withMinNbCols: Int,
withMaxNbCols: Int,
withNbChipsToAlign: Int)
-> Bool
// TODO : getNextPlayer(c) -> Int (or code this in Game instead? what is c anyway? Board doesn't know the players...)
}
public enum Result : Equatable {

Loading…
Cancel
Save