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] caron #11

Open
wants to merge 3 commits into
base: rft_2_caron
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
125 changes: 125 additions & 0 deletions RockPaperScissors/RockPaperScissors.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
73A210912BAC034E00B99C0F /* RockPaperScissorsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73A210902BAC034E00B99C0F /* RockPaperScissorsTests.swift */; };
73A210CA2BAC30DB00B99C0F /* RPS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73A210C92BAC30DB00B99C0F /* RPS.swift */; };
C784841D2B5E48E300FBF8B4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C784841C2B5E48E300FBF8B4 /* AppDelegate.swift */; };
C784841F2B5E48E300FBF8B4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C784841E2B5E48E300FBF8B4 /* SceneDelegate.swift */; };
C78484212B5E48E300FBF8B4 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C78484202B5E48E300FBF8B4 /* GameViewController.swift */; };
Expand All @@ -16,7 +18,20 @@
C78484642B6A32E500FBF8B4 /* GameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C78484632B6A32E500FBF8B4 /* GameView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
73A210922BAC034E00B99C0F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C78484112B5E48E300FBF8B4 /* Project object */;
proxyType = 1;
remoteGlobalIDString = C78484182B5E48E300FBF8B4;
remoteInfo = RockPaperScissors;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
73A2108E2BAC034E00B99C0F /* RockPaperScissorsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RockPaperScissorsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
73A210902BAC034E00B99C0F /* RockPaperScissorsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RockPaperScissorsTests.swift; sourceTree = "<group>"; };
73A210C92BAC30DB00B99C0F /* RPS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RPS.swift; sourceTree = "<group>"; };
C78484192B5E48E300FBF8B4 /* RockPaperScissors.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RockPaperScissors.app; sourceTree = BUILT_PRODUCTS_DIR; };
C784841C2B5E48E300FBF8B4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C784841E2B5E48E300FBF8B4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -29,6 +44,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
73A2108B2BAC034E00B99C0F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
C78484162B5E48E300FBF8B4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -39,10 +61,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
73A2108F2BAC034E00B99C0F /* RockPaperScissorsTests */ = {
isa = PBXGroup;
children = (
73A210902BAC034E00B99C0F /* RockPaperScissorsTests.swift */,
);
path = RockPaperScissorsTests;
sourceTree = "<group>";
};
C78484102B5E48E300FBF8B4 = {
isa = PBXGroup;
children = (
C784841B2B5E48E300FBF8B4 /* RockPaperScissors */,
73A2108F2BAC034E00B99C0F /* RockPaperScissorsTests */,
C784841A2B5E48E300FBF8B4 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -51,6 +82,7 @@
isa = PBXGroup;
children = (
C78484192B5E48E300FBF8B4 /* RockPaperScissors.app */,
73A2108E2BAC034E00B99C0F /* RockPaperScissorsTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -62,6 +94,7 @@
C784841E2B5E48E300FBF8B4 /* SceneDelegate.swift */,
C78484202B5E48E300FBF8B4 /* GameViewController.swift */,
C78484632B6A32E500FBF8B4 /* GameView.swift */,
73A210C92BAC30DB00B99C0F /* RPS.swift */,
C78484222B5E48E300FBF8B4 /* Main.storyboard */,
C78484252B5E48E400FBF8B4 /* Assets.xcassets */,
C78484272B5E48E400FBF8B4 /* LaunchScreen.storyboard */,
Expand All @@ -73,6 +106,24 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
73A2108D2BAC034E00B99C0F /* RockPaperScissorsTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 73A210962BAC034E00B99C0F /* Build configuration list for PBXNativeTarget "RockPaperScissorsTests" */;
buildPhases = (
73A2108A2BAC034E00B99C0F /* Sources */,
73A2108B2BAC034E00B99C0F /* Frameworks */,
73A2108C2BAC034E00B99C0F /* Resources */,
);
buildRules = (
);
dependencies = (
73A210932BAC034E00B99C0F /* PBXTargetDependency */,
);
name = RockPaperScissorsTests;
productName = RockPaperScissorsTests;
productReference = 73A2108E2BAC034E00B99C0F /* RockPaperScissorsTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
C78484182B5E48E300FBF8B4 /* RockPaperScissors */ = {
isa = PBXNativeTarget;
buildConfigurationList = C784842D2B5E48E400FBF8B4 /* Build configuration list for PBXNativeTarget "RockPaperScissors" */;
Expand Down Expand Up @@ -100,6 +151,10 @@
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
TargetAttributes = {
73A2108D2BAC034E00B99C0F = {
CreatedOnToolsVersion = 15.0;
TestTargetID = C78484182B5E48E300FBF8B4;
};
C78484182B5E48E300FBF8B4 = {
CreatedOnToolsVersion = 15.0.1;
};
Expand All @@ -119,11 +174,19 @@
projectRoot = "";
targets = (
C78484182B5E48E300FBF8B4 /* RockPaperScissors */,
73A2108D2BAC034E00B99C0F /* RockPaperScissorsTests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
73A2108C2BAC034E00B99C0F /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
C78484172B5E48E300FBF8B4 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -137,6 +200,14 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
73A2108A2BAC034E00B99C0F /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
73A210912BAC034E00B99C0F /* RockPaperScissorsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
C78484152B5E48E300FBF8B4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -145,11 +216,20 @@
C784841D2B5E48E300FBF8B4 /* AppDelegate.swift in Sources */,
C78484642B6A32E500FBF8B4 /* GameView.swift in Sources */,
C784841F2B5E48E300FBF8B4 /* SceneDelegate.swift in Sources */,
73A210CA2BAC30DB00B99C0F /* RPS.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
73A210932BAC034E00B99C0F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C78484182B5E48E300FBF8B4 /* RockPaperScissors */;
targetProxy = 73A210922BAC034E00B99C0F /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C78484222B5E48E300FBF8B4 /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand All @@ -170,6 +250,42 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
73A210942BAC034E00B99C0F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.qussk.RockPaperScissorsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RockPaperScissors.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/RockPaperScissors";
};
name = Debug;
};
73A210952BAC034E00B99C0F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.qussk.RockPaperScissorsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RockPaperScissors.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/RockPaperScissors";
};
name = Release;
};
C784842B2B5E48E400FBF8B4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -344,6 +460,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
73A210962BAC034E00B99C0F /* Build configuration list for PBXNativeTarget "RockPaperScissorsTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
73A210942BAC034E00B99C0F /* Debug */,
73A210952BAC034E00B99C0F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C78484142B5E48E300FBF8B4 /* Build configuration list for PBXProject "RockPaperScissors" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
1 change: 1 addition & 0 deletions RockPaperScissors/RockPaperScissors/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import UIKit

//fileprivate
fileprivate enum Hand {
Copy link

Choose a reason for hiding this comment

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

Hand 타입을 추가로 정의하신 이유가 있을까요?
한번 정의한 Hand 을 공유해서 사용하는 것이 어떨까요? 공유해도 좋을 것 같습니다!

static let paper: String = "🖐️"
static let rock: String = "✊"
Expand Down
25 changes: 24 additions & 1 deletion RockPaperScissors/RockPaperScissors/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,37 @@ import UIKit

class GameViewController: UIViewController {


// var genealogy: Genealogy

override func loadView() {
view = GameView()
}

// init(genealogy: Genealogy){
// self.genealogy = genealogy
// super.init(nibName: nil, bundle: nil)
// }
//
// required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

var genealogy: Genealogy = Genealogy()
let rps: RPS = RPS(genealogy: genealogy)

guard try! rps.rpsModify(of: ["🖐️", "✊"])

else {
print("패배")
return
}

print("승리")

}


Expand Down
110 changes: 110 additions & 0 deletions RockPaperScissors/RockPaperScissors/RPS.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// RPS.swift
// RockPaperScissors
//
// Created by qussk on 3/21/24.
//

import Foundation


//GameView에 있는 fileprivate enum의 Hand를 공유해도 되는 건지.? 일단 따로 쓰긴했어요..

fileprivate enum Hand {
static let paper: String = "🖐️"
static let rock: String = "✊"
static let scissor: String = "✌️"
Comment on lines +14 to +16
Copy link

Choose a reason for hiding this comment

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

족보를 나타내는 타입에서 승, 무, 패에 대한 프로퍼티를 가지고 있는 이유가 궁금합니다!


static let hands: [String] = [paper, rock, scissor]
}

struct Genealogy {
let win = "승"
let lose = "패"
let draw = "무"

//가위바위보 족보
func determineWinner(hand: [String]) -> String {
switch hand {
case ["🖐️", "✊"] : return win
case ["🖐️", "✌️"] : return lose
case ["✊", "✌️"] : return win
case ["✊", "🖐️"] : return lose
case ["✌️", "🖐️"] : return win
case ["✌️", "✊"] : return lose
Comment on lines +29 to +34
Copy link

Choose a reason for hiding this comment

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

패를 이모지로 나타내신 이유가 있을까요?
새로 정의하신 Hand 타입을 활용해보는 것은 어떨까요?

default:
return draw
}
}

}

class RPS {
let genealogy: Genealogy
var count:[Int] = [0,0]

init(genealogy: Genealogy) {
self.genealogy = genealogy
}


func rpsModify(of rps: [String]) throws -> Bool {
Copy link

Choose a reason for hiding this comment

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

rpsModify 메서드명을 보고 어떤 역할을 수행하는 지 모호해 보입니다.
더 이해하기 쉬운 이름으로 변경할 수 있을까요?

guard rpsHandsCheck(of: rps),
!rpsEmptyCheck(of: rps)
else {
throw NSError() as Error
}

var countting = self.count

while !besttwooutOfthree(of: 3, in: countting)[0] && !besttwooutOfthree(of: 3, in: countting)[1] {
print(self.count)
Copy link

Choose a reason for hiding this comment

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

어떤 용도로 사용하는 print문일까요? 불필요하다면 제거하는 것이 어떨까요?

countting = fightToMatch(of: rps, count: self.count)

}

return fightToResult(of: besttwooutOfthree(of: 3, in: countting))
}

//손인지 확인
Copy link

Choose a reason for hiding this comment

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

꼭 필요한 주석일까요? 메서드명을 명확하게 작성해서 의도를 잘 나타내보면 좋을 것 같습니다!

private func rpsHandsCheck(of rps: [String]) -> Bool {
Copy link

Choose a reason for hiding this comment

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

API 디자인 가이드에 따라 메서드명을 동사형으로 시작해보는 것은 어떨까요?
다른 메서드도 확인해보면 좋을 것 같습니다!

return !rps.filter { Hand.hands.contains($0) }.isEmpty
}

//비어있는지 확인
private func rpsEmptyCheck(of rps: [String]) -> Bool {
return !rps.filter { $0 == "" }.isEmpty
}

//승패 확인
func fightToMatch(of rps: [String], count: [Int]) -> [Int] {
return fightToCounting(of: genealogy.determineWinner(hand: rps), counts: count)
}

//승패 카운팅
func fightToCounting(of matching: String, counts: [Int]) -> [Int] {
var counts:[Int] = counts

if matching == "승" {
counts[0] += 1
} else if matching == "패" {
counts[1] += 1
}

self.count = counts
return counts
}

//삼세판
func besttwooutOfthree(of target: Int, in counting: [Int]) -> [Bool] {
return counting.map { $0 == target } //[true, false]
}


//삼세판후 대결 결과
func fightToResult(of countingResult: [Bool]) -> Bool {
//index0 = 나
//index1 = 컴퓨터
return countingResult[0]
}
}
Loading