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

[Wordle] 차리(이찬주) 미션 제출합니다. #11

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
38e9dde
docs: 기능 요구사항 목록 작성
kth990303 May 10, 2022
80f767b
feat: 글자 하나를 나타내는 `Letter` 구현
kth990303 May 10, 2022
da55951
feat: 유효한 단어를 나타내는 `Word` 구현
kth990303 May 10, 2022
6377d1d
feat: `Word`에서 다른 단어와 비교하는 기능 구현
kth990303 May 11, 2022
ba0bba1
feat: 예측 단어와 정답 단어 비교 기능 구현
kth990303 May 11, 2022
17aca8c
refactor: 접근제어자 수정
kth990303 May 11, 2022
35e26f7
docs: 누락된 요구사항 체크
kth990303 May 11, 2022
80cdae7
feat: 정답 단어를 날짜에 따라 뽑는 기능 구현
kth990303 May 11, 2022
d284131
feat: 단어가 소문자로 이루어졌는지 검증하는 로직 추가 구현
kth990303 May 11, 2022
052464f
feat: 게임을 실행하는 애플리케이션 구현
kth990303 May 11, 2022
b80b2e3
refactor: EOF 컨벤션 변경
kth990303 May 12, 2022
ce0abfe
style: `ktlintCheck`에 맞게 컨벤션 변경
kth990303 May 12, 2022
d2b992b
style: 메소드 순서 변경
cjlee38 May 13, 2022
0d96a6d
test: DSL 테스트 추가
cjlee38 May 18, 2022
df8a5b0
fix: 워들 로직 오류 수정
cjlee38 May 19, 2022
80b7921
refactor: 검증 로직 확장함수로 변경
cjlee38 May 19, 2022
53f36be
feat: Game 객체 추가 및 게임진행 책임 위임
cjlee38 May 19, 2022
7feb21f
refactor: 접근제어자 수정
cjlee38 May 19, 2022
c77d604
style: reformat code
cjlee38 May 19, 2022
21c766d
refactor: 날짜를 생성자 주입을 통해 받을 수 있도록 변경
cjlee38 May 21, 2022
4aa60e3
fix: 인덱스 상관없이 일치한 단어를 소진하도록 변경
cjlee38 May 22, 2022
86c784f
test: 누락한 테스트 수정
cjlee38 May 22, 2022
04c9896
refactor: 도메인에서 view 값 제거
cjlee38 May 22, 2022
0a3af01
style: ktlint 적용
cjlee38 May 22, 2022
d5216d2
style: 한줄 메소드는 식으로 변경
cjlee38 May 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/kotlin/wordle/domain/Answer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ class Answer(val word: Word) {
}

private fun compareAny(word: Word): List<Int> {
return (RANGE_START..RANGE_END).filter { isAnyMatch(word, it) }
val consumed = mutableListOf<Int>()
return (RANGE_START..RANGE_END).filter { isAnyMatch(word, it, consumed) }
}

private fun isAnyMatch(word: Word, outerIndex: Int, consumed: MutableList<Int>): Boolean {
return (RANGE_START..RANGE_END).any {
if (this.word.compareByIndex(word, it, outerIndex) && !consumed.contains(it)) {
consumed.add(it)
return true

Choose a reason for hiding this comment

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

워들 로직이 아직 개선되지 않은거 같아요!
만약 정답이 humph이고 hippy를 입력한 경우, p가 한개임을 유추할 수 있도록 첫번째 p는 회색으로 나와야하지 않을까요?
로마의 리뷰에서 참고해보았는데, 차리도 워들 세부규칙을 참고하면 좋을거 같습니다!
image

Copy link
Author

Choose a reason for hiding this comment

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

해결했다고 생각했는데 여전히 남아있었네요 ㅠ. 해당 부분 다시 수정하였으니 다시 확인해주시면 감사하겠습니다~

}
return@any false

Choose a reason for hiding this comment

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

😲😲😲

}
}

private fun merge(greenIndices: List<Int>, yellowIndices: List<Int>): List<Color> {
Expand All @@ -32,8 +43,4 @@ class Answer(val word: Word) {
}
return Color.GRAY
}

private fun isAnyMatch(word: Word, outerIndex: Int): Boolean {
return (RANGE_START..RANGE_END).any { this.word.compareByIndex(word, it, outerIndex) }
}
}
40 changes: 18 additions & 22 deletions src/test/kotlin/wordle/domain/AnswerTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wordle.domain

import io.kotest.matchers.collections.shouldContainAll
import io.kotest.matchers.collections.shouldContainExactly
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

Expand All @@ -11,21 +12,16 @@ class AnswerTest {
fun compareWithGreenAndGray() {
val answer = Answer(Word("cigar"))

answer.compare(Word("clear")) shouldContainAll listOf(
Color.GREEN,
Color.GRAY,
Color.GRAY,
Color.GREEN,
Color.GREEN
)
answer.compare(Word("clear")) shouldContainExactly
listOf(Color.GREEN, Color.GRAY, Color.GRAY, Color.GREEN, Color.GREEN)
}

@Test
@DisplayName("완전히 일치하는 글자들만 존재하는 예측을 비교한다. - 정답인 경우")
fun compareWithAllGreens() {
val answer = Answer(Word("cigar"))

answer.compare(Word("cigar")) shouldContainAll
answer.compare(Word("cigar")) shouldContainExactly
listOf(Color.GREEN, Color.GREEN, Color.GREEN, Color.GREEN, Color.GREEN)
}

Expand All @@ -34,7 +30,7 @@ class AnswerTest {
fun compareWithAllColors() {
val answer = Answer(Word("spill"))

answer.compare(Word("hello")) shouldContainAll
answer.compare(Word("hello")) shouldContainExactly
listOf(Color.GRAY, Color.GRAY, Color.YELLOW, Color.GREEN, Color.GRAY)
}

Expand All @@ -43,7 +39,7 @@ class AnswerTest {
fun compareWithYellowAndGray1() {
val answer = Answer(Word("front"))

answer.compare(Word("totem")) shouldContainAll
answer.compare(Word("totem")) shouldContainExactly
listOf(Color.YELLOW, Color.YELLOW, Color.GRAY, Color.GRAY, Color.GRAY)
}

Expand All @@ -52,16 +48,25 @@ class AnswerTest {
fun compareWithYellowAndGray2() {
val answer = Answer(Word("totem"))

answer.compare(Word("start")) shouldContainAll
answer.compare(Word("start")) shouldContainExactly
listOf(Color.GRAY, Color.YELLOW, Color.GRAY, Color.GRAY, Color.YELLOW)
}

@Test
@DisplayName("위치만 일치하는 글자들과 틀린 글자들이 존재하는 예측을 비교한다..")

Choose a reason for hiding this comment

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

Suggested change
@DisplayName("위치만 일치하는 글자들과 틀린 글자들이 존재하는 예측을 비교한다..")
@DisplayName("위치만 일치하는 글자들과 틀린 글자들이 존재하는 예측을 비교한다.")

아련해지네요..🌟

fun compareWithYellowAndGray3() {
val answer = Answer(Word("witch"))

answer.compare(Word("timid")) shouldContainExactly
listOf(Color.YELLOW, Color.GREEN, Color.GRAY, Color.GRAY, Color.GRAY)
}

@Test
@DisplayName("전부 틀린 글자들이 존재하는 예측을 비교한다.")
fun compareWithAllGrays() {
val answer = Answer(Word("parry"))

answer.compare(Word("biome")) shouldContainAll
answer.compare(Word("biome")) shouldContainExactly
listOf(Color.GRAY, Color.GRAY, Color.GRAY, Color.GRAY, Color.GRAY)
}

Expand All @@ -70,16 +75,7 @@ class AnswerTest {
fun compareWithAllYellows() {
val answer = Answer(Word("parse"))

answer.compare(Word("spear")) shouldContainAll
answer.compare(Word("spear")) shouldContainExactly
listOf(Color.YELLOW, Color.YELLOW, Color.YELLOW, Color.YELLOW, Color.YELLOW)
}

@Test
@DisplayName("test.")
fun test1() {
val answer = Answer(Word("witch"))

answer.compare(Word("timid")) shouldContainAll
listOf(Color.YELLOW, Color.GREEN, Color.GRAY, Color.GRAY, Color.GRAY)
}
}