Problem 1~4: 게임 rule구현하기
- 두 명의 플레이어가 번갈아서 최소 100점의 총점이 되면 끝남
- 각 턴마다, 현재 플레이어는 굴릴 주사위의 개수를 최대 10개까지 선택
- 턴 점수는 주사위 결과의 합계임.
- 몇가지 조건이 있음
- Sow Sad: 아무리 많은 주사위를 던져도 한 번 1이 나오면 그 플레이어의 턴 점수는 1이다.
- Example 1: The current player rolls 7 dice, 5 of which are 1's. They score 1 point for the turn.
- Example 2: The current player rolls 4 dice, all of which are 3's. Since Sow Sad did not occur, they score 12 points for the turn.
- Oink points: roll zero 플레이어는 상대의 2 * tens - ones를 계산한 점수 또는 1점중에 더 큰 값이 점수가 된다.
- Example 1:
- The opponent has 46 points, and the current player chooses to roll zero dice. 2 * 4 - 6 = 2; which is greater than 1, so the current player gains 2 points.
- Example 2:
- The opponent has 73 points, and the current player chooses to roll zero dice. 2 * 7 - 3 = 11; which is greater than 1, so the current player gains 11 points.
- Example 3:
- The opponent has 27 points, and the current player chooses to roll zero dice. 2 * 2 - 7 = -3; which is less than or equal to 1, so the current player gains 1 points.
- Example 1:
- Pigs on Prime: toss 후 플레이어의 점수가 소수라면 점수가 즉시 다음 소수까지 상승할 수 있는 점수를 획득한다.
- 참고) 1은 소수 수는 아니지만, 이 프로젝트에서는 1을 소수라고 간주한다.
- Example:
- Both players start out at 0. (0, 0)
- Player 0 rolls 2 dice and gets 5 points. (5, 0)
- 5 is a prime number, so Player 0 instantly gains two points, so that their score increases to 7 (7, 0)
- Player 1 then takes their turn.
- Sow Sad: 아무리 많은 주사위를 던져도 한 번 1이 나오면 그 플레이어의 턴 점수는 1이다.
- 함수 설명
- roll_dice(굴릴횟수, 던질 주사위) => 리턴값이 각 턴의 결괏값임(위의 규칙을 모두 적용한)
- problem 5
- play 함수 구현하는 것이 목표
- 목표점수 도달할때까지 주사위 굴림
- turn은 한 주사위를 roll하는 걸로 정의됨
- 몇번 굴릴지 결정하기 위해 각자의 전략을 사용함
- Strategy는 player score, opponent's score 주어지면 현재 플레이어가 턴에서 굴릴 주사위 수를 return하는 기능
- 전략(Strategy)은 Phase3
- 조건(지금 지켜놔야 하는 조건들)
- 단일루프만을 사용해야 함
- 각 strategy함수는 turn마다 한 번만 호출해야 함
- 모든 룰 적용되고 끝나면 게임 끝
- 게임 끝나면 final total 스코어가 player0, player1순서로 나오고 끝남.
- 힌트(라고 쓰고 조건이라고 생각한다)
- 이미 구현한 기능을 호출해야 한다.
- who변수, next_player함수를 사용한다.
- 5개의 인수 사용해서 take_turn 호출한다.
- take_turn은 턴마다 한번씩만 호출한다.
- pigs_on_prime을 call해서 현재 플레이어가 추가점수 몇 점을 얻을지 정한다.
- 제공된 함수 next_player를 호출하여 다음 플레이어 번호(0 또는 1)를 얻을 수 있습니다.
- 지금은 play 함수에 대한 leader 변수와 say 인수를 무시해도됨.
- 당신은 problem 7에서 그것들을 사용할 것이다.
- 테스트를 잠금해제하기 위해 hog.always_roll은 hog.py에서 정의된 always_roll 함수를 나타냄
- 예시와 주의할 점
- >>> strat0 = lambda score, opponent: opponent % 10
>>> strat1 = lambda score, opponent: max((score // 10) - 4, 0)
>>> s0, s1 = hog.play(strat0, strat1, score0=71, score1=80, dice=always_seven) - >>> s0
- >>> 87 (== 71 + 16)
- >>> s1
- >>> 108 (== 80 + 4*7)
- >>> strat0 = lambda score, opponent: opponent % 10
- 코딩 시작
- 의사코드
- take_turn: 현재 플레이어의 턴 점수를 리턴하는 함수
- who는 현재플레이어를 나타냄
- 의사코드
if who == 0:
roll_turn = strategy0(who의 점수, 반대사람의점수) #이번 턴의 roll수 받기
else:
roll_turn = strategy1(who의 점수, 반대사람의점수)
score_add = take_turn(roll_turn, who점수, 반대점수, dice, goal)
# 조건문 사용해서 score0또는 1에 plus하고 그게 prime이면 추가점수주는거니까 pig prime쓰기
who = next_player(who)
- 과정 중에 오류
- score0,1숫자 잘못씀
- score0 <= goal이 아님....한 점수가 goal이랑 똑같아져도 루프 빠져나와야 하기 때문
'🏃♀️ 활동 > 프로젝트 작업일지' 카테고리의 다른 글
Project: Ants vs SomeBees(2) (0) | 2022.07.26 |
---|---|
Project: Ants vs SomeBees(1) (0) | 2022.07.26 |
Project 2: CS 61A Autocorrected Typing Software(1) (0) | 2022.07.11 |
Phase 3: Strategies of the Game (0) | 2022.07.07 |
Hog(2): Playing the Game (0) | 2022.07.07 |