🔥 🧑‍💻 🐛 🔥 ........
continuous-integration/drone/push Build is passing Details

main
Alexis Drai 2 years ago
parent e54877263d
commit 3041f7d31d

@ -12,40 +12,30 @@ public func scan() -> Int {
}
var status: (isOver: Bool, result: Result)
print("nothing yet")
if let rules = BasicDefaultsNoDiag() {
print("rules")
if let board = Board() {
print("board")
if let human = Human(withId: 1,
if let p1 = Human(withId: 1,
withName: "Geraldine Humanman",
usingScanner: scan) {
print("human")
if let bot = Bot(withId: 2,
if let p2 = Bot(withId: 2,
withName: "Botty McBotFace") {
print("bot")
if let game = Game(withScanner : scan,
withBoard: board,
withRules: rules,
withPlayer1: human,
withPlayer2: bot) {
print("game")
withPlayer1: p1,
withPlayer2: p2) {
status = game.isOver
print(game.displayBoard()) // 1st turn
while(!(status.isOver)) {
print(game.boardString) // 1st turn
while(!(game.isOver)) {
if game.play() {
print(game.displayBoard())
status = game.isOver
print(game.boardString)
}
}
print(game.gameOverString)
}
}
}

@ -1,7 +1,6 @@
import Foundation
public class Game {
private let scanner: () -> Int
public let displayBoard: () -> String
private var board: Board
private let rules: IRules
private let player1: Player
@ -13,9 +12,6 @@ public class Game {
withPlayer1 player1: Player,
withPlayer2 player2: Player) {
self.scanner = scanner
self.displayBoard = { () -> String in
return board.description
}
guard(rules.isValid(board)) else { return nil }
self.board = board
self.rules = rules
@ -23,15 +19,20 @@ public class Game {
self.player2 = player2
}
public var isOver: (isOver: Bool, result: Result) {
public var isOver: Bool {
return rules.isGameOver(byPlayer: getCurrentPlayerId(),
onGrid: board.grid)
onGrid: board.grid).isOver
}
public var boardString: String {
return board.description
}
public var gameOverString: String {
var string = "Game over"
switch(isOver.result) {
switch(rules.isGameOver(byPlayer: getCurrentPlayerId(),
onGrid: board.grid).result) {
case .won(let playerId, let victoryTiles):
string.append("\nPlayer \(playerId) won!\n")
string.append(board.displayVictory(fromTiles: victoryTiles))

@ -14,7 +14,7 @@ public class Bot: Player {
public override func chooseColumn(inBoard board: Board,
withRules rules: IRules)
-> Int? {
print("(^°w°)")
print("(\(id)°w°)")
return Int.random(in: 0..<board.nbCols)
}
}

Loading…
Cancel
Save