-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLadder.java
More file actions
48 lines (38 loc) · 1.29 KB
/
Ladder.java
File metadata and controls
48 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package nextstep.ladder2.domain.ladder;
import nextstep.ladder2.domain.result.MatchingResult;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Ladder {
private final List<Line> lines = new ArrayList<>();
private final int peopleCount;
public Ladder(int peopleCount, int height) {
if (height < 1) {
throw new IllegalArgumentException("사다리 높이는 1 이상이어야 합니다.");
}
this.peopleCount = peopleCount;
for(int i = 0; i < height; i++) {
lines.add(LineFactory.create(peopleCount));
}
}
public int height() {
return lines.size();
}
public List<Line> lines() {
return List.copyOf(lines);
}
public Position resultOf(Position position) {
for (Line line : lines) {
position.moveBy(line.move(position.value()));
}
return position;
}
public MatchingResult play() {
List<Position> positions = Position.range(0, peopleCount, peopleCount);
List<Position> playerRewardList = positions.stream()
.map(this::resultOf)
.collect(Collectors.toList());
return new MatchingResult(playerRewardList);
}
}