import random
import time
# GIST 점수판 초기화
gist_scores = {total: {n: 10 for n in range(1, 4)} for total in range(1, 10)}
user_total_score = 0
gist_total_score = 0
game_round = 1
print("?? 10층 아파트 쌓기 게임 ??")
time.sleep(1)
print('\nXX 연타 하지 마세요 XX\n')
time.sleep(1.5)
print("게임 규칙:")
print("- 당신과 GIST(Game Intelligence & Strategy Trainer) 모델이 번갈아 1,2,3층 중 하나를 선택하여 총합 10층을 쌓습니다.")
time.sleep(2)
print("- 당신이 먼저 10층을 쌓으면 승리합니다.")
time.sleep(2)
print("- GIST 모델은 게임 결과에 따라 점수를 학습하며 전략이 발전합니다.")
time.sleep(2)
print("- 사용자는 첫 번째 턴에 2층을 쌓을 수 없습니다!")
time.sleep(2)
print("- 10층을 초과하면 안 됩니다.")
time.sleep(2)
# 사용자에게 GIST 이름 짓기
gist_name = input("?? 당신이 상대할 GIST 모델에게 이름을 지어주세요: ").strip()
if not gist_name:
gist_name = "GIST"
print(f"\n좋습니다! 이제부터 당신의 상대방은 '{gist_name}'입니다. 행운을 빕니다!\n")
print('로딩중')
for i in range(3):
print('.',end=' ')
time.sleep(0.5)
# 게임 시작
while True:
print(f"\n==== 게임 {game_round} 시작 ====")
total = 0
turn = "USER"
gist_history = []
first_user_turn = True
while True:
print(f"\n <층수: {total}>")
if turn == "USER":
while True:
try:
time.sleep(0.5)
print()
user_input = int(input("쌓을 층수를 고르세요(1,2,3층): "))
if user_input not in [1, 2, 3]:
print()
print("?? 1, 2, 3층 중 하나만 선택할 수 있습니다.")
continue
if first_user_turn and user_input == 2:
print()
print("?? 첫 턴에는 2층을 쌓을 수 없습니다.")
continue
if total + user_input > 10:
print()
print("?? 총 층수가 10층을 넘을 수 없습니다.")
continue
break
except ValueError:
print()
print("?? 잘못된 입력입니다.")
total += user_input
first_user_turn = False
if total == 10:
print(' <10층 달성!!>')
print("?? 당신의 승리! ??")
user_total_score += 1
# GIST가 지면 마지막 선택 점수 -1
if gist_history:
last_total, last_choice = gist_history[-1]
gist_scores[last_total][last_choice] -= 1
if gist_scores[last_total][last_choice] <= 8 and len(gist_history) >= 2:
prev_total, prev_choice = gist_history[-2]
gist_scores[prev_total][prev_choice] -= 1
break
turn = gist_name
else: # GIST 턴
if total not in gist_scores:
print(f"{gist_name}는 더 이상 선택할 수 없습니다.")
break
possible_choices = [n for n in range(1, 4) if total + n <= 10]
max_score = max(gist_scores[total][n] for n in possible_choices)
best_choices = [n for n in possible_choices if gist_scores[total][n] == max_score]
choice = random.choice(best_choices) # 동점이면 랜덤 선택
print()
print(' -생각중...')
time.sleep(0.6)
print()
print(f"?? {gist_name}는 {choice} 층을 쌓았습니다.")
print()
time.sleep(0.8)
gist_history.append((total, choice))
total += choice
if total == 10:
print(' <10층 달성!!>')
print(f"?? {gist_name} 승리! ??")
gist_total_score += 1
last_total, last_choice = gist_history[-1]
gist_scores[last_total][last_choice] += 1
if gist_scores[last_total][last_choice] >= 12 and len(gist_history) >= 2:
prev_total, prev_choice = gist_history[-2]
gist_scores[prev_total][prev_choice] += 1
break
turn = "USER"
# 한 판 종료 후 결과 출력
print(f"\n?? 게임 {game_round} 종료!")
time.sleep(0.8)
print(f" ?? 당신의 총 승점: {user_total_score}")
print(f" ?? {gist_name} 총 승점: {gist_total_score}")
print("\n?? GIST 전략 점수판:")
for total in range(1, 10):
print(f"총 층수 {total} => ", end="")
for n in range(1, 4):
print(f"{n}: {gist_scores[total][n]}", end=" ")
print()
time.sleep(0.8)
# 계속 여부 확인
while True:
again = input("\n계속 하시겠습니까? (y/n): ").strip().lower()
if again == 'y':
game_round += 1
break
elif again == 'n':
print(f'\n당신의 간식 점수... ==>> {user_total_score}')
if user_total_score>=15: #최고점수가 14점: 혹시 이 점수를 넘는 학생은 큰 간식 제공!
print('축하드립니다! 당신은 제작자의 최고점수를 넘으셨습니다!!')
elif user_total_score>=10: #마이쮸+다른 간식
print('훌룡합니다! 맛있는 간식 챙기세요!')
else: #얻은 점수를 마이쮸 개수로..
print('인간 시대의 끝이 도래했다...')
print("\n?? 지금까지 GIST 모델 강화학습 게임이였습니다! 감사합니다!")
input('키로 종료="">')
exit()
else:
print("y 또는 n으로 입력해주세요.")</enter키로>