Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 게임을 시작할 때 몇명이 플레이어의 수를 결정합니다.
- # 3. x2카드 추가 : [X]
- ## x2 카드는 다음 차례의 플레이어(혹은 컴퓨터)에게 두장의 카드를 내게 합니다.
- # 4. reverse카드 추가 : [X]
- ## reverse 카드는 게임의 순서를 역순으로 바꿉니다.
- # 5. 컴퓨터 추가 : [X]
- # 6. sum이 보이지 않게 하기 : [X]
- ## 여럿이서게임을 할 때 (자동으로 게임을 하는)컴퓨터를 추가합니다.
- ## 컴퓨터가 가진 카드는 보이지 않아야 하며, 항상 "게임에 패배하지 않는" 카드를 제출해야 합니다.
- ## (단, 가진 카드 중 어떤 카드를 내더라도 패배할 경우는 제외)
- ## 위 조건 이외에 추가기능은 (기존의 규칙을 바꾸지 않는 한도 내에서) 자유롭게 변경이 가능합니다.
- ## 또한 아래 카드의 구조(cards) 역시 마음대로 바꿔도 되지만 게임의 기능 자체는 유지해야 합니다.
- import random
- cards = (
- 0,0,0,0, # 0 카드 4장
- 76, # 76 카드 1장
- -10,-10,-10,-10, # -10 카드 4장
- 11,22,33,44,55,66, # 11,22,33,44,55,66 카드 각 1장
- 2,2,2, # 2 카드 3장
- 3,3,3, # 3 카드 3장
- 4,4,4, # 4 카드 3장
- 5,5,5, # 5 카드 3장
- 6,6,6, # 6 카드 3장
- 7,7,7, # 7 카드 3장
- 8,8,8, # 8 카드 3장
- 9,9,9, # 9 카드 3장
- 10,10,10,10,10,10,10,10, # 10 카드 8장
- # "2x","2x","2x","2x",
- # "rev","rev","rev","rev","rev",
- )
- def shuffle(cards) :
- random.shuffle(cards)
- return cards
- def draws(n,cards) :
- result = []
- while n > 0 :
- result.append(cards.pop())
- n -= 1
- return result
- def print_card(card) :
- if card == -10 :
- print("|-10|", end=" ")
- elif card < 10 :
- print("| "+str(card)+"| ", end="")
- else :
- print("| "+str(card)+"| ", end="")
- def print_hand(cards) :
- print(" 1 2 3 4 5")
- print("/---\\ /---\\ /---\\ /---\\ /---\\ ")
- for card in cards :
- print_card(card)
- print("\n\\---/ \\---/ \\---/ \\---/ \\---/ ")
- def print_board(x) :
- print(" --------")
- if x >= 10 :
- print(" "+str(x))
- else :
- print(" "+str(x))
- print(" --------")
- num_of_players = 4
- def pick(n, hand, deck) :
- a_card = hand[n-1]
- hand[n-1] = draws(1, deck)[0]
- return a_card
- def submit(card, sum) :
- return sum + card
- on = True
- while on :
- print("shuffle cards...")
- deck = shuffle(list(cards))
- hands = []
- for i in range(num_of_players) :
- hand = draws(5, deck)
- hands.append(hand)
- if deck == 0 :
- random.shuffle(list(a_card))
- # sum : 각 플레이어(혹은 컴퓨터)가 제출한 카드의 합을 누적하는 변수.
- # 이 값이 11,22,33,44,55,66 혹은 77 이상이 되도록 카드를 제출한 사람은 패배합니다.
- sum = 0
- game = True
- while game :
- for i in range(num_of_players) :
- print_board(sum)
- print("-------------------------------")
- print("[player "+str(i+1)+"]'s hand...")
- print("-------------------------------")
- print_hand(hands[i])
- print("-------------------------------")
- n = int(input("choose a card to submit (1-5) : "))
- a_card = pick(n, hands[i], deck)
- sum = submit(a_card, sum)
- if sum >= 77 or sum == 11 or sum == 22 or sum == 33 or sum == 44 or sum == 55 or sum == 66 :
- print ("lose")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement