-
Notifications
You must be signed in to change notification settings - Fork 26
2주차 미션 / 서버 3조 장현준 #34
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
base: 1week-completed
Are you sure you want to change the base?
Changes from all commits
8dce6fa
e6f6a53
d2adfa4
30aee97
05a0e9f
29caf31
e18b603
cd78593
32c627a
2f49f81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| pluginManagement { | ||
| plugins { | ||
| id 'org.jetbrains.kotlin.jvm' version '2.0.10' | ||
| } | ||
| } | ||
| plugins { | ||
| id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' | ||
| } | ||
| rootProject.name = 'kuit-ladder' | ||
|
|
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package ladder; | ||
|
|
||
| public class LadderSize { | ||
| private final GreaterThanOne numberOfPerson; | ||
| private final GreaterThanOne numberOfRow; | ||
|
|
||
| public LadderSize(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { | ||
| this.numberOfPerson = numberOfPerson; | ||
| this.numberOfRow = numberOfRow; | ||
| } | ||
|
|
||
| public int calLineSize() { | ||
| return (int)(numberOfPerson.getNumber()*numberOfRow.getNumber()*0.3); | ||
| } | ||
|
|
||
| public GreaterThanOne getNumberOfPerson() { | ||
| return numberOfPerson; | ||
| } | ||
|
|
||
| public GreaterThanOne getNumberOfRow() { | ||
| return numberOfRow; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,10 @@ public void move(Position position) { | |
| } | ||
| } | ||
|
|
||
| public void printNode(StringBuilder sb) { | ||
| sb.append(direction.getValue()); | ||
|
Member
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. node의 값을 외부로 노출하지 않고 값을 append 하는 로직을 잘 작성해 주셨네요. 디미터 법칙을 잘 이해하신 것 같습니다! |
||
| } | ||
|
|
||
| public void setRightNode() { | ||
| direction = RIGHT; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,4 +43,8 @@ private static void validatePosition(int position) { | |
| private static boolean isPosition(int position) { | ||
| return position >= 0; | ||
| } | ||
|
|
||
| public boolean isSamePosition(int i) { | ||
|
Member
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. equals 메서드를 오버라이드해서 구현하면 의미 전달이 더 잘 될 것 같습니다! |
||
| return this.position == i; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package ladder; | ||
|
|
||
| public class PositionPair { | ||
| private final int col; | ||
| private final int row; | ||
|
Member
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. PositionPair 라면 인스턴스 변수로 int 대신 Position 클래스를 갖도록 구현해 보는건 어떠신가요? |
||
|
|
||
| public PositionPair(int row, int col) { | ||
| this.col = col; | ||
| this.row = row; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,4 +58,25 @@ private boolean isLineAtNextPosition(Position position) { | |
| return lineAtPosition; | ||
| } | ||
|
|
||
| public void printRow(StringBuilder sb) { | ||
| for (int i = 0; i < nodes.length; i++) { | ||
| nodes[i].printNode(sb); | ||
|
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. 노드 출력은 Node가 맡는다는 생각 좋은 것 같아요 |
||
| sb.append(" "); | ||
| } | ||
| sb.append("\n"); | ||
| } | ||
|
|
||
| public void printStarRow(Position position, StringBuilder sb) { | ||
|
Member
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. printRow와 printStarRow는 로직이 매우 비슷해 보입니다. printRow에서 position과 비교하여 *을 append하는 로직만을 메서드로 따로 분리하면 가독성이나 클라이언트 코드 입장에서도 어떻게 코드를 다뤄야 할지 명확할 것 같습니다. |
||
| for (int i = 0; i < nodes.length; i++) { | ||
| nodes[i].printNode(sb); | ||
|
|
||
| if (position.isSamePosition(i)) { | ||
|
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. 값 비교를 메소드로 작성하니 가독성도 늘고, 객체 내부에 어떤 데이터가 있는지 자세히 몰라도 되네요! 객체지향적인 코드의 장점이 보이죠? |
||
| sb.append("*"); | ||
| } | ||
|
|
||
| sb.append(" "); | ||
| } | ||
| sb.append("\n"); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ladder; | ||
|
|
||
| public enum TimePeriod { | ||
|
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. enum을 통해서 올바른 매개변수의 값만 사용할 수 있게 한 점 좋아요! |
||
| BEFORE("Before"), AFTER("After"); | ||
|
Member
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. 상수를 이넘으로 처리한 것이 인상깊네요! |
||
|
|
||
| private final String timePeriod; | ||
|
|
||
| TimePeriod(String timePeriod) { | ||
| this.timePeriod = timePeriod; | ||
| } | ||
|
|
||
| public String getTimePeriod() { | ||
| return timePeriod; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package ladder.creator; | ||
|
|
||
| import ladder.*; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Random; | ||
|
|
||
| public class AutoLadderCreator implements LadderCreator { | ||
|
|
||
| private final Row[] rows; | ||
|
|
||
| public AutoLadderCreator(LadderSize ladderSize) { | ||
| GreaterThanOne numberOfRow = ladderSize.getNumberOfRow(); | ||
| GreaterThanOne numberOfPerson = ladderSize.getNumberOfPerson(); | ||
|
|
||
| rows = new Row[numberOfRow.getNumber()]; | ||
| for (int i = 0; i < numberOfRow.getNumber(); i++) { | ||
| rows[i] = new Row(numberOfPerson); | ||
| } | ||
|
|
||
| drawAutoRandomLine(ladderSize, numberOfPerson, numberOfRow); | ||
|
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. 생성자에서 랜덤 사디리 그리기를 수행하는 점 괜찮은데요! |
||
| } | ||
|
|
||
| private void drawAutoRandomLine(LadderSize ladderSize, GreaterThanOne numberOfPerson, GreaterThanOne numberOfRow) { | ||
| //생성해야 하는 line 개수 | ||
| int lineSize = ladderSize.calLineSize(); | ||
|
|
||
| HashSet<PositionPair> set = new HashSet<>(); | ||
|
Member
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. Set 같은 컬렉션에 들어가는 객체는 equals, hashCode 메서드가 구현되어 있어야 제대로 된 중복 검증이 가능합니다! |
||
| Random random = new Random(); | ||
|
|
||
| int count = 0; | ||
|
|
||
| while (count < lineSize) { | ||
| //0~numberOfPerson-2 사이의 난수 생성 => 왼쪽에만 생성되기 때문에 2를 뺌! | ||
| int col = random.nextInt(numberOfPerson.getNumber()-1); | ||
|
|
||
| //0~numberOfRow-1 사이의 난수 생성 | ||
| int row = random.nextInt(numberOfRow.getNumber()); | ||
| PositionPair pair = new PositionPair(row, col); | ||
|
|
||
| //중복 확인 | ||
| if(set.contains(pair)) { | ||
|
Member
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. 반복문 조건식으로 count를 사용하는 것이 아니라 set.size() 를 사용했다면, 중복처리와 반복문 조건식 핸들링을 한 번에 할 수 있습니다! |
||
| continue; | ||
| } | ||
|
Comment on lines
+42
to
+44
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. 혹시 디버깅하면서 중복확인이 되는지 확인해보셨나요? 제가 찾아보니까 HashSet의 contains()는 두 객체의 주소가 같은지 비교하기 때문에 중복 확인이 안 될 수도 있을 것 같습니다 |
||
|
|
||
| try{ | ||
| this.drawLine(Position.from(row), Position.from(col)); | ||
| set.add(pair); | ||
| count++; | ||
| } catch (IllegalArgumentException e) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void drawLine(Position row, Position col) { | ||
| rows[row.getValue()].drawLine(col); | ||
| } | ||
|
|
||
| @Override | ||
| public Row[] getRows() { | ||
| return rows; | ||
| } | ||
|
|
||
| } | ||
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.
랜덤으로 그릴 사다리 라인 값을 정하는 로직이 LadderSize의 책임 중 하나인지 고민해 보시면 좋을 것 같습니다!