-
Notifications
You must be signed in to change notification settings - Fork 748
๐ 3๋จ๊ณ - ์ฌ๋ค๋ฆฌ(๊ฒ์ ์คํ) #2392
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
67911ab
refactor: improve Line generation logic and add final position calculโฆ
baki-719 1d5a6d4
feat: add inputResults method for collecting execution results
baki-719 a2dd20f
fix: adjust player count in Line generation logic
baki-719 c11cf3c
refactor: remove getFinalPosition method from Line class
baki-719 28904b0
feat: add result calculation and display functionality in Ladder game
baki-719 543a09b
feat: implement cursor movement logic in Line class and add corresponโฆ
baki-719 d143ab4
refactor: simplify Line constructor and improve calculateNextPositionโฆ
baki-719 e245c50
feat: refactor position calculation logic in Ladder and Lines classes
baki-719 c1c4b13
feat: add Report class for result management and update OutputView toโฆ
baki-719 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
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 |
---|---|---|
@@ -1,20 +1,56 @@ | ||
package nextstep.ladder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class Line { | ||
private final List<Boolean> points; | ||
|
||
public Line(int playerCount, Random random) { | ||
this.points = IntStream.range(1, playerCount) | ||
.mapToObj(it -> random.nextBoolean()) | ||
.collect(Collectors.toUnmodifiableList()); | ||
Line(int playerCount, Random random) { | ||
this.points = new ArrayList<>(); | ||
|
||
for (int i = 0; i < playerCount - 1; i++) { | ||
if (i == 0) { | ||
points.add(random.nextBoolean()); | ||
continue; | ||
} | ||
|
||
if (points.get(i - 1) == true) { | ||
points.add(false); | ||
continue; | ||
} | ||
|
||
points.add(random.nextBoolean()); | ||
} | ||
} | ||
|
||
Line(List<Boolean> points) { | ||
this.points = points; | ||
} | ||
|
||
public List<Boolean> getPoints() { | ||
return points; | ||
} | ||
|
||
public int calculateNextPosition(int cursor) { | ||
if (cursor == 0 && points.get(cursor)) { | ||
return ++cursor; | ||
} | ||
|
||
if (cursor == points.size() && points.get(cursor - 1)) { | ||
return --cursor; | ||
} | ||
|
||
if (points.get(cursor - 1)) { | ||
return --cursor; | ||
} | ||
|
||
if (points.get(cursor)) { | ||
return ++cursor; | ||
} | ||
|
||
return cursor; | ||
|
||
} | ||
} |
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
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,28 @@ | ||
package nextstep.ladder; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Report { | ||
private final Map<String, String> result; | ||
|
||
public Report(Map<String, String> result) { | ||
this.result = result; | ||
} | ||
|
||
public Map<String, String> getResult() { | ||
return new HashMap<>(result); | ||
} | ||
|
||
public boolean containsName(String name) { | ||
return result.containsKey(name); | ||
} | ||
|
||
public String findResultByName(String name) { | ||
if (!result.containsKey(name)) { | ||
throw new IllegalArgumentException("ํด๋น ์ด๋ฆ์ ๊ฒฐ๊ณผ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค."); | ||
} | ||
|
||
return result.get(name); | ||
} | ||
} |
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
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
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.
์ ๊ทผ ์ ์ด์ ์ ์ ํ ๋ถ์ฌํด์ฃผ์ธ์.
์ ์๊ฐ์๋ ์์ public์ผ๋ก ์์ฑํ์ ์์ฑ์๋ฅผ builder๋ static of pattern์ผ๋ก ๋ฐ๊พธ๊ณ ์ด ์์ฑ์๋ฅผ private์ผ๋ก ๊ฐ๋ฆฌ๋ ๊ฒ๋ ์ํธํ ๊ฒ ๊ฐ์ต๋๋ค.
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.
๋๋ค Lines์ test์ฝ๋์์๋ง ์ ๊ทผํ๋๊น default๋ก ์ ์ธํ๊ณ
builder๋ static of๋ ๊ฐ์ธ์ ์ผ๋ก ์ด์ ๋ ๋ถ๋์๋ ์ฌ์ฉ์ํ๋ ์ฃผ์์ฌ์ ์ฌ์ฉํ์ง ์์์ต๋๋ค.
์ถํ ๋ณ์๊ฐ ๋์ด๋๊ฑฐ๋ ๋ก์ง์ด ๋์ด๋๋ฉด ๋ฐ์์ ํ๋๋ก ํ๊ฒ ์ต๋๋ค!