Redesign des colonnes

main
Mathis RIBEMONT 2 years ago
parent 8bd0b38862
commit 2c77207c43

@ -11,7 +11,7 @@ public struct Board: CustomStringConvertible {
var grid: [[Int?]];
let nbRows: Int;
let nbColumns: Int;
private static let descriptionMapper: [Int?:String] = [nil:"-", 1:"O", 2:"X"];
private static let descriptionMapper: [Int?:String] = [nil:" ", 1:"O", 2:"X"];
public init?(nbR: Int = 6, nbC: Int = 7) {
if nbR <= 0 || nbC <= 0 {
@ -43,17 +43,30 @@ public struct Board: CustomStringConvertible {
var string = String()
for row in grid {
string.append("| ")
for cell in row {
string.append("\(String(describing: Board.descriptionMapper[cell] ?? "-")) ")
string.append("\(String(describing: Board.descriptionMapper[cell] ?? " "))")
string.append(" | ")
}
string.append("\n")
}
string.append("|")
for i in 0...grid.count{
string.append("---|")
}
string.append("\n")
string.append("|")
for i in 0...grid.count{
string.append(" \(i) |")
}
return string
}
private func isFull() -> Bool {
for column in 0..<nbColumns{
for column in 0...nbColumns{
if !isColumnFull(column: column) {
return false
}

@ -12,6 +12,7 @@ public struct Game {
private var players: [Player]
private var numero: Int = 0
private var afficheur: Afficheur
private var winner: Player?
public init?(withBoard board: Board, playedBy players: [Player], writeOn afficheur: Afficheur) {
self.board = board
@ -60,4 +61,8 @@ public struct Game {
public mutating func joueurSuivant() {
numero = (numero + 1) % players.count
}
public func getWinner() -> Player? {
return winner;
}
}

@ -12,6 +12,7 @@ public class Human : Player {
public var board: Board
private var lecteur: Lecteur
// au lieu du protocol Lecteur, prendre une fonction qui sera appelé à chaque fois si on ne veux qu'une seul méthode (c'est une closure, si on la stock, on doit mettre @escaping en paramètre). On peut stocker une méthode optionnel
public init(named name: String, playedOn board: Board, readOn lecteur: Lecteur){
self.name = name
self.board = board

@ -7,17 +7,17 @@
import Foundation
class IA: Player {
var name: String
public class IA: Player {
public var name: String
var board: Board
public var board: Board
init(named name: String, playedOn board: Board){
public init(named name: String, playedOn board: Board){
self.name = name
self.board = board
}
func playInColumn() -> Int {
public func playInColumn() -> Int {
return Int.random(in: 0..<(board.nbColumns))
}

@ -7,6 +7,11 @@
import Foundation
// en static, le nombre de ligne, de colonne, et de case à aligner
// méthode createBoard, ou alors permettre de vérifier si la board est valid
// isValid(column) , IsGameOver(column),
// Pour avoir une collection de règles, créer une règle qui étend ce protocol, et qui contiendra une liste de rules, qui elles vont faire la logique. Ca permettra de juger les priorités des règles.
public protocol Rule {
func executeRule() -> Bool
func executeRule(onBoard board: Board, lastPieceX x: Int) -> Bool
}

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EC62D5D02976881000CAB764"
BuildableName = "puissance4"
BlueprintName = "puissance4"
ReferencedContainer = "container:puissance4.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
viewDebuggingEnabled = "No">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EC62D5D02976881000CAB764"
BuildableName = "puissance4"
BlueprintName = "puissance4"
ReferencedContainer = "container:puissance4.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EC62D5D02976881000CAB764"
BuildableName = "puissance4"
BlueprintName = "puissance4"
ReferencedContainer = "container:puissance4.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

@ -10,5 +10,13 @@
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>EC62D5D02976881000CAB764</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

@ -27,11 +27,15 @@ let afficheur = Afficheur()
var b = Board()
if let board = b {
let player1 = Human(named: "Bingeamain", playedOn: board, readOn: lecteur)
let player2 = Human(named: "illeauhanne", playedOn: board, readOn: lecteur)
//let player2 = Human(named: "illeauhanne", playedOn: board, readOn: lecteur)
let player2 = IA(named: "Géraimiedepain", playedOn: board)
var game = Game(withBoard: board, playedBy: [player1, player2], writeOn: afficheur)
while true {
var winner : Player?
while game?.getWinner() == nil {
game?.tour()
}
afficheur.afficherLigne(message: "Le gagnant est \(winner?.name)")
}

Loading…
Cancel
Save