Skip to content

E1psy congr00 #4

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 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ce6479b
docs: readme
E1psycongr00 Dec 3, 2022
8452ad0
view: outputView
E1psycongr00 Dec 3, 2022
4801e58
feat(type): add type
E1psycongr00 Dec 3, 2022
e463e14
feat(maker): add pairMaker
E1psycongr00 Dec 3, 2022
011edd1
feat(io): add reader
E1psycongr00 Dec 3, 2022
0e6697a
feat(duplicateChecker): add duplicateChecker
E1psycongr00 Dec 3, 2022
e6adde7
feat(fileLoader): add fileNameLoader
E1psycongr00 Dec 3, 2022
233f6c5
feat(type): add name
E1psycongr00 Dec 3, 2022
355ad7c
feat(nameLoader): addNameLoader
E1psycongr00 Dec 3, 2022
af3573d
feat(database): add database
E1psycongr00 Dec 3, 2022
0734e83
feat(crewLoader): add loader
E1psycongr00 Dec 3, 2022
fb245c4
feat(controller): add controller
E1psycongr00 Dec 3, 2022
1fd08b4
feat(gameService): add service
E1psycongr00 Dec 3, 2022
b514275
test(test): add test
E1psycongr00 Dec 3, 2022
e89c9da
feat(pairMaker): add even, odd pair maker
E1psycongr00 Dec 5, 2022
c84bb62
test(pairMaker): test even, odd pair maker
E1psycongr00 Dec 5, 2022
60a9b52
feat(pairStatus): add status interface
E1psycongr00 Dec 5, 2022
7a35b3f
feat(pairStatus): add search status
E1psycongr00 Dec 5, 2022
38feca2
feat(pairStatus): add retryStatus
E1psycongr00 Dec 5, 2022
6880863
feat(pairStatus): add resetStatus
E1psycongr00 Dec 5, 2022
dadffdc
feat(pairStatus): add matchingStatus
E1psycongr00 Dec 5, 2022
c931b61
feat(pairStatus): add quit status
E1psycongr00 Dec 5, 2022
828192e
feat(pairStatus): add feature status
E1psycongr00 Dec 5, 2022
1e062ce
feat(exception): add business exception
E1psycongr00 Dec 5, 2022
8196d5c
feat(exception): add duplicate exception extends business exception
E1psycongr00 Dec 5, 2022
51cdd34
feat(exception): add duplicate pair exception extends business exception
E1psycongr00 Dec 5, 2022
37bf5ac
feat(exception): add empty matched exception extends business exception
E1psycongr00 Dec 5, 2022
91df578
feat(exception): add exceed try extends business exception
E1psycongr00 Dec 5, 2022
9ca4067
feat(gameLauncher): add pairMatchingGameLauncher
E1psycongr00 Dec 5, 2022
5736ace
docs(readme): improve input output details
E1psycongr00 Dec 5, 2022
648353a
fix(database): change database method argument
E1psycongr00 Dec 5, 2022
89ef36b
feat(crew): static method backend and frontend
E1psycongr00 Dec 5, 2022
bc3c1a1
fix(controller): fix controller to state pattern's context
E1psycongr00 Dec 5, 2022
25fc2fe
feat(matchingInformation): add matchingInformation
E1psycongr00 Dec 5, 2022
d6b83b2
fix(pair): change toString
E1psycongr00 Dec 5, 2022
ef9108d
fix(duplicateChecker): change method argument
E1psycongr00 Dec 5, 2022
25db2bf
fix(course): change toString
E1psycongr00 Dec 5, 2022
7ec10ed
fix(mission): change field type
E1psycongr00 Dec 5, 2022
3292e82
feat(subject): add subject
E1psycongr00 Dec 5, 2022
b4db011
fix(application): change controller to launcher
E1psycongr00 Dec 5, 2022
8e429d9
refactor(consoleReader): change object to domain class
E1psycongr00 Dec 5, 2022
7f18fcb
refactor(duplicateChecker): change boolean type to throwing exception
E1psycongr00 Dec 5, 2022
0dc8cd5
feat(view): add inputView
E1psycongr00 Dec 5, 2022
bd36c86
feat(view): add outputView
E1psycongr00 Dec 5, 2022
dd9ffa3
feat(view): add reset OutputView
E1psycongr00 Dec 5, 2022
36161b7
refactor(crewLoader): use static method
E1psycongr00 Dec 5, 2022
c25afd2
test(crewLoader): test crew loader
E1psycongr00 Dec 5, 2022
d55c188
feat(crew): add course getter
E1psycongr00 Dec 5, 2022
d49f164
feat(name): add equals and hashcode
E1psycongr00 Dec 5, 2022
a3454c1
feat(pair): add match function
E1psycongr00 Dec 5, 2022
253014b
fix(pairMatchingGame): fix argument and function
E1psycongr00 Dec 5, 2022
e0f8658
test(duplicateChecker): test duplicateChecker
E1psycongr00 Dec 5, 2022
d84de0b
fix(database): fix exitPair logic
E1psycongr00 Dec 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# 페어 매칭



# 기능 목록

## 페어 매칭 기능

### 조건
- 미션을 수행할 페어는 기본적으로 2명씩 매칭
- 인원이 홀수인 경우 3인으로 구성
- 같은 레벨에서 이미 페어를 맺은 크루와는 다시 페어 매칭 불가능

### 구현
- 이름 목록 -> List<String>
- 크루 목록 random으로 섞기 -> Randoms.shuffle 활용
- 홀수인 경우 마지막 남은 크루는 마지막 페어에 포함.
- 같은 레벨에서 만난적이 있는 크루면 다시 크루 목록의 순서를 랜덤으로 섞어서 매칭 시도
- 3회 시도까지 매칭이 되지 않거나 매칭을 할 수 있는 경우의 수가 없으면 에러 메시지 출력

### 재매칭 시도
- 안내 문구를 출력 후 매칭 진행
- 아니오를 선택할 경우 코스, 레벨, 미션을 다시 선택

## 페어 조회 기능
- 과정,레벨, 미션을 선택하면 미션의 페어 정보 출력
- 매칭 이력이 없으면 매칭 이력 없음을 안내


# 입출력 요구 사항

## 파일 입출력
- 주어진 .md 파일을 활용한다.
- 두 파일의 내용은 수정이 가능하다. 그러나 크루들의 이름은 중복될 수 없다.

## 기능 선택
- 기능의 종류를 선택한다.
- 1,2,3,Q 이외의 입력이 들어오면 예외를 처리한다.

## 페어 매칭

### 입력

```text
기능을 선택하세요.
1. 페어 매칭
2. 페어 조회
3. 페어 초기화
Q. 종료
```

- 페어매칭 선택시 입력창
```text

#############################################
과정: 백엔드 | 프론트엔드
미션:
- 레벨1: 자동차경주 | 로또 | 숫자야구게임
- 레벨2: 장바구니 | 결제 | 지하철노선도
- 레벨3:
- 레벨4: 성능개선 | 배포
- 레벨5:
############################################
과정, 레벨, 미션을 선택하세요.
ex) 백엔드, 레벨1, 자동차경주
프론트엔드, 레벨1, 자동차경주
```
- **condition**
- 과정, 레벨, 미션을 선택하고 리스트에 없는 목록을 입력한 경우 예외처리를 한다.
- 3개만 입력 가능해야 함.

- 매칭 정보가 있어서 아니오를 누른 경우 입력창
```text
과정, 레벨, 미션을 선택하세요.
ex) 백엔드, 레벨1, 자동차경주
```

- 매칭 정보가 있는 경우 확인 입력 창
```text
매칭 정보가 있습니다. 다시 매칭하시겠습니까?
네 | 아니오
```
### 출력
- 페어 매칭 결과
```text

페어 매칭 결과입니다.
다비 : 신디
쉐리 : 덴버
제키 : 로드
라라 : 윌터
니콜 : 이브
린다 : 시저
보노 : 제시 : 제키
```

- 초기화후 출력
```text
초기화 되었습니다.
```



## 프로그램 사용 예시
```text
기능을 선택하세요.
1. 페어 매칭
2. 페어 조회
3. 페어 초기화
Q. 종료
1

#############################################
과정: 백엔드 | 프론트엔드
미션:
- 레벨1: 자동차경주 | 로또 | 숫자야구게임
- 레벨2: 장바구니 | 결제 | 지하철노선도
- 레벨3:
- 레벨4: 성능개선 | 배포
- 레벨5:
############################################
과정, 레벨, 미션을 선택하세요.
ex) 백엔드, 레벨1, 자동차경주
프론트엔드, 레벨1, 자동차경주

페어 매칭 결과입니다.
다비 : 신디
쉐리 : 덴버
제키 : 로드
라라 : 윌터
니콜 : 이브
린다 : 시저
보노 : 제시 : 제키

기능을 선택하세요.
1. 페어 매칭
2. 페어 조회
3. 페어 초기화
Q. 종료
1

#############################################
과정: 백엔드 | 프론트엔드
미션:
- 레벨1: 자동차경주 | 로또 | 숫자야구게임
- 레벨2: 장바구니 | 결제 | 지하철노선도
- 레벨3:
- 레벨4: 성능개선 | 배포
- 레벨5:
############################################
과정, 레벨, 미션을 선택하세요.
ex) 백엔드, 레벨1, 자동차경주
프론트엔드, 레벨1, 자동차경주

매칭 정보가 있습니다. 다시 매칭하시겠습니까?
네 | 아니오
아니오

과정, 레벨, 미션을 선택하세요.
ex) 백엔드, 레벨1, 자동차경주
프론트엔드, 레벨1, 자동차경주
매칭 정보가 있습니다. 다시 매칭하시겠습니까?
네 | 아니오

페어 매칭 결과입니다.
이브 : 윌터
보노 : 제키
신디 : 로드
제시 : 린다
시저 : 라라
니콜 : 다비
리사 : 덴버 : 제키

기능을 선택하세요.
1. 페어 매칭
2. 페어 조회
3. 페어 초기화
Q. 종료
2

#############################################
과정: 백엔드 | 프론트엔드
미션:
- 레벨1: 자동차경주 | 로또 | 숫자야구게임
- 레벨2: 장바구니 | 결제 | 지하철노선도
- 레벨3:
- 레벨4: 성능개선 | 배포
- 레벨5:
############################################
과정, 레벨, 미션을 선택하세요.
ex) 백엔드, 레벨1, 자동차경주
프론트엔드, 레벨1, 자동차경주

페어 매칭 결과입니다.
이브 : 윌터
보노 : 제키
신디 : 로드
제시 : 린다
시저 : 라라
니콜 : 다비
리사 : 덴버 : 제키

기능을 선택하세요.
1. 페어 매칭
2. 페어 조회
3. 페어 초기화
Q. 종료
3

초기화 되었습니다.

기능을 선택하세요.
1. 페어 매칭
2. 페어 조회
3. 페어 초기화
Q. 종료
Q
```
6 changes: 4 additions & 2 deletions src/main/java/pairmatching/Application.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package pairmatching;

import pairmatching.luncher.PairMatchingGameLauncher;

public class Application {
public static void main(String[] args) {
// TODO 구현 진행

PairMatchingGameLauncher pairMatchingGameLauncher = new PairMatchingGameLauncher();
pairMatchingGameLauncher.play();
}
}
58 changes: 58 additions & 0 deletions src/main/java/pairmatching/db/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package pairmatching.db;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import pairmatching.domain.type.MatchingInformation;
import pairmatching.domain.type.Pair;

public class Database {

private final Map<String, Set<Pair>> memory = new HashMap<>();

public void addAll(MatchingInformation matchingInformation, List<Pair> pairs) {
memory.computeIfAbsent(matchingInformation.toString(), key -> new LinkedHashSet<>())
.addAll(pairs);
}

public boolean exist(MatchingInformation matchingInformation) {
return memory.containsKey(matchingInformation.toString());
}

public boolean existPair(String inputKey, Pair data) {
List<String> keys = findKeys(inputKey);
return keys.stream()
.map(memory::get)
.anyMatch(pairs -> matchPairs(pairs, data));
}

public Set<Pair> getAll(MatchingInformation matchingInformation) {
Set<Pair> pairs = memory.get(matchingInformation.toString());
if (pairs == null) {
return new LinkedHashSet<>();
}
return pairs;
}

public void clear() {
memory.clear();
}

public void removeKey(MatchingInformation matchingInformation) {
memory.remove(matchingInformation.toString());
}

private List<String> findKeys(String inputKey) {
return memory.keySet().stream()
.filter(key -> key.contains(inputKey))
.collect(Collectors.toList());
}

private boolean matchPairs(Set<Pair> pairs, Pair value) {
return pairs.stream()
.anyMatch(pair -> pair.match(value));
}
}
63 changes: 63 additions & 0 deletions src/main/java/pairmatching/domain/PairMatchingGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package pairmatching.domain;

import java.util.List;
import java.util.Set;
import pairmatching.domain.checker.DefaultDuplicateChecker;
import pairmatching.domain.checker.DuplicateChecker;
import pairmatching.db.Database;
import pairmatching.domain.loader.CrewLoader;
import pairmatching.domain.maker.EvenPairMaker;
import pairmatching.domain.maker.OddPairMaker;
import pairmatching.domain.maker.PairMaker;
import pairmatching.domain.type.Crew;
import pairmatching.domain.type.MatchingInformation;
import pairmatching.domain.type.Pair;
import pairmatching.exception.EmptyMatchedCrewException;

public class PairMatchingGame {

private final Database database = new Database();
private final CrewLoader crewLoader = new CrewLoader();
private final DuplicateChecker duplicateChecker = new DefaultDuplicateChecker(database);

public Set<Pair> pairMatch(MatchingInformation matchingInformation) {
duplicateChecker.checkDuplicate(matchingInformation);
List<Pair> pairs = makeCrewPairs(matchingInformation);
database.addAll(matchingInformation, pairs);
return database.getAll(matchingInformation);
}

public Set<Pair> reMatch(MatchingInformation matchingInformation) {
database.removeKey(matchingInformation);
List<Pair> pairs = makeCrewPairs(matchingInformation);
database.addAll(matchingInformation, pairs);
return database.getAll(matchingInformation);
}

public Set<Pair> showPair(MatchingInformation matchingInformation) {
Set<Pair> pairs = database.getAll(matchingInformation);
if (pairs.isEmpty()) {
throw new EmptyMatchedCrewException();
}
return pairs;
}

public void reset() {
database.clear();
}

private List<Pair> makeCrewPairs(MatchingInformation matchingInformation) {
List<Crew> names = crewLoader.getNames(matchingInformation.getCourse());
PairMaker pairMaker = createPairMaker(names.size());
List<Pair> pairs = pairMaker.createPair(names);
duplicateChecker.checkDuplicatePair(matchingInformation.getLevel().toString(), pairs);
return pairs;
}

private PairMaker createPairMaker(int number) {
if (number % 2 == 0) {
return new EvenPairMaker();
}
return new OddPairMaker();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pairmatching.domain.checker;

import java.util.List;
import pairmatching.db.Database;
import pairmatching.domain.type.MatchingInformation;
import pairmatching.domain.type.Pair;
import pairmatching.exception.DuplicateException;
import pairmatching.exception.DuplicatePairException;

public class DefaultDuplicateChecker implements DuplicateChecker {

private final Database database;

public DefaultDuplicateChecker(Database database) {
this.database = database;
}

@Override
public void checkDuplicate(MatchingInformation matchingInformation) {
if (database.exist(matchingInformation)) {
throw new DuplicateException();
}
}

@Override
public void checkDuplicatePair(String inputKey, List<Pair> pairs) {
boolean duplicatePair = pairs.stream().anyMatch(pair -> database.existPair(inputKey, pair));
if (duplicatePair) {
throw new DuplicatePairException();
}
}
}
Loading