🚧 WIP on protocols for rules

main
Alexis Drai 2 years ago
parent e37c869821
commit eef5a45899

@ -0,0 +1,46 @@
import Foundation
public struct BasicDefaultsNoDiag : IRules {
var minNbRows: Int
var maxNbRows: Int
var minNbCols: Int
var maxNbCols: Int
var nbChipsToAlign: Int
func isGameOver(byPlayer playerId: Int, ontGrid grid: [[Int?]]) -> (isOver: Bool, hasWinner: Bool, victoryTiles: [(Int?, Int?)]) {
var tiles : [(Int?, Int?)] = Array(repeating: (nil, nil), count: nbChipsToAlign)
/*
game over?
winner exists?
return (true, true, tiles)
else
return (true, false, tiles) (all tiles at nil)
else
return (false, false, tiles) (all tiles at nil)
*/
return (isOver: false, hasWinner: false, victoryTiles: tiles);
}
init?(withMinNbRows minNbRows: Int = 0,
withMaxNbRows maxNbRows: Int = 15,
withMaxNbCols minNbCols: Int = 0,
withMaxNbCols maxNbCols: Int = 15,
withNbChipsToAlign nbChipsToAlign: Int = 4) {
self.minNbRows = minNbRows
self.maxNbRows = maxNbRows
self.minNbCols = minNbCols
self.maxNbCols = maxNbCols
self.nbChipsToAlign = nbChipsToAlign
}
}

@ -1,5 +1,6 @@
import Foundation import Foundation
//TODO implement Equatable?
public struct Board : CustomStringConvertible { public struct Board : CustomStringConvertible {
public let nbRows: Int public let nbRows: Int

@ -0,0 +1,10 @@
import Foundation
protocol IRules {
var minNbRows: Int { get }
var maxNbRows: Int { get }
var minNbCols: Int { get }
var maxNbCols: Int { get }
var nbChipsToAlign: Int { get }
func isGameOver(byPlayer playerId: Int, ontGrid grid: [[Int?]]) -> (isOver: Bool, hasWinner: Bool, victoryTiles: [(Int?, Int?)])
}
Loading…
Cancel
Save