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
step1: 지뢰 찾기(그리기) #265
base: sjjeong
Are you sure you want to change the base?
step1: 지뢰 찾기(그리기) #265
Conversation
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.
안녕하세요. 지뢰찾기 미션동안 잘 부탁드립니다. 🦀
다른 미션들과 병행하느라 많이 힘드실텐데 응원하겠습니다.
몇가지 의견을 남겨드렸으니 확인 부탁드립니다. 💪🏻
fun showInputHeight() { | ||
println("높이를 입력하세요.") | ||
} | ||
|
||
fun showInputWidth() { | ||
println("너비를 입력하세요.") | ||
} | ||
|
||
fun showInputMineCount() { | ||
println("지뢰는 몇 개인가요?") | ||
} |
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.
입력을 받기 위한 출력을 OutputView에서 결정하고 있습니다.
만약 입력 소스가 콘솔이 아닌 키오스크, GUI 등 다른 입력으로 결정된다면 어떻게 될까요?
입력을 받는 입력 채널, 결과를 내보내는 출력 채널 이라는 의미로 생각 해보면 어떨까요?
그것을 구현하는 방법이 콘솔이니까요
@Test | ||
internal fun `지뢰판의 높이는 0보다 커야 한다`() { | ||
shouldThrow<IllegalArgumentException> { | ||
Minesweeper(size = Size(height = 0, width = 1), mineCount = 1) | ||
} | ||
} | ||
|
||
@Test | ||
internal fun `지뢰판의 너비는 0보다 커야 한다`() { | ||
shouldThrow<IllegalArgumentException> { | ||
Minesweeper(size = Size(height = 1, width = 0), mineCount = 1) | ||
} | ||
} |
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.
항상 양의 정수를 가지고 있는 역할은 Size에서 구현을 하면 어떨까요?
Size가 논리적으로 음수를 가지지는 않을 것이라고 생각합니다
while (minePositionList.size < mineCount) { | ||
val position = Position((0 until size.height).random(), (0 until size.width).random()) | ||
if (minePositionList.contains(position)) { | ||
continue | ||
} | ||
minePositionList.add(position) | ||
} |
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.
게임에 대한 진행 상황을 테스트 하기 위해 지뢰게임 판을 준비해야 할 경우가 생길 수 있습니다.
특정 위치에 지뢰가 있을 때 ~
등의 동작을 테스트 하려면 어떻게 할 수 있을까요?
지난 미션들에서 해왔던 랜덤이라는 불확실성을 테스트 가능하도록 만드는 방법을 사용할 수 있을까요?
while (minePositionList.size < mineCount) { | ||
val position = Position((0 until size.height).random(), (0 until size.width).random()) | ||
if (minePositionList.contains(position)) { | ||
continue | ||
} | ||
minePositionList.add(position) | ||
} |
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.
현재 지뢰를 심는 알고리즘에서는 같은 값이 나올때마다 불필요한 반복을 하게 됩니다.
가로, 세로가 주어졌을 때 랜덤으로 지뢰의 위치들을 만들어서 반환하도록 하면 어떨까요?
로또 미션에서 45번까지의 숫자를 랜덤하게 6번 뽑는 로직과 비슷합니다.
shuffle()
과 take()
를 활용 해보세요
override fun toString(): String { | ||
val stringBuilder = StringBuilder() | ||
for (i in 0 until size.height) { | ||
for (j in 0 until size.width) { | ||
val position = Position(i, j) | ||
if (minePositionList.contains(position)) { | ||
stringBuilder.append("*") | ||
} else { | ||
stringBuilder.append("C") | ||
} | ||
if (j == size.width - 1) { | ||
stringBuilder.append("\n") | ||
} else { | ||
stringBuilder.append(" ") | ||
} | ||
} | ||
} | ||
return stringBuilder.toString() | ||
} |
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.
지뢰 및 보드를 출력하는 것은 UI의 관심사로 보입니다.
MineSweeper가 루트 패키지에 있는데 도메인 모델로 구현한 의도가 아닐까요?
잘 부탁 드립니다