|
|
|
@ -10,11 +10,11 @@ public struct Connect4Rules : Rules {
|
|
|
|
|
|
|
|
|
|
let piecesToAlign: Int
|
|
|
|
|
|
|
|
|
|
init(piecesToAlign: Int) {
|
|
|
|
|
public init(piecesToAlign: Int) {
|
|
|
|
|
self.piecesToAlign = piecesToAlign
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func add(board: inout Board, position pos: (row: Int, column: Int), token: Token) -> Bool {
|
|
|
|
|
public func add(board: inout Board, position pos: (row: Int, column: Int), token: Token) -> Bool {
|
|
|
|
|
var currentRowNb = 0;
|
|
|
|
|
for var row in board.grid {
|
|
|
|
|
if row[pos.column] != Token.empty && currentRowNb != 0 {
|
|
|
|
@ -26,7 +26,7 @@ public struct Connect4Rules : Rules {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isGameOver(board: Board) -> (result: Bool, winner: Token) {
|
|
|
|
|
public func isGameOver(board: Board) -> (result: Bool, winner: Token) {
|
|
|
|
|
// Vérification générale avec le nombre de pièces à aligner
|
|
|
|
|
let maxRow = board.rowNb
|
|
|
|
|
let maxCol = board.columnNb
|
|
|
|
@ -95,4 +95,20 @@ public struct Connect4Rules : Rules {
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func possibleMoves(board: Board) -> [(row: Int, column: Int)] {
|
|
|
|
|
var possibleMoves: [(Int, Int)] = []
|
|
|
|
|
|
|
|
|
|
for column in 0..<board.columnNb {
|
|
|
|
|
// Trouver la première case vide en partant du bas de la colonne
|
|
|
|
|
for row in (0..<board.rowNb).reversed() {
|
|
|
|
|
if board[row, column] == Token.empty {
|
|
|
|
|
possibleMoves.append((row, column)) // Ajouter la position (row, column)
|
|
|
|
|
break // Une fois trouvé, on passe à la colonne suivante
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return possibleMoves
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|