Skip to content
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

[STEP 4] ๐Ÿ’ฃ์ง€๋ขฐ์ฐพ๊ธฐ๐Ÿ’ฅ ๋ฆฌํŒฉํ„ฐ๋ง #492

Open
wants to merge 47 commits into
base: y2gcoder
Choose a base branch
from

Conversation

y2gcoder
Copy link

์•ˆ๋…•ํ•˜์„ธ์š” ๋‚จ์ค€๋‹˜!

์˜ค๋žœ๋งŒ์— ์ธ์‚ฌ๋“œ๋ฆฌ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค๐Ÿ˜…

ํฌ๋ฆฌ์Šค๋งˆ์Šค๋Š” ์ž˜ ๋ณด๋‚ด์…จ๋Š”์ง€์š”?๐ŸŽ„

๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„๋‹ค ๋ณด๋‹ˆ ๊ทธ๋™์•ˆ ๋ฐฐ์› ๋˜ ๊ฑธ ์ ์šฉํ•ด๋ณด๊ณ ์ž ๋…ธ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค!

ํ•ญ์ƒ ์–‘์งˆ์˜ ํ”ผ๋“œ๋ฐฑ ์ฃผ์‹œ๋Š” ๋‚จ์ค€๋‹˜๊ป˜ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค๐Ÿ‘

ํฌ๊ธฐํ•˜์ง€ ์•Š๊ณ  ๋งˆ๋ฌด๋ฆฌ๊นŒ์ง€ ์—ด์‹ฌํžˆ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

์–‘์˜๊ทผ ์˜ฌ๋ฆผ

- open() ๋ฉ”์„œ๋“œ ๊ฐ„์†Œํ™”: findAllShouldOpen()์œผ๋กœ ์ฑ…์ž„ ์ด์ „
- findAllShouldOpen(): BFS๋ฅผ ํ†ตํ•ด ์—ด์–ด์•ผ ํ•  Set<Location> ๊ณ„์‚ฐ
- applyOpen(): Set<Location>์„ ์ธ๋ฑ์Šค ๊ธฐ๋ฐ˜ Set ์œผ๋กœ ๋ณ€๊ฒฝ && ๊ฐ€๋ณ€ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€๊ฒฝํ•ด์„œ ๊ณ„์‚ฐ ํ›„ ๋ถˆ๋ณ€ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ˜ํ™˜ํ•จ์œผ๋กœ์จ ์„ฑ๋Šฅ ํ–ฅ์ƒ
@namjackson
Copy link

์•„๋ฌด๋ž˜๋„ ๋ฆฌํŒฉํ„ฐ๋ง ๊ณผ์ •์ด๋ผ์„œ, ํฌ๊ฒŒ ์ฝ”๋ฉ˜ํŠธ ๋“œ๋ฆด๋ถ€๋ถ„์ด ์—†์„๊ฑฐ๊ฐ™์•„์š” :)
์ด๋Œ€๋กœ ๋งˆ๋ฌด๋ฆฌ ํ•˜์‹œ๋ ค๋ฉด ๊ทธ๋ƒฅ ๋ฆฌ๋ทฐ์š”์ฒญ ์ฃผ์‹œ๊ฑฐ๋‚˜, ๋จธ์ง€ ํ•˜๋„๋กํ• ๊ฒŒ์š” :)
์ฝ”๋“œ ์ •๋ฆฌํ•˜์…”๋„ ๋˜๊ณ , ์ถ”๊ฐ€๋กœ ๊ถ๊ธˆํ•œ์ ์žˆ์œผ์‹œ๋ฉด ์ฝ”๋ฉ˜ํŠธ ๋‹ฌ์•„์ฃผ์…”๋„ ์ข‹์•„์š” !

Copy link

@namjackson namjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•ˆ๋…•ํ•˜์„ธ์š” ์˜๊ทผ๋‹˜! ์ƒˆํ•ด๋ณต ๋งŽ์ด ๋ฐ›์œผ์„ธ์š”!
๊ฐœ์ธ์ ์œผ๋กœ ์—ฐ์ดˆ์— ์ผ์ •์ด ๋ฐ”์˜๋‹ค ๋ณด๋‹ˆ๊นŒ ํ”ผ๋“œ๋ฐฑ์ด ๋Šฆ์—ˆ๋„ค์š” :)
์ง€๋ขฐ์ฐพ๊ธฐ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„ ๊ณ ์ƒ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค!
์ฝ”๋ฉ˜ํŠธ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”!

@@ -0,0 +1,13 @@
package tdd.minesweeper.domain

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐœ์ธ์ ์œผ๋กœ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด domain ํŒจํ‚ค์ง€ ๋‚ด์—์„œ๋„
๊ธฐ๋Šฅ ๋“ฑ์œผ๋กœ ๋ฌถ์–ด์„œ ํŒจํ‚ค์ง€๋ฅผ ๊ด€๋ฆฌํ•ด๋ด๋„ ์ข‹์„๊ฑฐ๊ฐ™์•„์š” :)
cell๊ด€๋ จ ๊ฐ์ฒด๋ฅผ ๋ชจ์•„๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

Comment on lines +4 to +12
val adjacentMines: AdjacentMines?

fun isOpen(): Boolean

fun hasMine(): Boolean

fun open(): Cell

fun isExpandableToAdjacent(): Boolean

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cell์„ ์ธํ„ฐํŽ˜์ด์Šค ๋กœ ๋ถ„๋ฆฌํ•˜์…ง๋„ค์š”!
MineCell์—์„œ๋Š” adjacentMines๋Š” null ์ผ์ˆ˜๋ฐ–์— ์—†๊ณ ,
open, isExpandableToAdjacent ๋˜ํ•œ ClosedCell์—์„œ๋งŒ ํ•„์š”ํ•œ ํ•จ์ˆ˜์ด๊ธฐ๋„ํ•ด์š” :)
๊ฐ์ฒด์ง€ํ–ฅ ์›์น™์ค‘ ์ธํ„ฐํŽ˜์ด์Šค ๋ถ„๋ฆฌ ์›์น™์— ์–ด๊ธ‹๋‚ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์š”,
๋” ์ž‘์€ ๋‹จ์œ„๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ถ„๋ฆฌํ•ด๋ณผ์ˆ˜ ์žˆ์„๊ฑฐ๊ฐ™์•„์š”!
(ํ•˜์ง€๋งŒ ์–ธ์ œ๋‚˜, trade-off ๋น„์šฉ์ด ๋“œ๋Š”๊ฑด ์–ด์ฉ”์ˆ˜ ์—†์„๊ฑฐ ๊ฐ™์•„์š”!
์˜คํžˆ๋ ค ์กฐ๊ธˆ๋” ๋ณต์žกํ•ด์งˆ์ˆ˜ ์žˆ๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ์–ด์š”!
๋ณต์žกํ•˜์ง€ ์•Š๊ณ , ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ถ„๋ฆฌํ• ์ˆ˜ ์žˆ๋Š” ์ง€์ ์„ ์˜๊ทผ๋‹˜์˜ ๊ธฐ์ค€์œผ๋กœ ์žก์•„๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”:) )

import tdd.minesweeper.domain.strategy.DefaultBoardCellsCreator

@BoardDslMaker
class BoardBuilder(private val boardCellsCreator: BoardCellsCreator = DefaultBoardCellsCreator()) :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dsl ํ™œ์šฉ ๐Ÿ‘

Comment on lines +7 to +9
class DefaultShouldOpenLocationFinder : ShouldOpenLocationFinder {
override fun findAllShouldOpen(
board: Board,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Board์˜ open์—์„œ ์—ฐ๊ด€๋œ Cell ๊ด€๋ จ ๋ถ€๋ถ„์„ ๋ถ„๋ฆฌํ•ด ์ฃผ์…จ๋„ค์š” ๐Ÿ‘
Board์—์„œ๋„ ShouldOpenLocationFinder๋ฅผ ์˜์กดํ•˜๊ณ ์žˆ๊ณ ,
ShouldOpenLocationFinder์—์„œ๋„ Board๋ฅผ ์˜์กดํ•˜๊ณ  ์žˆ์–ด์š” :)
Board์™€ ShouldOpenLocationFinder๋Š” ๊ฒฐํ•ฉ๋„๊ฐ€ ๋†’๋‹ค๊ณ  ๋ณผ์ˆ˜๋„ ์žˆ์„๊ฑฐ ๊ฐ™์•„์š” :)
์–‘๋ฐฉํ–ฅ ์˜์กด์„ฑ์€ ๊ฐ€๋…์„ฑ ์ธก๋ฉด์ด๋‚˜, ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ ์–ด๋ ค์šธ์ˆ˜ ์žˆ์–ด์š”

board๊ฐ€ ์•„๋‹Œ Cells๋ฅผ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•˜๋„๋ก ์ˆ˜์ •ํ• ์ˆ˜ ์žˆ์„๊ฑฐ ๊ฐ™์•„์š”

val allLocations = createAllLocations(area)

// ์ง€๋ขฐ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ
val mineLocations = calculateMineLocations(allLocations, inputManualMineLocations, countOfMines)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateMineLocations๋Š” ๋ถ„๋ฆฌํ•ด๋ณผ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”?
DefaultBoardCellsCreator์˜ ๊ด€์‹ฌ์‚ฌ๋Š” MineLocations ์ผ๊ฑฐ๊ฐ™์•„์š”
MineLocations์ด inputManual์ธ์ง€, ๋žœ๋ค location์ธ์ง€๋Š” ๋ชฐ๋ผ๋„
Cells์„ ๋งŒ๋“œ๋Š”๋ฐ ์˜ํ–ฅ์ด ์—†์ง€๋Š” ์•Š์„๊นŒ์š”?

val closedCells = createMinePlantedCells(allLocations, mineLocations)

// ์ง€๋ขฐ ์ธ์ ‘ ์œ„์น˜ ํ‘œ์‹œ
val updatedCells = markOfAdjacentMines(closedCells, allLocations, mineLocations)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๋ฏธ closedCells์—๋Š” allLocations, mineLocations์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์žˆ์ง€ ์•Š๋‚˜์š”?
์ง€๋ขฐ ์ธ์ ‘ ์œ„์น˜ ํ‘œ์‹œ ๊ธฐ๋Šฅ์— 3๊ฐœ์˜ ๋ฆฌ์ŠคํŠธ๊ฐ€ ํ•„์š”ํ• ๊นŒ์š”? :)

import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe

class AdjacentMinesTest : BehaviorSpec({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ƒˆ๋กญ๊ฒŒ TDD๋กœ ๋‹ค์‹œํ•œ๋ฒˆ ์ž‘์„ฑํ•˜์‹ ๋ถ€๋ถ„์€ ์–ด๋– ์…จ๋‚˜์š”?

์ €๋Š” TDD๋ฅผ ์ฒ˜์Œ ๋„์ž…ํ•˜๋‹ค๋ณด๋ฉด ์•„๋ฌด๋ž˜๋„ ์ฒ˜์Œ ์ž‘์„ฑํ•œ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์—๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•˜๊ณ ,
์ด์— ๋งŒ์กฑํ•˜๊ธฐ์œ„ํ•ด ๊ตฌํ˜„ํ•˜๋‹ค๋ณด๋‹ˆ, ์„ค๊ณ„๊ฐ€ ์–ด๊ธ‹๋‚˜๊ฑฐ๋‚˜ ๊ผฌ์—ฌ์„œ, ์–ด๋ ค์› ๋˜ ๊ธฐ์–ต์ด ๋‚˜๋„ค์š”,

์ƒˆ๋กœ ํ•œ๋ฒˆ ์ž‘์„ฑํ•˜๊ฒŒ๋˜๋‹ˆ ๊ธฐ์กด์— ์–ด๋Š์ •๋„ ๋„๋ฉ”์ธ๊ณผ ์„ค๊ณ„์— ๋Œ€ํ•œ ๊ธฐ๋ฐ˜์ด ์Œ“์—ฌ์„œ
์กฐ๊ธˆ๋” ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ TDD๋ฅผ ํ• ์ˆ˜ ์žˆ์—‡๋˜๊ฑฐ ๊ฐ™์•„์š” :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants