parent
e635bf5311
commit
e519b07cf5
@ -0,0 +1,27 @@
|
|||||||
|
import Foundation
|
||||||
|
class Game {
|
||||||
|
private let scanner: () -> Int
|
||||||
|
private let displayBoard: () -> String
|
||||||
|
private let board: Board
|
||||||
|
private let rules: IRules
|
||||||
|
private let player1: Player
|
||||||
|
private let player2: Player
|
||||||
|
|
||||||
|
init(withScanner scanner: @escaping () -> Int,
|
||||||
|
withBoard board: Board,
|
||||||
|
withRules rules: IRules,
|
||||||
|
withPlayer1 player1: Player,
|
||||||
|
withPlayer2 player2: Player) {
|
||||||
|
self.scanner = scanner
|
||||||
|
self.displayBoard = { () -> String in
|
||||||
|
return board.description
|
||||||
|
}
|
||||||
|
// TODO check that board is valid using the rules
|
||||||
|
self.board = board
|
||||||
|
self.rules = rules
|
||||||
|
self.player1 = player1
|
||||||
|
self.player2 = player2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,12 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class Bot: Player {
|
class Bot: Player {
|
||||||
override func playBetween(min: Int, andMaxIncl maxIncl: Int) -> Int {
|
|
||||||
return Int.random(in: min..<maxIncl + 1)
|
// TODO implement
|
||||||
|
// board est passé par copie, donc constant et immuable (?)
|
||||||
|
// var b = board nous donne une copie modifiable, avec laquele le bot peut faire des essais
|
||||||
|
|
||||||
|
override func chooseColumn(inBoard board: Board, withRules rules: IRules) -> Int? {
|
||||||
|
return Int.random(in: 0..<board.nbCols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,14 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
class Human: Player {
|
class Human: Player {
|
||||||
|
|
||||||
|
private let scanner: () -> Int?
|
||||||
|
|
||||||
|
init(withId id: Int, withName name: String, usingScanner scanner: @escaping () -> Int?){
|
||||||
|
self.scanner = scanner
|
||||||
|
super.init(withId: id, withName: name)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func chooseColumn(inBoard board: Board, withRules rules: IRules) -> Int? {
|
||||||
|
return scanner()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
class SmarterBot: Bot {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +1,25 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
protocol IRules {
|
public protocol IRules {
|
||||||
var minNbRows: Int { get }
|
var minNbRows: Int { get }
|
||||||
var maxNbRows: Int { get }
|
var maxNbRows: Int { get }
|
||||||
var minNbCols: Int { get }
|
var minNbCols: Int { get }
|
||||||
var maxNbCols: Int { get }
|
var maxNbCols: Int { get }
|
||||||
var nbChipsToAlign: Int { get }
|
var nbChipsToAlign: Int { get }
|
||||||
func isGameOver(byPlayer playerId: Int, onGrid grid: [[Int?]]) -> (isOver: Bool, hasWinner: Bool, victoryTiles: [(Int, Int)]?)
|
func isGameOver(byPlayer playerId: Int, onGrid grid: [[Int?]]) -> (isOver: Bool, result: Result)
|
||||||
|
// TODO plug in the EnumResult
|
||||||
|
// and
|
||||||
|
// isGameOver(c) -> (Bool, EnumResult)
|
||||||
|
// getNextPlayer(c) -> Int
|
||||||
|
// isValid(c) -> Bool
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Result {
|
||||||
|
case notOver
|
||||||
|
case deadlocked
|
||||||
|
|
||||||
|
// playerId, victoryTiles
|
||||||
|
case won(Int, [(Int, Int)]?)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue