-
Notifications
You must be signed in to change notification settings - Fork 50
[4기][3주차] Wordle 과제 제출 - 분수 #25
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
Open
Saerang
wants to merge
23
commits into
woowahan-pjs:main
Choose a base branch
from
Saerang:boonsoo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
99b1f3a
docs: 기능 요구 사항, 유비쿼터스 언어 정리
anwjrrp33 055067c
feat: Words 생성기 구현
anwjrrp33 5b2d7a1
feat: Words 구현
anwjrrp33 62c685f
docs: 기능 요구 사항 수정
407bd21
refactor: 메서드, 테스트코드 리팩터링
01c5f7a
feat: word 구현
e523243
feat: 일급 컬렉션 구현
f52a5f0
docs: 기능 요구사항 수정
70f41fa
test: word 테스트 코드 작성
anwjrrp33 cb1dc6b
feat: Words 정답을 가져오는 기능 구현
anwjrrp33 96c91f7
feat: 정답 생성
anwjrrp33 d54e1b7
feat: 답안과 정답을 비교하는 기능 구현
anwjrrp33 efba747
docs: 기능 요구사항 수정
anwjrrp33 d6125e7
refactor: 이름변경 (CorrectAnswer -> Answer)
9954847
feat: Letter 생성
bfe943a
refactor: Answer, Word 에서 Letter 를 사용하도록 변경
cac009b
docs: 기능 요구사항 수정
13f908c
refactor: 타일 비교 리팩터링
anwjrrp33 c8b37fa
feat: 입출력 기능 구현
anwjrrp33 5c5daeb
feat: 기능 조립
anwjrrp33 1fc9412
refactor: 기능 리팩터링
anwjrrp33 59476e5
test: 안쓰는 코드 제거
09d3cb1
refactor: 코드리뷰 반영
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
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,9 @@ | ||
| import controller.GameController; | ||
| import service.GameService; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| GameController gameController = new GameController(new GameService()); | ||
| gameController.start(); | ||
| } | ||
| } |
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,6 @@ | ||
| package config; | ||
|
|
||
| public class FileConfig { | ||
|
|
||
| public final static String FILE_PATH = "src/main/resources/words.txt"; | ||
| } |
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 @@ | ||
| package controller; | ||
|
|
||
| import domain.Answer; | ||
| import dto.GameHistory; | ||
| import service.GameService; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class GameController { | ||
|
|
||
| private final GameService gameService; | ||
|
|
||
| public GameController(GameService gameService) { | ||
| this.gameService = gameService; | ||
| } | ||
|
|
||
| public void start() { | ||
| Answer answer = gameService.init(); | ||
| List<GameHistory> gameHistories = gameService.startGame(answer); | ||
| gameService.endGame(gameHistories); | ||
| } | ||
| } |
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,81 @@ | ||
| package domain; | ||
|
|
||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Answer { | ||
|
|
||
| private final Word answer; | ||
|
|
||
| private boolean isSuccess = false; | ||
|
|
||
| public Answer(Word answer) { | ||
| this.answer = answer; | ||
| } | ||
|
|
||
| public List<Tile> compare(Word answer) { | ||
| Map<Letter, Long> letterMap = getLetterMap(); | ||
|
|
||
| List<Tile> result = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < Word.WORD_LENGTH; i++) { | ||
| Long count = letterMap.get(answer.getWord().get(i)); | ||
|
|
||
| Tile tile = getTile(count, this.answer.getWord().get(i), answer.getWord().get(i)); | ||
| result.add(tile); | ||
|
|
||
| letterMap.put(answer.getWord().get(i), letterMap.getOrDefault(answer.getWord().get(i), 0L) - 1); | ||
| } | ||
| endGame(result); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private Map<Letter, Long> getLetterMap() { | ||
| return this.answer.getWord() | ||
| .stream() | ||
| .collect(Collectors.groupingBy(c -> c, Collectors.counting())); | ||
| } | ||
|
|
||
| private void endGame(List<Tile> result) { | ||
| int count = Collections.frequency(result, Tile.GREEN); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 Collections 메서드가 있는줄 처음 알았네요. 덕분에 배워갑니다!❤ |
||
|
|
||
| if (count == Word.WORD_LENGTH) { | ||
| this.isSuccess = true; | ||
| } | ||
| } | ||
|
|
||
| private Tile getTile(Long count, Letter answerLetter, Letter letter) { | ||
| if (count == null || count <= 0) { | ||
| return Tile.GRAY; | ||
| } | ||
| if (answerLetter.equals(letter)) { | ||
| return Tile.GREEN; | ||
| } | ||
| return Tile.YELLOW; | ||
| } | ||
|
|
||
| public boolean isSuccess() { | ||
| return isSuccess; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Answer that = (Answer) o; | ||
| return Objects.equals(answer, that.answer); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(answer); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Answer{" + | ||
| "answer=" + answer + | ||
| '}'; | ||
| } | ||
| } | ||
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,43 @@ | ||
| package domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Letter { | ||
| private final String letter; | ||
|
|
||
| public Letter(Character letter) { | ||
| if (this.isNotAlphabet(letter)) { | ||
| throw new IllegalArgumentException(letter + "는 알파벳이 아닙니다."); | ||
| } | ||
|
|
||
| this.letter = String.valueOf(letter); | ||
| } | ||
|
|
||
| private boolean isNotAlphabet(Character letter) { | ||
| return !(letter >= 'A' && letter <= 'Z') && !(letter >= 'a' && letter <= 'z'); | ||
| } | ||
|
|
||
| public String getLetter() { | ||
| return letter; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Letter letter1 = (Letter) o; | ||
| return Objects.equals(letter, letter1.letter); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(letter); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Letter{" + | ||
| "letter='" + letter + '\'' + | ||
| '}'; | ||
| } | ||
| } |
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,15 @@ | ||
| package domain; | ||
|
|
||
| public enum Tile { | ||
| GREEN("\uD83D\uDFE9"), YELLOW("\uD83D\uDFE8"), GRAY("⬜"); | ||
|
|
||
| private final String tile; | ||
|
|
||
| Tile(String tile) { | ||
| this.tile = tile; | ||
| } | ||
|
|
||
| public String getTile() { | ||
| return tile; | ||
| } | ||
| } |
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,49 @@ | ||
| package domain; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Word { | ||
| public static final int WORD_LENGTH = 5; | ||
|
|
||
| private final List<Letter> word; | ||
|
|
||
| public Word(String word) { | ||
| if (this.isNotMatchWord(word)) { | ||
| throw new IllegalArgumentException(word + "는 5글자의 알파벳이 아닙니다."); | ||
| } | ||
|
|
||
| this.word = word.chars().mapToObj(c -> (char) c) | ||
| .map(Letter::new) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private boolean isNotMatchWord(String word){ | ||
| return word.length() != WORD_LENGTH; | ||
| } | ||
|
|
||
| public List<Letter> getWord() { | ||
| return word; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Word word1 = (Word) o; | ||
| return Objects.equals(word, word1.word); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(word); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Word{" + | ||
| "word=" + word + | ||
| '}'; | ||
| } | ||
| } |
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,34 @@ | ||
| package domain; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Words { | ||
| public static final LocalDate DEFAULT_DATE = LocalDate.of(2021, 6, 19); | ||
| private final List<Word> words; | ||
|
|
||
| public Words(List<String> words) { | ||
| this.words = convert(words); | ||
| } | ||
|
|
||
| private List<Word> convert(List<String> words) { | ||
| if (words.size() == 0) { | ||
| throw new IllegalArgumentException("파일이 비어 있습니다."); | ||
| } | ||
|
|
||
| return words.stream().map(Word::new).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public Answer getAnswer(LocalDate now) { | ||
| long betweenDay = ChronoUnit.DAYS.between(DEFAULT_DATE, now); | ||
|
|
||
| Word answer = this.words.get((int) (betweenDay % words.size())); | ||
| return new Answer(answer); | ||
| } | ||
|
|
||
| public List<Word> getWords() { | ||
| return words; | ||
| } | ||
| } |
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 @@ | ||
| package dto; | ||
|
|
||
| import domain.Tile; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class GameHistory { | ||
|
|
||
| private final List<Tile> gameHistory; | ||
|
|
||
| public GameHistory(List<Tile> gameHistory) { | ||
| this.gameHistory = gameHistory; | ||
| } | ||
|
|
||
| public String getGameResult() { | ||
| return gameHistory.stream().map(Tile::getTile) | ||
| .collect(Collectors.joining()); | ||
| } | ||
| } |
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,54 @@ | ||
| package service; | ||
|
|
||
| import config.FileConfig; | ||
| import domain.Answer; | ||
| import domain.Tile; | ||
| import domain.Word; | ||
| import domain.Words; | ||
| import dto.GameHistory; | ||
| import support.WordsGenerator; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class GameService { | ||
| public static final int GAME_TOTAL_ROUND = 6; | ||
|
|
||
| public Answer init() { | ||
| InputView.inputStartGame(); | ||
| Words words = new Words(WordsGenerator.read(FileConfig.FILE_PATH)); | ||
| return words.getAnswer(LocalDate.now()); | ||
| } | ||
|
|
||
| public List<GameHistory> startGame(Answer answer) { | ||
| List<GameHistory> gameHistories = new ArrayList<>(); | ||
|
|
||
| int count = 0; | ||
| while (isGameProgress(answer, count)) { | ||
| Word inputWord = new Word(InputView.inputWord()); | ||
| List<Tile> tiles = answer.compare(inputWord); | ||
| gameHistories.add(new GameHistory(tiles)); | ||
| print(answer, gameHistories); | ||
| count++; | ||
| } | ||
|
|
||
| return gameHistories; | ||
| } | ||
|
|
||
| private static boolean isGameProgress(Answer answer, int count) { | ||
| return count < GAME_TOTAL_ROUND && !answer.isSuccess(); | ||
| } | ||
|
|
||
| private void print(Answer answer, List<GameHistory> gameHistories) { | ||
| if (!answer.isSuccess()) { | ||
| OutputView.outputTiles(gameHistories); | ||
| } | ||
| } | ||
|
|
||
| public void endGame(List<GameHistory> gameHistories) { | ||
| OutputView.outputEndGame(gameHistories); | ||
| } | ||
| } |
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.
중복되는 값을 변수 선언하여 재사용을 할 수 있을것 같습니다.
Uh oh!
There was an error while loading. Please reload this page.
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.
음 너무 길어져서 10줄이 넘어서 ㅋㅋㅋ 재선언 안하긴 했습니다.
다른방법으로 구현을 리팩터링 해야할 것 같네요.