From 1c45aa447d51663c4bdf0518f61e9e57577aca06 Mon Sep 17 00:00:00 2001 From: Mathieu GROUSSEAU Date: Mon, 10 Feb 2025 17:41:58 +0100 Subject: [PATCH] Grid column numbers --- CLI/CLI/main.swift | 2 -- CustomTypes/Sources/CustomTypes/Display.swift | 20 ++++++++++++++++++- Model/Sources/Model/Game.swift | 2 -- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CLI/CLI/main.swift b/CLI/CLI/main.swift index 16ef892..2cc1e20 100644 --- a/CLI/CLI/main.swift +++ b/CLI/CLI/main.swift @@ -104,8 +104,6 @@ encoder.userInfo[.gameDecodingContext] = CodableContext() let data = try encoder.encode(CodableGameWrapper(of: game)) -print(String(data: data, encoding: .utf8)!) - var decoder = JSONDecoder() decoder.userInfo[.gameDecodingContext] = CodableContext(creatingCallbacks: { name, type in playerPrompt }) let game2 = (try decoder.decode(CodableGameWrapper.self, from: data)).game diff --git a/CustomTypes/Sources/CustomTypes/Display.swift b/CustomTypes/Sources/CustomTypes/Display.swift index 45ff281..f5612ed 100644 --- a/CustomTypes/Sources/CustomTypes/Display.swift +++ b/CustomTypes/Sources/CustomTypes/Display.swift @@ -4,7 +4,18 @@ extension Board { public func display(winCells: [Coords]) -> String { var str = String() + let rows = Self.numbers(size: self.rows) + let columns = Self.numbers(size: self.columns) + for row in 0.. (nums: [String], size: Int) { + let elems = Array((1...size).map { String($0) }) + let size = max(2, elems.lazy.map { $0.count }.max() ?? 0) + return (nums: elems.map { String(repeating: " ", count: size - $0.count) + $0 }, size: size ) + } } extension Board: CustomStringConvertible, CustomDebugStringConvertible { diff --git a/Model/Sources/Model/Game.swift b/Model/Sources/Model/Game.swift index dbbd926..8479b2b 100644 --- a/Model/Sources/Model/Game.swift +++ b/Model/Sources/Model/Game.swift @@ -115,8 +115,6 @@ public struct Event { self.listeners.append(listener) } - // func dynamicallyCall(withArguments args: [Int]) -> Int { return args.count } - func dynamicallyCall(withArguments args: [Param]) -> Void { for param in args { for listener in self.listeners {