c'est le PC qui marche pas c'est pas mon code

master
Adam BONAFOS 3 months ago
parent 908107ae3e
commit 1fde20ecd5

@ -10,4 +10,5 @@ protocol Rules {
func add(board: inout Board, position pos: (row: Int, column: Int), token: Token) -> Bool func add(board: inout Board, position pos: (row: Int, column: Int), token: Token) -> Bool
func isGameOver(board: Board) -> (result: Bool, winner: Token) func isGameOver(board: Board) -> (result: Bool, winner: Token)
func possibleMoves(board: Board) -> [(row: Int, column: Int)] func possibleMoves(board: Board) -> [(row: Int, column: Int)]
} }

@ -7,6 +7,21 @@
import Foundation import Foundation
public struct TicTacToeRules: Rules { public struct TicTacToeRules: Rules {
func possibleMoves(board: Board) -> [(row: Int, column: Int)] {
var possibleMoves: [(Int, Int)] = []
for column in 0..<board.columnNb {
for row in 0..<board.rowNb {
if board[row, column] == Token.empty {
possibleMoves.append((row, column)) // Ajouter la position (row, column)
}
}
}
return possibleMoves
}
func add(board: inout Board, position pos: (row: Int, column: Int), token: Token) -> Bool { func add(board: inout Board, position pos: (row: Int, column: Int), token: Token) -> Bool {
if board[pos.0, pos.1] == .empty { if board[pos.0, pos.1] == .empty {
board[pos.0, pos.1] = token board[pos.0, pos.1] = token
@ -20,4 +35,5 @@ public struct TicTacToeRules: Rules {
// TODO // TODO
return (false, Token.empty) return (false, Token.empty)
} }
} }

Loading…
Cancel
Save