-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/chanllange #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c62a880
* ✨[feat]: 도전 과제 3 구현
Roy-wonji e70f0da
* ✨[feat]: 랜덤 번호 만들기 외부에서 주입 하도록 변경
Roy-wonji 5a4114c
✨[feat]: 입력 파실 파일 분리
Roy-wonji b470816
✨[feat]: 공통으로 쓰는 거 인터페이스로 분리
Roy-wonji ff89f72
✨[feat]: 메뉴를 enum 으로 분리해서 구현
Roy-wonji eec973f
✨[feat]: 게임 기록 을 저장 하는 파일로 분리
Roy-wonji f1f7210
✨[feat]: 판별 관련 해서 파일분리
Roy-wonji 1983dc5
✨[feat]: 해당 라운드에 어떤게 판별하고 되는지 파일을 분리
Roy-wonji a1c80ef
✨[feat]: 해당 파일을 분리 하고 필요한 기능 만 구현
Roy-wonji 6f08d83
🔥[del]: 중복된 파일 삭제
Roy-wonji c0bc96f
🪛[chore]: 안쓰는 코드 삭제
Roy-wonji d0c6a07
🪛[chore]: 네이밍 리펙토링 및 리드미 추가
Roy-wonji 241ffe2
🪛[chore]: PR수정
Roy-wonji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
SpartBaseBallGame/SpartBaseBallGame/Sources/Answer/AnswerGeneratorProtocol.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // | ||
| // AnswerGeneratorProtocol.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| protocol AnswerGeneratorProtocol { | ||
| func make(digits: Int) -> [Int] | ||
| } |
18 changes: 18 additions & 0 deletions
18
SpartBaseBallGame/SpartBaseBallGame/Sources/Answer/RandomAnswerGenerator.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // | ||
| // RandomAnswerGenerator.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
|
|
||
| struct RandomAnswerGenerator: AnswerGeneratorProtocol, Sendable { | ||
| func make(digits: Int) -> [Int] { | ||
| let first = Int.random(in: 1...9) | ||
| var pool = Array(0...9).filter { $0 != first } | ||
| pool.shuffle() | ||
| return [first] + Array(pool.prefix(digits - 1)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
SpartBaseBallGame/SpartBaseBallGame/Sources/GameStart/GameManger.swift
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
SpartBaseBallGame/SpartBaseBallGame/Sources/GuessParser/GuessParser.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // | ||
| // GuessParser.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| /// 1) Parser: 입력 파싱 | ||
| struct GuessParser: Sendable { | ||
| let digits: Int | ||
| let forbidLeadingZero: Bool | ||
|
|
||
| init(digits: Int, forbidLeadingZero: Bool = true) { | ||
| precondition((1...10).contains(digits)) | ||
| self.digits = digits | ||
| self.forbidLeadingZero = forbidLeadingZero | ||
| } | ||
|
|
||
| // MARK: - 입력 파싱 | ||
| func parse(_ input: String) -> [Int]? { | ||
| let trimmed = input.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard trimmed.count == digits, trimmed.allSatisfy(\.isNumber) else { return nil } | ||
| if forbidLeadingZero && trimmed.first == "0" { return nil } | ||
| let nums = trimmed.compactMap { Int(String($0)) } | ||
| guard Set(nums).count == digits else { return nil } // 중복 금지 | ||
| return nums | ||
| } | ||
| } | ||
|
|
||
22 changes: 22 additions & 0 deletions
22
SpartBaseBallGame/SpartBaseBallGame/Sources/Interface/ConsoleIO.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // | ||
| // ConsoleIO.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
| import LogMacro | ||
|
|
||
| struct ConsoleIO: IOProvider { | ||
| func show(_ message: String) { | ||
| #logDebug(message) | ||
| } | ||
|
|
||
| // MARK: - readLine 비동기 래핑 | ||
| func readLine() async -> String? { | ||
| await withCheckedContinuation { continuation in | ||
| Task.detached { continuation.resume(returning: Swift.readLine()) } | ||
| } | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
SpartBaseBallGame/SpartBaseBallGame/Sources/Interface/IOProvider.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // | ||
| // IOProvider.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| protocol IOProvider { | ||
| func show(_ message: String) | ||
| func readLine() async -> String? | ||
| } |
20 changes: 20 additions & 0 deletions
20
SpartBaseBallGame/SpartBaseBallGame/Sources/Judge/JudgeEngine.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // JudgeEngine.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| /// 2) Judge: 판정 로직 | ||
| struct JudgeEngine: Sendable { | ||
| func judge(answer: [Int], guess: [Int]) -> JudgeResult { | ||
| let strike = zip(answer, guess).filter { $0 == $1 }.count | ||
| let ball = Set(answer).intersection(guess).count - strike | ||
| if strike == answer.count { return .correct } | ||
| if strike == .zero && ball == .zero { return .nothing } | ||
| return .strikeAndBall(strike: strike, ball: ball) | ||
| } | ||
| } | ||
|
|
31 changes: 31 additions & 0 deletions
31
SpartBaseBallGame/SpartBaseBallGame/Sources/Menu/MenuAction.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // | ||
| // MenuAction.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum MenuType { | ||
| case startGame, showRecords, quit, invalid | ||
| } | ||
|
|
||
| struct MenuAction: Sendable { | ||
| func ask(using io: IOProvider) async -> MenuType { | ||
| io.show(""" | ||
| 환영합니다! 원하시는 번호를 입력해주세요 | ||
| 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 | ||
| """, ) | ||
|
|
||
| guard let line = await io.readLine()?.trimmingCharacters(in: .whitespacesAndNewlines), | ||
| let menuNumber = Int(line) else { return .invalid } | ||
|
|
||
| switch menuNumber { | ||
| case 1: return .startGame | ||
| case 2: return .showRecords | ||
| case 3: return .quit | ||
| default: return .invalid | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
SpartBaseBallGame/SpartBaseBallGame/Sources/Record/GameRecord.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // | ||
| // GameRecord.swift | ||
| // SpartBaseBallGame | ||
| // | ||
| // Created by Wonji Suh on 8/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| // MARK: - 기록 저장/출력 | ||
| actor GameRecord: Sendable { | ||
| private(set) var items: [Int] = [] | ||
|
|
||
| func saveRecord(_ attempts: Int) async { | ||
| items.append(attempts) | ||
| } | ||
|
|
||
| func isEmpty() -> Bool { | ||
| items.isEmpty | ||
| } | ||
|
|
||
| func showRecords(using console: IOProvider) async { | ||
| console.show("< 게임 기록 보기 >") | ||
| if items.isEmpty { | ||
| console.show("완료된 게임 기록이 없습니다.") | ||
| return | ||
| } | ||
| for (idx, tries) in items.enumerated() { | ||
| console.show("\(idx + 1)번째 게임 : 시도 횟수 - \(tries)") | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 앞자리를 0을 받느냐 아니냐에 대한 것이죠 ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Peter1119 네