diff --git a/DouShouQiConsole/DouShouQiConsole/main.swift b/DouShouQiConsole/DouShouQiConsole/main.swift
index 3f55375..1fd4d47 100644
--- a/DouShouQiConsole/DouShouQiConsole/main.swift
+++ b/DouShouQiConsole/DouShouQiConsole/main.swift
@@ -58,7 +58,7 @@ let initialBoardConfiguration: [[Cell]] = [
if let board = Board(withGrid: initialBoardConfiguration) {
// Afficher le plateau de jeu
- print(board.display())
+ print(board)
} else {
print("Erreur lors de l'initialisation du plateau de jeu.")
}
@@ -66,7 +66,7 @@ if let board = Board(withGrid: initialBoardConfiguration) {
// Initialisez un Board avec cette configuration
if var board = Board(withGrid: initialBoardConfiguration) {
print("Plateau initial:")
- print(board.description) // Affichez l'état initial du plateau
+ print(board) // Affichez l'état initial du plateau
// Testez countPieces(of:)
let player1PieceCount = board.countPieces(of: .player1)
@@ -82,12 +82,12 @@ if var board = Board(withGrid: initialBoardConfiguration) {
// Testez removePiece(atRow:andColumn:)
let removeResult = board.removePiece(atRow: 0, andColumn: 0)
print("Résultat de la suppression : \(removeResult)")
- print(board.description) // Affichez le plateau après suppression
+ print(board) // Affichez le plateau après suppression
// Testez insert(piece:atRow:andColumn:)
let insertResult = board.insert(piece: Piece(withOwner: .player1, andAnimal: .lion), atRow: 0, andColumn: 0)
print("Résultat de l'insertion : \(insertResult)")
- print(board.description) // Affichez le plateau après insertion
+ print(board) // Affichez le plateau après insertion
} else {
print("Erreur lors de l'initialisation du plateau de jeu.")
}
diff --git a/Extension/Sources/Extension/Board.swift b/Extension/Sources/Extension/Board.swift
index 995e0f0..e04950e 100644
--- a/Extension/Sources/Extension/Board.swift
+++ b/Extension/Sources/Extension/Board.swift
@@ -9,16 +9,20 @@ import Foundation
import Model
-public extension Board {
- func display() {
+
+extension Board: CustomStringConvertible {
+ public var description: String {
+ var description = ""
for row in grid {
for cell in row {
if let piece = cell.piece {
- print(cell.cellType.symbol + piece.owner.symbol + piece.animal.symbol, terminator: " ")}
+ description += cell.cellType.symbol + piece.owner.symbol + piece.animal.symbol + " "}
else {
- print(cell.cellType.symbol, terminator: " ")}
+ description += cell.cellType.symbol + " "}
}
- print()
+ description += "\n"
}
+ return description
}
+
}
diff --git a/Model/.swiftpm/xcode/xcshareddata/xcschemes/Model.xcscheme b/Model/.swiftpm/xcode/xcshareddata/xcschemes/Model.xcscheme
new file mode 100644
index 0000000..1ce8e7f
--- /dev/null
+++ b/Model/.swiftpm/xcode/xcshareddata/xcschemes/Model.xcscheme
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Model/.swiftpm/xcode/xcshareddata/xcschemes/ModelTests.xcscheme b/Model/.swiftpm/xcode/xcshareddata/xcschemes/ModelTests.xcscheme
new file mode 100644
index 0000000..442f5d2
--- /dev/null
+++ b/Model/.swiftpm/xcode/xcshareddata/xcschemes/ModelTests.xcscheme
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Model/Sources/Model/Animal.swift b/Model/Sources/Model/Animal.swift
index 521f6d9..5563f17 100644
--- a/Model/Sources/Model/Animal.swift
+++ b/Model/Sources/Model/Animal.swift
@@ -7,7 +7,7 @@
import Foundation
-public enum Animal: String { case rat, cat, dog, wolf, leopard, tiger, lion, elephant
+public enum Animal : CustomStringConvertible { case rat, cat, dog, wolf, leopard, tiger, lion, elephant
public var description: String {
switch self {
diff --git a/Model/Sources/Model/Board.swift b/Model/Sources/Model/Board.swift
index 732c2f7..b708550 100644
--- a/Model/Sources/Model/Board.swift
+++ b/Model/Sources/Model/Board.swift
@@ -7,10 +7,10 @@
import Foundation
-public struct Board {
- let nbRows: Int
- let nbColumns: Int
- public var grid: [[Cell]]
+public struct Board : CustomStringConvertible {
+ public let nbRows: Int
+ public let nbColumns: Int
+ public private(set) var grid: [[Cell]]
public init?(withGrid grid: [[Cell]]) {
guard let firstRowLength = grid.first?.count, grid.allSatisfy({ $0.count == firstRowLength }) else {
diff --git a/Model/Sources/Model/Cell.swift b/Model/Sources/Model/Cell.swift
index e8e2045..97acb08 100644
--- a/Model/Sources/Model/Cell.swift
+++ b/Model/Sources/Model/Cell.swift
@@ -7,7 +7,7 @@
import Foundation
-public struct Cell {
+public struct Cell : CustomStringConvertible {
public let cellType: CellType
public var initialOwner: Owner
public var piece: Piece?
diff --git a/Model/Sources/Model/CellType.swift b/Model/Sources/Model/CellType.swift
index 875102b..214b5c6 100644
--- a/Model/Sources/Model/CellType.swift
+++ b/Model/Sources/Model/CellType.swift
@@ -7,7 +7,7 @@
import Foundation
-public enum CellType {
+public enum CellType : CustomStringConvertible {
case unknown, jungle, water, trap, den
public var description: String {
diff --git a/Model/Sources/Model/Owner.swift b/Model/Sources/Model/Owner.swift
index 137d78e..0ecad93 100644
--- a/Model/Sources/Model/Owner.swift
+++ b/Model/Sources/Model/Owner.swift
@@ -7,7 +7,7 @@
import Foundation
-public enum Owner {
+public enum Owner : CustomStringConvertible {
case noOne, player1, player2
public var description: String {
diff --git a/Model/Sources/Model/Piece.swift b/Model/Sources/Model/Piece.swift
index 1d6f8c4..8cb632b 100644
--- a/Model/Sources/Model/Piece.swift
+++ b/Model/Sources/Model/Piece.swift
@@ -7,7 +7,7 @@
import Foundation
-public struct Piece {
+public struct Piece : CustomStringConvertible{
public let owner: Owner
public let animal: Animal
diff --git a/Model/Tests/ModelTests/ModelTests copy.xctestplan b/Model/Tests/ModelTests/ModelTests copy.xctestplan
new file mode 100644
index 0000000..b5ea18b
--- /dev/null
+++ b/Model/Tests/ModelTests/ModelTests copy.xctestplan
@@ -0,0 +1,24 @@
+{
+ "configurations" : [
+ {
+ "id" : "FDE4F17C-2211-4B72-BFD6-0E54DA99D1CC",
+ "name" : "Configuration 1",
+ "options" : {
+
+ }
+ }
+ ],
+ "defaultOptions" : {
+
+ },
+ "testTargets" : [
+ {
+ "target" : {
+ "containerPath" : "container:",
+ "identifier" : "ModelTests",
+ "name" : "ModelTests"
+ }
+ }
+ ],
+ "version" : 1
+}
diff --git a/README.md b/README.md
index b2d9291..28b8ba7 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,9 @@
## Introduction
Le projet DouShouQi en Swift est une implémentation console du jeu de plateau DouShouQi.
+## Correction
+Le commit à prendre en compte pour ce Tp2 est celui à 15:33
+
## Prérequis
- **Système d'exploitation**: macOS Ventura 13.1
- **Logiciel**: Xcode version 14.2