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 |