Skip to content

3단계 - 사다리(게임 실행) #2421

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
wants to merge 7 commits into
base: victor-shin
Choose a base branch
from

Conversation

Victor-shin
Copy link

리뷰 중점 구분

  • 전반적인 클래스 설계가 잘 되었는지 검토 요청 드립니다.
  • 게임을 실행하고 나서 출력하는 부분을 개선을 더 잘해야할지 고민이 됩니다.
    그외의 조언도 부탁드립니다.
    감사합니다.

기능 요구사항

  • 사다리 실행 결과를 출력해야 한다.

  • 개인별 이름을 입력하면 개인별 결과를 출력하고, "all"을 입력하면 전체 참여자의 실행 결과를 출력한다.

  • 사다리 게임에 참여하는 사람에 이름을 최대5글자까지 부여할 수 있다. 사다리를 출력할 때 사람 이름도 같이 출력한다.

  • 사람 이름은 쉼표(,)를 기준으로 구분한다.

  • 사람 이름을 5자 기준으로 출력하기 때문에 사다리 폭도 넓어져야 한다.

  • 사다리 타기가 정상적으로 동작하려면 라인이 겹치지 않도록 해야 한다.

  • |-----|-----| 모양과 같이 가로 라인이 겹치는 경우 어느 방향으로 이동할지 결정할 수 없다.

프로그래밍 요구사항

  • 자바 8의 스트림과 람다를 적용해 프로그래밍한다.
  • 규칙 6: 모든 엔티티를 작게 유지한다.
  • 규칙 7: 3개 이상의 인스턴스 변수를 가진 클래스를 쓰지 않는다.

Copy link
Contributor

@javajigi javajigi left a comment

Choose a reason for hiding this comment

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

사다리타기를 객체 지향 기반으로 구현하는 것이 생각보다 쉽지 않죠? ㅠㅠ
구현하느라 고생했네요. 👍
지금 구현한 객체 설계에서 조금 더 작은 단위의 객체로 분리해 보면 어떨까 생각해 피드백 남겨봤어요.
더 작은 단위의 객체를 추출하는 연습해 보면 좋겠고요.
생성자 활용도 더 적극적으로 하면 좋겠다는 생각에 피드백 남겨 봤어요.

import java.util.concurrent.ThreadLocalRandom;

public class LineGenerator {
public static List<Boolean> generateLine(int countOfPerson) {
Copy link
Contributor

Choose a reason for hiding this comment

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

클래스, 메서드 이름의 의도가 그렇듯이 List 보다는 Line 객체를 생성해 반환하는 것은 어떨까?

}

for(int i = 0; i < values.size() -1; i++) {
if(isConsecutiveLine(values.get(i), values.get(i + 1))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Boolean 값 두 개를 가지는 새로운 객체를 도출해 보는 것은 어떨까?
예를 들어

Point {
     Boolean current;
     Boolean previous;
}

위와 같이 현재 위치의 boolean 값과 이전 위치의 boolean 값을 가지는 더 작은 단위의 객체를 도출해 보면 어떨까?
더 작은 객체의 도출했을 때 현재와 비교해 어떤 장/단점이 있을까?

}
public int countOfPeople() {
return countOfPeople;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ladder가 사다리 타기를 위한 모든 상태 값을 가진다.
Ladder에 play()와 같은 메시지를 보내 사다리 타기를 실행하는 역할을 부여하면 어떨까?

return false;
}

public int move(int index) {
Copy link
Contributor

Choose a reason for hiding this comment

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

index 값이 원시값이다보니 IndexOutOfBoundsException에 대한 체크를 계속해야 한다.
index 원시값을 포장해 보는 것은 어떨까?

return false;
}

public int move(int index) {
Copy link
Contributor

Choose a reason for hiding this comment

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

LEFT, RIGHT, PASS와 같은 상태 값을 enum으로 구현할 경우 이 로직 구현이 어떻께 달라질까?
얻을 수 있는 이점이 있을까?

assertValidLine(line);
});
}
static Stream<List<Boolean>> validLines() {
Copy link
Contributor

Choose a reason for hiding this comment

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

ParameterizedTest 기반으로 테스트하는 것은 알지만 이렇게 많은 경우의 수를 테스트할 필요가 있을까?
좀 더 적은 경우의 수로 모두 커버할 수 있지 않을까?


@Test
public void 사다리_왼쪽으로_이동불가() {
Line line = new Line(List.of(false, false));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Line line = new Line(List.of(false, false));
Line line = new Line(false, false);

Line 객체에 가변 인자를 받은 생성자를 추가해 위와 같이 구현하도록 지원하면 어떨까?

@Victor-shin Victor-shin changed the title Step3 3단계 - 사다리(게임 실행) May 1, 2025
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