Skip to content
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

숫자게임 [STEP 1] safari, malrnag #79

Merged
merged 10 commits into from
Feb 10, 2022
Merged

숫자게임 [STEP 1] safari, malrnag #79

merged 10 commits into from
Feb 10, 2022

Conversation

Siwon-L
Copy link

@Siwon-L Siwon-L commented Feb 9, 2022

@leeari95
Untitled Diagram drawio-3

진행 상황

  • 랜덤한 수를 반환할 함수 (randomInt)

 func randomInt(to: Int, from: Int) -> Int { Int.random(in: to...from) }
  • 중복이 제거된 3개의 수를 반환 할 수 있는 함수 -> Set (makeNonOverlappingNumber)

func makeNonOverlappingNumber() -> Set<Int> {
    var nonOverlappingNumber: Set<Int> = Set<Int>()
    while nonOverlappingNumber.count < 3 {
        nonOverlappingNumber.insert(randomInt(to: 1, from: 9))
    }
    return nonOverlappingNumber
}
  • 두 배열을 비교해주는 함수 (checkScore)

func checkScore(answerNumber: [Int], playerNumber: [Int]) {
    var ballScore: Int = 0
    var strikeScore: Int = 0
 ...   
}
  • 게임 시작 함수 (startGame)

func startGame() {
    let computerNumbers: [Int] = Array(makeNonOverlappingNumber())
    var gameCount: Int = 9
 ...
}

첫 번째 고민했던 부분

코딩하면서 가장 먼저 고민했던 부분은 수를 담을 타입이었습니다.

해결방법

처음엔 중복을 효율적으로 배제하기 위해 집합의 개념인 Set 타입 하나만을 사용하는 방법을 고민하였지만, 게임의 특성상 컴퓨터 번호와 임의의 번호를 비교해야 하기 때문에 Set 타임으로 랜덤 한 수를 받고, index(위치 값)로 읽어올 수 있는 배열로 담는 방법을 선택했습니다.

두 번째 고민했던 부분

그다음으로 많이 짝과 고민했던 내용은 함수의 네이밍과 코드의 가독성을 높이는 부분이었습니다.

해결 방법

최대한 한 함수에서는 하나의 기능으로만 구현하려 노력했으며, 함수 네이밍 또한, 직관적으로 알아볼 수 있도록 하였습니다. 하지만, 아직 많은 부분이 어색하게만 느껴집니다.

피드백 받고싶은 부분

함수 네이밍과 코드의 가독성에 대한 부분에 대한 피드백을 받아 보고 싶습니다.

@leeari95 leeari95 self-requested a review February 9, 2022 10:59
Copy link
Member

@leeari95 leeari95 left a comment

Choose a reason for hiding this comment

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

safari, malrnag 안녕하세요~ 리뷰를 맡은 Ari입니다~! 😁 반갑습니다~

두분 모두 STEP1 진행하느라 고생하셨어요! 🎉
올려주신 순서도진행 상황, 고민했던 부분을 공유해주신 덕분에 코드를 쉽게 파악해볼 수 있었는데요. 💯

몇가지 말씀드려볼 사항들이 있어 적어보도록 하겠습니다.
어디까지나 제 의견이고, 정답은 아니니 꼭 따르실 필요는 없답니다! 🙌🏻


FlowChart를 살펴보았어요.

  • 깔끔하게 잘 만드신 것 같아요! 다만 순서도의 각 도형들은 어떤 의미를 가지고 도형을 선택하셨는지 궁금하네요~ (순서도를 잘못 그렸다는 뜻이 아닙니다.)

실행예시가 다른 부분을 발견했는데요.🔎

  • 남은 게임 횟수남은 기회
  • 게임 한판을 진행할때마다 출력되는 문자열의 순서

  • 스텝1 요구사항과 두분이 제출한 코드의 실행예시가 다르다는 점을 알고계실까요? 이 부분은 요구사항에 맞게 수정이 필요해보입니다. 만약 실행예시와 다르게 해야하는 이유가 있다면 야곰과 논의해서 다르게 해도 되는지를 확인받아보시면 좋을 것 같습니다.😊

제약조건에 맞지 않는 부분들이 몇군데 확인됩니다.

  • 들여쓰기 2번을 초과하지 않습니다. 라는 조건을 지키지 않는 부분이 있는 것 같습니다! 함수로 인한 들여쓰기도 포함되는 것으로 알고있는데, 정확한건 야곰에게 물어보셔야할 듯 해요.
    • 저도 숫자게임 프로젝트 진행할 때 헷갈렸던 부분이라 엄청 질문했던 기억이... 🤣
func test() {
    for i in 1...2 { // 여기까진 허용!
        if ...  { // 여기서부터 초과하는 걸로 알고있어요.
            ...
        }
    }
}

코딩 컨벤션을 맞춰보시면 좋을 것 같아요.

  • 중간에 한줄로 작성되어있는 클로저가 몇개 보이더라구요! 저는 개인적으로 짧아도 무조건 풀어씁니다. 그 이유는 나중에 디버깅할 때 번거롭거든요.. 하지만 이건 그냥 개인 취향이니 참고만 해주세요.
    • 간단한 고차함수도 $0을 사용하는 축약형보다는 기본형으로 풀어쓰는게 더 보기 좋더라구요~!

커밋 메세지 스타일을 맞춰보셨을까요?

  • 커밋로그를 살펴보니 README.md 수정, 순서도 추가에 대한 커밋 메세지 부분들이 다른 커밋들과 다르네요. 커밋 규칙에 대한 부분을 다시 한번 살펴보시고 해당 커밋에 적절한 타입은 무엇일지 고민해보면 좋을 것 같아요 🤗
  • 그리고 짝프로그래밍이 제약사항인걸로 알고있는데, 커밋 로그를 살펴보니 그렇게 하지 않은 것 같아보여요. 앞으로 계속 캠프분들과 협업을 하게 될탠데, 협업자세에 대해서 고민해보셨으면 좋겠습니다. 가이드는 캠프사이트에 자세히 잘나와있는 걸로 알고있어요 😊

두분 너무 고생 많으셨어요...!
자세한 피드백은 코멘트로 달아드렸는데, 혹시 의견이 다른 부분이나 궁금한 점은 바로바로 말씀해주세요~ DM을 주셔도 좋습니다!

@@ -6,5 +6,49 @@

import Foundation

print("Hello, World!")
func randomInt(to: Int, from: Int) -> Int { Int.random(in: to...from) }
Copy link
Member

Choose a reason for hiding this comment

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

파라미터로 random 값의 범위를 설정할 수 있는 유연한 함수네요! 👏🏻👏🏻👏🏻
그런데 이 부분은 다른 함수들과 다르게 함수가 한줄로 작성되어있는데, 특별한 이유가 있을까요?
그리고 Int.random(in:) 메소드를 사용하는 것 말곤 다른 기능을 하지 않는 것 같은데
따로 메소드로 분리해준 이유도 궁금합니다!

Choose a reason for hiding this comment

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

함수또한 클로저에 포함되므로 한줄로 작성하게되면
반환값이 있더라도 return 키워드를 생략이 가능하므로 코드를 줄이기위해 한줄로 작성하였습니다!

기능은 Int.random(in: )만을 사용하고있는 함수인데
아래에 언급해주신 함수와 굳이 저렇게 따로 분리시켜줄 필요가 있을까? 라는 의문을 저희 또한 가지고있었습니다!
지금 상황에서는 randomInt 기능을 makeNonOverlappingNumbers 에 포함시키고 makeNonOverlappingNumbers 함수를 randomInt 함수처럼 유연하게 작동할수있게끔 수정할수 있을것같습니다!


func makeNonOverlappingNumber() -> Set<Int> {
Copy link
Member

@leeari95 leeari95 Feb 9, 2022

Choose a reason for hiding this comment

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

위에서는 파라미터로 수를 전달받고 있는데,
randomInt(to:from:)를 사용하는 이 함수는 파라미터가 없네요?
이 함수도 위 함수와 같이 유연하게 해줄순 없을까요?

그리고 겹치지 않는다라는 의미 보단 랜덤하다는 의미는 어떨까요!?

Choose a reason for hiding this comment

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

Ari 말씀처럼 네이밍을 기존 makeNonOverlappingNumbers 보다 makeRandomNumber 로 변경하는게 코드를 읽는 입장에서 이해하기 편할것같습니다!

func makeNonOverlappingNumber() -> Set<Int> {
var nonOverlappingNumber: Set<Int> = Set<Int>()
while nonOverlappingNumber.count < 3 {
nonOverlappingNumber.insert(randomInt(to: 1, from: 9))
Copy link
Member

Choose a reason for hiding this comment

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

계속 동일한 숫자가 insert 된다면... 불필요한 반복을 할 수도 있을 것 같아요.
운이 나빠서 같은 숫자가 나온다면 nonOverlappingNumber를 채우기 위해 10번 넘게도 반복할 것 같은데요.
이 부분에 대해 한번 고민해보셨을까요?
꼭 Set이 아니여도 Array로도 원하는 방향으로 해결해볼 수도 있을 것 같은데요~ 🤩

Choose a reason for hiding this comment

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

요구서에 Set에대해 공부해보라는 언급이 있었기에 Set을사용하여 풀기를 권장하시는것 같아 Set을 사용했었습니다!
Ari말씀처럼 운이나빠 중복된숫자가 게속나오게 될경우 반복횟수가 의도한것보다 많이 늘어날수 있을것같습니다!
지금까지 Set을 사용하면서 생각지 못했던 경우였습니다!
Array를 활용하여 중복되지 않는 값을 할당하도록 수정해보도록 하겠습니다!

var strikeScore: Int = 0

for i in 0...answerNumber.count - 1 {
if answerNumber[i] == playerNumber[i] {
Copy link
Member

@leeari95 leeari95 Feb 9, 2022

Choose a reason for hiding this comment

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

들여쓰기 2번을 초과하고 있어요. 😱
판정하는 부분을 별도의 함수로 분리한다면 어떨까요?

그리고 for문의 범위연산자를 ...이 아니라 ..<으로 범위를 설정해준다면 뒤에 - 1을 없앨 수 있을 것 같네요?!

Choose a reason for hiding this comment

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

네! 아무래도 for문안에 if 를 사용하다보니 가독성이 조금 떨어지는것같아 방법을 찾고있었습니다 ㅠ
Ari 말씀처럼 판정하는 부분을 별도의 메소드로 분리해보도록 하겠습니다!

반개방 연산자에 대해 알고는 있었으나 사용해본적이 없어 잊고있던것같습니다 ㅜㅜㅜ 역시..배우고 게속 뭔가를 만들어봐야 기억에 남는것 같습니다!

}

func startGame() {
let computerNumbers: [Int] = Array(makeNonOverlappingNumber())
Copy link
Member

Choose a reason for hiding this comment

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

Set을 Array로 바꿔주고 있는 부분이 2군데 보이고 있는데,
살펴보니 makeNonOverlappingNumber 함수는 Array로만 쓰이고 있는 거 같아요~
해당 함수의 반환타입을 Array로 수정해준다면 개선이 가능할 것 같아보여요 💪🏻

Choose a reason for hiding this comment

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

네! Set으로 반환 하는게아닌 Array 로 반환하게되면 지금처럼 따로 Array로 변경해줄 필요가 없을것 같습니다!
수정해보도록 하겠습니다!!


while true {
let playerNumbers = Array(makeNonOverlappingNumber())
if gameCount == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

승패 판정하는 기능을 따로 분리해보면 어떨까요?
여기도 마찬가지로 들여쓰기 2번을 초과하고 있네요. 🤔
기능을 분리해본다면 좋을 것 같아요!

그리고 while문의 조건이 true로 되어있는데 이 부분도 조건이 명확하지 않아서,
어떤 경우에 반복이 끝나는지? 아래 코드들을 좀더 살펴봐야하는 점이 불편한 것 같아요.
조건문을 활용해서 이 부분도 개선해보면 좋을 것 같습니다!

그리고 gameCount == 0 해당 부분에서 사용되는 0대신 다른 값으로도 대체가 가능합니다.
Int.zero를 참고해보시면 좋을 것 같네요! 되도록이면 하드코딩은 피해주시는게 좋습니다~😄

Choose a reason for hiding this comment

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

네! 들여쓰기가 2번 된다면 가독성이 많이떨어져서 해당 기능을 따로 함수로 빼두어야 하나 고민했었습니다!
분리해보도록 하겠습니다!

while 문의 조건이 gameCount > 0 일때 반복문이 실행되도록 조건을 두었었으나 while 내부에서 또다시 gameCount가 0이면 컴퓨터 승리라는 조건이 들어가게되어 똑같은 조건을 2번 검사하게 되는것 같아 조건을 true로 두고 내부에서 반복문을 종료하게끔 했었습니다!
Ari 의 피드백을 보고 생각하니 코드를 읽는 사람 입장에서는 반복문이 언제종료되는지 한번에 알수없기 때문에 가독성이 떨어지는것 같습니다 ㅠㅠ
수정해보도록 하겠습니다!

let playerNumbers = Array(makeNonOverlappingNumber())
if gameCount == 0 {
print("컴퓨터 승리...!")
break
Copy link
Member

@leeari95 leeari95 Feb 9, 2022

Choose a reason for hiding this comment

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

braek를 각 조건문마다 해주는 이유가 있을까요?

Choose a reason for hiding this comment

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

while문의 조건이 true 이기때문에 반복을 조건을 검사해서 내부에서 반복을 멈출수있게 만들다보니 내부에 break 를 사용하게 되었습니다!
위의 코멘트 문제점을 수정하여 while 내부에서 반복문 종료를 하지 않아도 될수있게 수정할수 있을것 같습니다!

gameCount -= 1
checkScore(answerNumber: computerNumbers, playerNumber: playerNumbers)
print("임의의 수 : ", terminator: "")
playerNumbers.forEach{ print($0, terminator: " ") }
Copy link
Member

Choose a reason for hiding this comment

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

오.. 고차함수를 활용해보셨네요! 멋져요!! 😆
하지만 forEach로 문자열을 하나씩 출력하는 방법말고, 다른 고차함수로 문자열을 합쳐볼 수는 없을까요? 🤔
아래 링크를 참고해보면 좋을 것 같습니다😁
swift - joined(separator:)
swift - reduce(::)

Choose a reason for hiding this comment

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

네! joined 은 String 에서만 사용할수 있기에 타입변환을 해주어야 하나? 라는 생각에 변환시키지 않고 forEach 를 사용했습니다!
Ari 코멘트를 보고나니 오히려 String 값으로 타입변환해주면 임의의수 를 출력하는 코드와 같이 한줄로 변경해서 사용할수 있게 되는군요!

그리고 reduce 에대해 공부해보니 피보나치 수열을 만드는 메서드 인것같습니다! 문자열로 변환후 사용하게되면 joined 처럼 문자열끼리 겷합 해줄수 있어 joined() 처럼 사용할수 있는것 같습니다!
언젠가 요긴하게 사용할 메서드 인것같습니다!! :)

ballScore += 1
}
}
print("\n\(strikeScore) 스트라이트, \(ballScore) 볼")
Copy link
Member

Choose a reason for hiding this comment

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

출력예시랑 다른 이유가 여기에 있는 것 같네요~?

Choose a reason for hiding this comment

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

그렇군요!! 이부분 요구서에 맞게 수정하도록 하겠습니다!

@@ -4,3 +4,5 @@

- 이 저장소를 자신의 저장소로 fork하여 프로젝트를 진행합니다


![Untitled Diagram drawio-3](https://user-images.githubusercontent.com/91936941/153184248-2997a8f8-4109-4060-91c6-ac7d04f8341d.png)
Copy link
Member

Choose a reason for hiding this comment

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

꾸준한 README 작성은 나중에 꼭 보답이 되실거에요.
캠프생활동안 화이팅입니다!!!!! 🤛🏻🤛🏻🤛🏻🤛🏻

Choose a reason for hiding this comment

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

진행 하면서 README 를 제대로 활용하지 않았습니다 ㅠㅠ
이번 짝 프로그래밍을 진행하면서 처음 시행하다보니 자꾸 서로 의견을 조율해서 코드를 작성하게 되는것 같습니다 ㅜㅜ
그러다보니 커밋 횟수도 많이 적습니다 ㅠ
step2부분에서는 좀더 제약사항을 충실히 지키며 진행해보도록 하겠습니다!

보통 README에 작성할내용은 짝 프로그램을 진행할경우 짝이 코드를 이해하기 쉽도록 설명 같은걸 작성해 넣으면 될까요~?

Copy link
Member

@leeari95 leeari95 Feb 10, 2022

Choose a reason for hiding this comment

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

보통 리드미는 프로젝트를 간단히 설명하기 위해 작성하게 됩니다.

프로젝트 설명, 실행화면, 모델구성, 뷰구성 등등... 프로젝트 설명 관련 내용

아직은 초반이라 괜찮은데, 나중에 포트폴리오로 쓸만할 프로젝트를 하게되신다면 꼼꼼히 적어두는 편이 좋겠죠?
(면접관들이 볼테니까요!)

저같은 경우에는 일단 캠프생활 동안에는 모든 프로젝트 리드미를기록의 용도
STEP 별로 작성하여 정리해놓고 있습니다.
프로젝트 기간 고민한 내용, 의문점, 트러블 슈팅, 개선한 점 등을 기록해놓는 편입니다. 😊

이건 제 리드미인데, 그냥 이런식으로도 하는구나~ 참고용으로 봐주심 좋을 것 같아요.
저는 리드미 킹왕짱👑 타코캣 선배님의 리드미를 참고하였어요!

꾸준하게 기록해두면 나중에 포트폴리오 정리할 때 요긴하게 쓰이겠죵? 🤗

Choose a reason for hiding this comment

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

그렇군요! 포트폴리오로 제출하게된다면 README를 꼼꼼히 작성하는게 도움이될것 같습니다! Ari의 README 와 타코캣의 README 참고 하겠습니다! 감사합니다 :)

Copy link
Member

Choose a reason for hiding this comment

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

꼭 포트폴리오용 뿐만아니라
문제해결했을 때 어떻게 해결했는지.. 등등.. 이전에 어떻게 했었지? 하면서 다시 찾아서 보는 경우도 허다합니다.
기록용으로는 아주 최고!!!! 꼭 쓰세요!!!! 👍🏻

Choose a reason for hiding this comment

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

지금 Ari 리드미를 읽어봤는데 굉장합니다..!!
확실히 시간이지나고 프로젝트를 다시 보게될경우 리드미를 보고 기억할수있도록 기록하면 좋을것 같아요!
꼼꼼히 작성하는 습관 들여보도록 하겠습니다!

return nonOverlappingNumber
}

func checkScore(answerNumber: [Int], playerNumber: [Int]) {
Copy link
Member

Choose a reason for hiding this comment

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

answerNumber는 좀 어색한거 같은데 다른 이름은 없을까요?
비밀스러운 숫자라든지.... 😏

Choose a reason for hiding this comment

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

네! 네이밍도 변경 해보도록 하겠습니다!

어릴적 영어공부해둘걸... 하고 후회하는 중입니다 ㅠ


func checkScore(answerNumber: [Int], playerNumber: [Int]) {
var ballScore: Int = 0
var strikeScore: Int = 0
Copy link
Member

@leeari95 leeari95 Feb 9, 2022

Choose a reason for hiding this comment

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

타입을 모두 명시해준 부분이 멋집니다. 최고...! 👍🏻
이렇게 명시해준 특별한 이유가 있을까요?

Choose a reason for hiding this comment

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

아무래도 가독성 때문에 타입을 명시해주기는 했으나.. 할당된 값을 보고 타입을 유추할수 있을것 같습니다!
보통 타입 어노테이션은 생략 할수있으면 생략 하는게 좋을지 여쭤보고 싶습니다!

Copy link
Member

@leeari95 leeari95 Feb 10, 2022

Choose a reason for hiding this comment

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

음.. 이건 스타일의 차이라서 개발자마다 다른 것 같아요!

개인적으로 저는 무슨 타입인지 알아보기 힘들 경우 (프로퍼티나 메소드체이닝으로 값을 할당해줄 경우) 기입해주는 편입니다!
할당하는 값이 한눈에도 알아보기 괜찮으면 구지 적진 않는 것 같아요!
이건 제 스타일이니 여러분들도 캠프 생활하면서 자신만의 코드 스타일을 한번 만들어보세요! 😁

Choose a reason for hiding this comment

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

네! 답변 감사합니다! 한눈에 무슨타입인지 알아보기 힘든경우에만 명시해주어도 괜찮을것 같습니다!
이전까지는 조금이라도 이해하는데 도움이될까..싶어 명시해두긴했었습니다 ㅠㅠ 한눈에 무슨타입인지 이해하기 쉽다면 굳이 명시하지 않아도 될것같습니다!!

Copy link
Member

Choose a reason for hiding this comment

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

명시해주면 가독성이 훨~~~씬 좋아지기 때문에, 좋은 습관인 것 같습니다.
대단해요!!!! 저는 그렇게 못하거든요... 😮‍💨

Choose a reason for hiding this comment

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

함수를 통해 값을 할당받는 변수나 상수의 경우 따로 타입 어노테이션을 하지 않았었는데..
게속 불편했는데도 인지하지 못해서 타입 명시해줄생각을 못했던것 같습니다 ㅠㅠ 정수나 문자 값 을 바로 할당해주는 경우엔 괜찮지만
함수의 결과 값을 리턴받는 변수의 경우 타입명시해주는게 가독성이 훨씬 좋을것 같습니다!

malrang-malrang and others added 4 commits February 10, 2022 19:05
randomInt 함수 기능 makeRandomNumber 로 병합

makeNonOverlappingNumber 에서 makeRandomNumber 으로 네이밍 변경

makeRandomNumber 함수에 파라미터를 추가하여 유연한 함수로 수정함
함수의 반환 값을 Set타입에서 Array로 변경
중복값 제거 방식을 변경하여 원하는만큼만 반복해 중복되지 않는 값을 만들어내도록 수정함

게임의 스코어를 가져오는 getScore 함수 추가

checkScore 함수에서 튜플 반환값 추가

CheckScore 함수 내부의 print구문 삭제

printGameResult 게임결과를 출력하는 함수 추가

gameStart 함수 내부에서 while 반복문을 repeat-while 로 변경
gameCount 타입 어노테이션 제거
computerNumbers,playerNumbers 타입어노테이션 추가
@@ -6,5 +6,61 @@

import Foundation

print("Hello, World!")
func makeRandomNumber(to: Int, from: Int, count: Int) -> [Int]? {
Copy link
Member

Choose a reason for hiding this comment

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

함수명이 좀더 명확해졌네요!!! 굿굿!! 👍🏻
다만 파라미터 순서는 from, to가 맞지않을까요?

Copy link
Author

Choose a reason for hiding this comment

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

앗!! 맞네요 부끄러운 실수를 했습니다.

var nonOverlappingNumber: [Int] = []
var range: Set<Int> = Set<Int>(to...from)
while nonOverlappingNumber.count < count {
guard let randomNumber: Int = range.randomElement() else { return nil }
Copy link
Member

Choose a reason for hiding this comment

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

오!? 이렇게도 해결이 가능하군요? 신박하네요!
근데 비슷~한 방법으로 배열로 해결 가능합니다! ㅎㅎ
아래를 참고하세용 ㅎㅎ
swift - shuffled()

Copy link
Author

Choose a reason for hiding this comment

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

감사합니다. 랜덤함수 중에 중복을 제거할 수 있는 방법이 없지 않을까 고민하다가 집합에 들어있는 수만 랜덤하게 뽑아낼 수 있는 방법이 있을것 같아 찾아봤는데 randomElement()를 확인하였고, 이번 프로젝트에 잘 어울릴것 같아 사용 했습니다. shuffled()도 공부해서 사용 해보도록 하겠습니다. 감사합니다.

Choose a reason for hiding this comment

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

shuffled() 을 사용하면 범위를정해서 굉장히 간단하게 중복되지 않은 값들을 얻을수있군요...! 다음에 꼭 사용해보겠습니다!


func getScore(problemNumber: [Int], solutionNumber: [Int]) -> (strikeScore: Int, ballScore: Int) {
Copy link
Member

Choose a reason for hiding this comment

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

와.. 튜플을 쓰시다니... 멋지게 리팩토링 되었네요! 👍🏻

Copy link
Author

Choose a reason for hiding this comment

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

튜플이 각 요소마다 네이밍을 달아줄 수 있어 혼돈이 없겠다고 생각하여 튜플 반환을 고려했습니다.

@leeari95
Copy link
Member

수정주신 사항 잘 확인했습니다.
추가 코멘트 남겨보았는데, 이건 다음 스텝에서 개선해보셔도 될 것 같아요.

그리고 커밋 이력을 보니까 뭉터기 커밋이 있는데, 이 부분은 커밋 단위를 좀더 고민해보셨으면 좋겠어요.
보통 커밋 단위는 기능별로 끊어냅니다!
제일 쉬운 방법은 함수 별로 커밋하기 😉
(함수는 하나의 기능이니까요!)

다음 스텝도 화이팅입니다!!!!! 💪🏻💪🏻

@leeari95 leeari95 merged commit ae026d5 into yagom-academy:5_malrang Feb 10, 2022
} else if gameCount == 0 {
print("\n컴퓨터 승리...!", terminator: "")
}
print("\n(playerStrikeScore) 스트라이크,(playerBallScore) 볼", terminator: "")
Copy link
Member

Choose a reason for hiding this comment

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

오잉!? 뭔가.. 빠진 것 같죠???
image

Choose a reason for hiding this comment

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

앗! 푸쉬 하고 풀 하면서 \ 역슬래시가 어느샌가 사라졌습니다 ㅠㅠㅠ 수정하였습니다!

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.

3 participants