|
|
@ -31,14 +31,12 @@ public class Game {
|
|
|
|
public var gameOverString: String {
|
|
|
|
public var gameOverString: String {
|
|
|
|
var string = "Game over"
|
|
|
|
var string = "Game over"
|
|
|
|
|
|
|
|
|
|
|
|
switch(rules.isGameOver(byPlayer: getCurrentPlayerId(),
|
|
|
|
let gameOverResult = rules.isGameOver(byPlayer: getCurrentPlayerId(),
|
|
|
|
onGrid: board.grid).result) {
|
|
|
|
onGrid: board.grid).result
|
|
|
|
case .won(let playerId, let victoryTiles):
|
|
|
|
if case .won(let playerId, let victoryTiles) = gameOverResult {
|
|
|
|
string.append("\nPlayer \(playerId) won!\n")
|
|
|
|
string.append("\nPlayer \(playerId) won!\n")
|
|
|
|
string.append(board.displayVictory(fromTiles: victoryTiles))
|
|
|
|
string.append(board.displayVictory(fromTiles: victoryTiles))
|
|
|
|
default: break; // nothing
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return string
|
|
|
|
return string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -47,7 +45,11 @@ public class Game {
|
|
|
|
let currentPlayer = {
|
|
|
|
let currentPlayer = {
|
|
|
|
if(rules.getNextPlayer(fromGrid: board.grid,
|
|
|
|
if(rules.getNextPlayer(fromGrid: board.grid,
|
|
|
|
withPlayer1Id: player1.id,
|
|
|
|
withPlayer1Id: player1.id,
|
|
|
|
withPlayer2Id: player2.id) == player1.id) { return player1 } else { return player2 }
|
|
|
|
withPlayer2Id: player2.id) == player1.id) {
|
|
|
|
|
|
|
|
return player1
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return player2
|
|
|
|
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
if let chosenCol = currentPlayer.chooseColumn(inBoard: board,
|
|
|
|
if let chosenCol = currentPlayer.chooseColumn(inBoard: board,
|
|
|
@ -60,7 +62,10 @@ public class Game {
|
|
|
|
private func getCurrentPlayerId() -> Int {
|
|
|
|
private func getCurrentPlayerId() -> Int {
|
|
|
|
if(rules.getNextPlayer(fromGrid: board.grid,
|
|
|
|
if(rules.getNextPlayer(fromGrid: board.grid,
|
|
|
|
withPlayer1Id: player1.id,
|
|
|
|
withPlayer1Id: player1.id,
|
|
|
|
withPlayer2Id: player2.id) == player1.id) { return player2.id } else { return player1.id }
|
|
|
|
withPlayer2Id: player2.id) == player1.id) {
|
|
|
|
|
|
|
|
return player2.id
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return player1.id
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|