베스킨라빈스31 게임만들기

pjh_h·2021년 12월 23일
0

오늘은 베스킨라빈스 31게임 만들기를 해보았다.

version을 2가지로 나누어 만들었다.
첫번째는 일반ver, 두번째는 무조건 컴퓨터가 이기는ver을 만들었다.

🎲 [Baskinrobbins31 Game 1]

  1. 1~31까지 란 숫자를 리스트로 만들어서 게임을 구현해보려고 하였다.
  2. 컴퓨터가 선택한 랜덤한 숫자만큼 리스트에서 숫자를 지워내려고 하였다.
  3. 구현에 실패했다.
import random

Start= random.choice(['Player','Computer'])
num_list = range(1,32)
def br31():
    for num in num_list:
        print(num)

while True:

    if Start == 'Player':
        print('Player가 선공입니다')
        p_ud = int(input('숫자를 입력하세요'))
        num_list[:num_list.index(p_ud) + 1]
        for num in num_list:
            print(num)
    else:
        print('컴퓨터가 선공입니다')
        computer = random.choice([1, 2, 3])
        num_list[:num_list.index(computer) + 1]
        for num in num_list:
            print(num)

🎲 [Baskinrobbins31 Game 1-1]

  1. 리스트 방식이 아닌 call = 0 으로 값을 정해놓고 턴마다 call 값에 더하는 방법으로 구현하였다.
  2. 컴퓨터와 플레이어의 턴을 count를 이용해서 했는데 더 쉬운 방법이 있을 것 같다.
import random


print("베스킨라빈스 31 게임 프로그램입니다!")

start = random.choice([1, 0])
start = int(start)

call = 0
count = 1

while call < 31:
    if count % 2 == start:
        # 사용자의 차례
        print('사용자의 차례')
        size_of_call = input("호출할 개수를 입력하세요 : ")
        size_of_call = int(size_of_call)

        for _ in range(size_of_call):
            if call == 31:
                break
            call += 1
            print("사용자 : '{0}'!!!".format(call))

    else:
        # 컴퓨터의 차례
        print('컴퓨터의 차례')
        size_of_call = random.randint(1, 3)

        for _ in range(size_of_call):
            if call == 31:
                break
            call += 1
            print("컴퓨터 : '{0}'!!!".format(call))

    count += 1

if count % 2 == start:
    print("사용자의 승리!!")
else:
    print("컴퓨터의 승리!!")

🎲 [Baskinrobbins31 Game 2]

  1. Baskinrobbins31 Game 1과 같으나 컴퓨터가 무조건 이겨야한다.
  2. 컴퓨터가 무조건 이길 수 밖에 없는 조건을 찾아서 추가했다.
  3. 2,6,10,14,18,22,26,30을 말하면 이긴다는 것을 알게 되었다.
import random
from random import randrange

print("베스킨라빈스 31 게임 프로그램입니다!")

start = random.choice([1, 0])
start = int(start)

call = 0
count = 1

while call < 31:
    if count % 2 == start:
        # 사용자의 차례
        print('사용자의 차례')
        size_of_call = input("호출할 개수를 입력하세요 : ")
        size_of_call = int(size_of_call)

        for _ in range(size_of_call):
            if call == 31:
                break
            call += 1
            print("사용자 : '{0}'!!!".format(call))

    else:
        # 컴퓨터의 차례
        print('컴퓨터의 차례')
        if (call + 3) % 4 == 0:
            computer = 1
        elif (call + 4) % 4 == 0:
            computer = 2
        elif (call + 5) % 4 == 0:
            computer = 3
        else:
            computer = randrange(1,4)
        size_of_call = computer

        for _ in range(size_of_call):
            if call == 31:
                break
            call += 1
            print("컴퓨터 : '{0}'!!!".format(call))

    count += 1

if count % 2 == start:
    print("사용자의 승리!!")
else:
    print("컴퓨터의 승리!!")

Baskinrobbins31 게임을 만들면서 아직 내가 미숙한 것을 느꼈다.
파이썬 기초 문법 강의를 좀 더 들어야겠다.

profile
까짓거 한번 해보죠

0개의 댓글