From 036ebe7515b4b8c342d6de9ed8fefcd36b7ad6a6 Mon Sep 17 00:00:00 2001 From: notalentprogrammer Date: Mon, 12 May 2025 22:17:12 +0900 Subject: [PATCH] Change storage file structure --- {Baekjoon => code_study/Baekjoon}/c/1000.c | 0 {Baekjoon => code_study/Baekjoon}/c/1001.c | 0 {Baekjoon => code_study/Baekjoon}/c/1008.c | 0 {Baekjoon => code_study/Baekjoon}/c/10430.c | 0 {Baekjoon => code_study/Baekjoon}/c/10869.c | 0 {Baekjoon => code_study/Baekjoon}/c/10926.c | 0 {Baekjoon => code_study/Baekjoon}/c/10998.c | 0 {Baekjoon => code_study/Baekjoon}/c/11382.c | 0 {Baekjoon => code_study/Baekjoon}/c/1330.c | 0 {Baekjoon => code_study/Baekjoon}/c/14681.c | 0 {Baekjoon => code_study/Baekjoon}/c/18108.c | 0 {Baekjoon => code_study/Baekjoon}/c/2480.c | 0 {Baekjoon => code_study/Baekjoon}/c/2525.c | 0 {Baekjoon => code_study/Baekjoon}/c/2557.c | 0 {Baekjoon => code_study/Baekjoon}/c/2588.c | 0 {Baekjoon => code_study/Baekjoon}/c/2753.c | 0 {Baekjoon => code_study/Baekjoon}/c/2884.c | 0 {Baekjoon => code_study/Baekjoon}/c/9498.c | 0 {Baekjoon => code_study/Baekjoon}/c/foo.c | 0 {Baekjoon => code_study/Baekjoon}/js/1000.js | 0 {Baekjoon => code_study/Baekjoon}/js/1001.js | 0 {Baekjoon => code_study/Baekjoon}/js/1008.js | 0 {Baekjoon => code_study/Baekjoon}/js/10430.js | 0 {Baekjoon => code_study/Baekjoon}/js/10869.js | 0 {Baekjoon => code_study/Baekjoon}/js/10926.js | 0 {Baekjoon => code_study/Baekjoon}/js/10998.js | 0 {Baekjoon => code_study/Baekjoon}/js/11382.js | 0 {Baekjoon => code_study/Baekjoon}/js/18108.js | 0 {Baekjoon => code_study/Baekjoon}/js/2557.js | 0 {Baekjoon => code_study/Baekjoon}/js/2588.js | 0 {Baekjoon => code_study/Baekjoon}/js/foo.js | 0 .../Baekjoon}/python/1000.py | 0 .../Baekjoon}/python/1001.py | 0 .../Baekjoon}/python/1008.py | 0 .../Baekjoon}/python/10430.py | 0 .../Baekjoon}/python/10869.py | 0 .../Baekjoon}/python/10926.py | 0 .../Baekjoon}/python/10998.py | 0 .../Baekjoon}/python/11382.py | 0 .../Baekjoon}/python/1330.py | 0 .../Baekjoon}/python/14681.py | 0 .../Baekjoon}/python/18108.py | 0 .../Baekjoon}/python/2480.py | 0 .../Baekjoon}/python/2525.py | 0 .../Baekjoon}/python/2557.py | 0 .../Baekjoon}/python/2588.py | 0 .../Baekjoon}/python/2753.py | 0 .../Baekjoon}/python/2884.py | 0 .../Baekjoon}/python/9498.py | 0 .../Baekjoon}/python/foo.py | 0 just_code/game/chinchiro.py | 303 ++++++++++++++++++ just_code/game/ecard.py | 220 +++++++++++++ just_code/lotto_sim.py | 102 ++++++ just_code/result_250508_210108.txt | 21 ++ 54 files changed, 646 insertions(+) rename {Baekjoon => code_study/Baekjoon}/c/1000.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/1001.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/1008.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/10430.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/10869.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/10926.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/10998.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/11382.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/1330.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/14681.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/18108.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/2480.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/2525.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/2557.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/2588.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/2753.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/2884.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/9498.c (100%) rename {Baekjoon => code_study/Baekjoon}/c/foo.c (100%) rename {Baekjoon => code_study/Baekjoon}/js/1000.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/1001.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/1008.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/10430.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/10869.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/10926.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/10998.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/11382.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/18108.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/2557.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/2588.js (100%) rename {Baekjoon => code_study/Baekjoon}/js/foo.js (100%) rename {Baekjoon => code_study/Baekjoon}/python/1000.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/1001.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/1008.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/10430.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/10869.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/10926.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/10998.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/11382.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/1330.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/14681.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/18108.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/2480.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/2525.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/2557.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/2588.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/2753.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/2884.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/9498.py (100%) rename {Baekjoon => code_study/Baekjoon}/python/foo.py (100%) create mode 100644 just_code/game/chinchiro.py create mode 100755 just_code/game/ecard.py create mode 100644 just_code/lotto_sim.py create mode 100644 just_code/result_250508_210108.txt diff --git a/Baekjoon/c/1000.c b/code_study/Baekjoon/c/1000.c similarity index 100% rename from Baekjoon/c/1000.c rename to code_study/Baekjoon/c/1000.c diff --git a/Baekjoon/c/1001.c b/code_study/Baekjoon/c/1001.c similarity index 100% rename from Baekjoon/c/1001.c rename to code_study/Baekjoon/c/1001.c diff --git a/Baekjoon/c/1008.c b/code_study/Baekjoon/c/1008.c similarity index 100% rename from Baekjoon/c/1008.c rename to code_study/Baekjoon/c/1008.c diff --git a/Baekjoon/c/10430.c b/code_study/Baekjoon/c/10430.c similarity index 100% rename from Baekjoon/c/10430.c rename to code_study/Baekjoon/c/10430.c diff --git a/Baekjoon/c/10869.c b/code_study/Baekjoon/c/10869.c similarity index 100% rename from Baekjoon/c/10869.c rename to code_study/Baekjoon/c/10869.c diff --git a/Baekjoon/c/10926.c b/code_study/Baekjoon/c/10926.c similarity index 100% rename from Baekjoon/c/10926.c rename to code_study/Baekjoon/c/10926.c diff --git a/Baekjoon/c/10998.c b/code_study/Baekjoon/c/10998.c similarity index 100% rename from Baekjoon/c/10998.c rename to code_study/Baekjoon/c/10998.c diff --git a/Baekjoon/c/11382.c b/code_study/Baekjoon/c/11382.c similarity index 100% rename from Baekjoon/c/11382.c rename to code_study/Baekjoon/c/11382.c diff --git a/Baekjoon/c/1330.c b/code_study/Baekjoon/c/1330.c similarity index 100% rename from Baekjoon/c/1330.c rename to code_study/Baekjoon/c/1330.c diff --git a/Baekjoon/c/14681.c b/code_study/Baekjoon/c/14681.c similarity index 100% rename from Baekjoon/c/14681.c rename to code_study/Baekjoon/c/14681.c diff --git a/Baekjoon/c/18108.c b/code_study/Baekjoon/c/18108.c similarity index 100% rename from Baekjoon/c/18108.c rename to code_study/Baekjoon/c/18108.c diff --git a/Baekjoon/c/2480.c b/code_study/Baekjoon/c/2480.c similarity index 100% rename from Baekjoon/c/2480.c rename to code_study/Baekjoon/c/2480.c diff --git a/Baekjoon/c/2525.c b/code_study/Baekjoon/c/2525.c similarity index 100% rename from Baekjoon/c/2525.c rename to code_study/Baekjoon/c/2525.c diff --git a/Baekjoon/c/2557.c b/code_study/Baekjoon/c/2557.c similarity index 100% rename from Baekjoon/c/2557.c rename to code_study/Baekjoon/c/2557.c diff --git a/Baekjoon/c/2588.c b/code_study/Baekjoon/c/2588.c similarity index 100% rename from Baekjoon/c/2588.c rename to code_study/Baekjoon/c/2588.c diff --git a/Baekjoon/c/2753.c b/code_study/Baekjoon/c/2753.c similarity index 100% rename from Baekjoon/c/2753.c rename to code_study/Baekjoon/c/2753.c diff --git a/Baekjoon/c/2884.c b/code_study/Baekjoon/c/2884.c similarity index 100% rename from Baekjoon/c/2884.c rename to code_study/Baekjoon/c/2884.c diff --git a/Baekjoon/c/9498.c b/code_study/Baekjoon/c/9498.c similarity index 100% rename from Baekjoon/c/9498.c rename to code_study/Baekjoon/c/9498.c diff --git a/Baekjoon/c/foo.c b/code_study/Baekjoon/c/foo.c similarity index 100% rename from Baekjoon/c/foo.c rename to code_study/Baekjoon/c/foo.c diff --git a/Baekjoon/js/1000.js b/code_study/Baekjoon/js/1000.js similarity index 100% rename from Baekjoon/js/1000.js rename to code_study/Baekjoon/js/1000.js diff --git a/Baekjoon/js/1001.js b/code_study/Baekjoon/js/1001.js similarity index 100% rename from Baekjoon/js/1001.js rename to code_study/Baekjoon/js/1001.js diff --git a/Baekjoon/js/1008.js b/code_study/Baekjoon/js/1008.js similarity index 100% rename from Baekjoon/js/1008.js rename to code_study/Baekjoon/js/1008.js diff --git a/Baekjoon/js/10430.js b/code_study/Baekjoon/js/10430.js similarity index 100% rename from Baekjoon/js/10430.js rename to code_study/Baekjoon/js/10430.js diff --git a/Baekjoon/js/10869.js b/code_study/Baekjoon/js/10869.js similarity index 100% rename from Baekjoon/js/10869.js rename to code_study/Baekjoon/js/10869.js diff --git a/Baekjoon/js/10926.js b/code_study/Baekjoon/js/10926.js similarity index 100% rename from Baekjoon/js/10926.js rename to code_study/Baekjoon/js/10926.js diff --git a/Baekjoon/js/10998.js b/code_study/Baekjoon/js/10998.js similarity index 100% rename from Baekjoon/js/10998.js rename to code_study/Baekjoon/js/10998.js diff --git a/Baekjoon/js/11382.js b/code_study/Baekjoon/js/11382.js similarity index 100% rename from Baekjoon/js/11382.js rename to code_study/Baekjoon/js/11382.js diff --git a/Baekjoon/js/18108.js b/code_study/Baekjoon/js/18108.js similarity index 100% rename from Baekjoon/js/18108.js rename to code_study/Baekjoon/js/18108.js diff --git a/Baekjoon/js/2557.js b/code_study/Baekjoon/js/2557.js similarity index 100% rename from Baekjoon/js/2557.js rename to code_study/Baekjoon/js/2557.js diff --git a/Baekjoon/js/2588.js b/code_study/Baekjoon/js/2588.js similarity index 100% rename from Baekjoon/js/2588.js rename to code_study/Baekjoon/js/2588.js diff --git a/Baekjoon/js/foo.js b/code_study/Baekjoon/js/foo.js similarity index 100% rename from Baekjoon/js/foo.js rename to code_study/Baekjoon/js/foo.js diff --git a/Baekjoon/python/1000.py b/code_study/Baekjoon/python/1000.py similarity index 100% rename from Baekjoon/python/1000.py rename to code_study/Baekjoon/python/1000.py diff --git a/Baekjoon/python/1001.py b/code_study/Baekjoon/python/1001.py similarity index 100% rename from Baekjoon/python/1001.py rename to code_study/Baekjoon/python/1001.py diff --git a/Baekjoon/python/1008.py b/code_study/Baekjoon/python/1008.py similarity index 100% rename from Baekjoon/python/1008.py rename to code_study/Baekjoon/python/1008.py diff --git a/Baekjoon/python/10430.py b/code_study/Baekjoon/python/10430.py similarity index 100% rename from Baekjoon/python/10430.py rename to code_study/Baekjoon/python/10430.py diff --git a/Baekjoon/python/10869.py b/code_study/Baekjoon/python/10869.py similarity index 100% rename from Baekjoon/python/10869.py rename to code_study/Baekjoon/python/10869.py diff --git a/Baekjoon/python/10926.py b/code_study/Baekjoon/python/10926.py similarity index 100% rename from Baekjoon/python/10926.py rename to code_study/Baekjoon/python/10926.py diff --git a/Baekjoon/python/10998.py b/code_study/Baekjoon/python/10998.py similarity index 100% rename from Baekjoon/python/10998.py rename to code_study/Baekjoon/python/10998.py diff --git a/Baekjoon/python/11382.py b/code_study/Baekjoon/python/11382.py similarity index 100% rename from Baekjoon/python/11382.py rename to code_study/Baekjoon/python/11382.py diff --git a/Baekjoon/python/1330.py b/code_study/Baekjoon/python/1330.py similarity index 100% rename from Baekjoon/python/1330.py rename to code_study/Baekjoon/python/1330.py diff --git a/Baekjoon/python/14681.py b/code_study/Baekjoon/python/14681.py similarity index 100% rename from Baekjoon/python/14681.py rename to code_study/Baekjoon/python/14681.py diff --git a/Baekjoon/python/18108.py b/code_study/Baekjoon/python/18108.py similarity index 100% rename from Baekjoon/python/18108.py rename to code_study/Baekjoon/python/18108.py diff --git a/Baekjoon/python/2480.py b/code_study/Baekjoon/python/2480.py similarity index 100% rename from Baekjoon/python/2480.py rename to code_study/Baekjoon/python/2480.py diff --git a/Baekjoon/python/2525.py b/code_study/Baekjoon/python/2525.py similarity index 100% rename from Baekjoon/python/2525.py rename to code_study/Baekjoon/python/2525.py diff --git a/Baekjoon/python/2557.py b/code_study/Baekjoon/python/2557.py similarity index 100% rename from Baekjoon/python/2557.py rename to code_study/Baekjoon/python/2557.py diff --git a/Baekjoon/python/2588.py b/code_study/Baekjoon/python/2588.py similarity index 100% rename from Baekjoon/python/2588.py rename to code_study/Baekjoon/python/2588.py diff --git a/Baekjoon/python/2753.py b/code_study/Baekjoon/python/2753.py similarity index 100% rename from Baekjoon/python/2753.py rename to code_study/Baekjoon/python/2753.py diff --git a/Baekjoon/python/2884.py b/code_study/Baekjoon/python/2884.py similarity index 100% rename from Baekjoon/python/2884.py rename to code_study/Baekjoon/python/2884.py diff --git a/Baekjoon/python/9498.py b/code_study/Baekjoon/python/9498.py similarity index 100% rename from Baekjoon/python/9498.py rename to code_study/Baekjoon/python/9498.py diff --git a/Baekjoon/python/foo.py b/code_study/Baekjoon/python/foo.py similarity index 100% rename from Baekjoon/python/foo.py rename to code_study/Baekjoon/python/foo.py diff --git a/just_code/game/chinchiro.py b/just_code/game/chinchiro.py new file mode 100644 index 0000000..8e7b41c --- /dev/null +++ b/just_code/game/chinchiro.py @@ -0,0 +1,303 @@ +import random +import time +import os +from colorama import Fore, Back, Style, init + +init(autoreset=True) + +def clear_screen(): + os.system('cls' if os.name == 'nt' else 'clear') + +def print_title(): + title = """ + ██████╗██╗ ██╗██╗███╗ ██╗ ██████╗██╗ ██╗██╗██████╗ ██████╗ + ██╔════╝██║ ██║██║████╗ ██║██╔════╝██║ ██║██║██╔══██╗██╔═══██╗ + ██║ ███████║██║██╔██╗ ██║██║ ███████║██║██████╔╝██║ ██║ + ██║ ██╔══██║██║██║╚██╗██║██║ ██╔══██║██║██╔══██╗██║ ██║ + ╚██████╗██║ ██║██║██║ ╚████║╚██████╗██║ ██║██║██║ ██║╚██████╔╝ + ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═════╝ + """ + print(Fore.CYAN + Style.BRIGHT + title) + print(Fore.YELLOW + Style.BRIGHT + "Created by songyc.eng".rjust(50)) + print(Fore.GREEN + "\n시작은 Enter, 종료는 q + Enter를 눌러주세용!") + +def print_dice(dice): + dice_art = [ + ["┌─────────┐", + "│ │", + "│ ● │", + "│ │", + "└─────────┘"], + ["┌─────────┐", + "│ ● │", + "│ │", + "│ ● │", + "└─────────┘"], + ["┌─────────┐", + "│ ● │", + "│ ● │", + "│ ● │", + "└─────────┘"], + ["┌─────────┐", + "│ ● ● │", + "│ │", + "│ ● ● │", + "└─────────┘"], + ["┌─────────┐", + "│ ● ● │", + "│ ● │", + "│ ● ● │", + "└─────────┘"], + ["┌─────────┐", + "│ ● ● │", + "│ ● ● │", + "│ ● ● │", + "└─────────┘"] + ] + + for i in range(5): + for die in dice: + print(Fore.WHITE + dice_art[die-1][i], end=" ") + print() + +def get_hand_name(dice): + dice.sort() + if dice == [1, 2, 3]: + return "히후미" + elif dice == [4, 5, 6]: + return "시고로" + elif dice[0] == dice[1] == dice[2]: + if dice[0] == 1: + return "핀조로" + else: + return f"아라시({dice[0]})" + elif dice[0] == dice[1] or dice[1] == dice[2]: + return f"눈 있음({dice[2] if dice[0] == dice[1] else dice[0]})" + else: + return "눈 없음" + +def compare_hands(hand1, hand2): + hand_order = ["눈 없음", "히후미", "눈 있음(1)", "눈 있음(2)", "눈 있음(3)", "눈 있음(4)", "눈 있음(5)", "눈 있음(6)", "시고로", "아라시(2)", "아라시(3)", "아라시(4)", "아라시(5)", "아라시(6)", "핀조로"] + + if hand1 == hand2: + return 0 + elif hand1 == "히후미" and hand2 == "눈 없음" or hand2 == "히후미" and hand1 == "눈 없음": + return 0 + else: + return hand_order.index(hand1) - hand_order.index(hand2) + +def roll_dice_animation(players, money, hands, parent, bets, current_player): + dice_faces = [ + ["┌─────────┐", "│ │", "│ ● │", "│ │", "└─────────┘"], + ["┌─────────┐", "│ ● │", "│ │", "│ ● │", "└─────────┘"], + ["┌─────────┐", "│ ● │", "│ ● │", "│ ● │", "└─────────┘"], + ["┌─────────┐", "│ ● ● │", "│ │", "│ ● ● │", "└─────────┘"], + ["┌─────────┐", "│ ● ● │", "│ ● │", "│ ● ● │", "└─────────┘"], + ["┌─────────┐", "│ ● ● │", "│ ● ● │", "│ ● ● │", "└─────────┘"] + ] + + for _ in range(5): # 애니메이션 5번 반복 + dice = [random.randint(1, 6) for _ in range(3)] + clear_screen() + display_status(players, money, hands, parent, bets, current_player) + for i in range(5): + for die in dice: + print(dice_faces[die - 1][i], end=" ") + print() + print("\n주사위 굴리는 중...\n") + time.sleep(0.3) + + final_dice = [random.randint(1, 6) for _ in range(3)] + clear_screen() + display_status(players, money, hands, parent, bets, current_player) + for i in range(5): + for die in final_dice: + print(dice_faces[die - 1][i], end=" ") + print() + time.sleep(0.3) # 0.3초 딜레이 + return final_dice + +def computer_bet(remaining_money, parent_money): + max_bet = min(int(remaining_money * 0.6), parent_money) + return random.randint(1, max_bet) if max_bet > 0 else 0 + +def display_status(players, money, hands, parent, bets, current_player): + print("\n===== 플레이어 상태 =====") + for player in players: + hand = hands.get(player, "") + status = "파산" if money[player] <= 0 else f"{money[player]}원" + bet_info = f"배팅: {bets.get(player, '-')}원" if player != parent else "" + parent_indicator = Fore.YELLOW + "👑 " if player == parent else "" + current_indicator = Fore.CYAN + "▶ " if player == current_player else "" + player_name = f"{current_indicator}{parent_indicator}{player}" + print(f"{player_name:<15}: {Fore.GREEN}{status:<10} {Fore.MAGENTA}{hand:<10} {Fore.WHITE}{bet_info}") + print("==========================\n") + +def roll_dice_with_input(player, players, money, hands, parent, bets, current_player): + for i in range(3): + input(f"{i+1}번째 주사위 굴리기 (Enter를 누르세요)...") + dice = roll_dice_animation(players, money, hands, parent, bets, current_player) + hand = get_hand_name(dice) + print(f"결과: {hand}") + if hand != "눈 없음": + return dice, hand + return dice, hand + +def play_game(players, initial_money): + money = {player: initial_money for player in players} + parent_index = 0 + game_count = 0 + + while len([p for p in players if money[p] > 0]) > 1: + clear_screen() + print(Fore.CYAN + f"\n===== 게임 {game_count + 1} =====") + + # 파산하지 않은 부모 선택 + while money[players[parent_index]] <= 0: + parent_index = (parent_index + 1) % len(players) + parent = players[parent_index] + + hands = {} + bets = {} + display_status(players, money, hands, parent, bets, "") + + for player in players: + if player != parent and money[player] > 0: + if player == "나": + while True: + try: + bet = int(input(f"{player}의 배팅액: ")) + if 0 < bet <= money[player] and bet <= money[parent]: + bets[player] = bet + break + else: + print("유효하지 않은 배팅액입니다.") + except ValueError: + print("숫자를 입력해주세요.") + else: + bets[player] = computer_bet(money[player], money[parent]) + print(f"{player}의 배팅액: {bets[player]}") + display_status(players, money, hands, parent, bets, player) + + # 부모가 주사위를 던짐 + print(f"\n{parent}(부모)의 차례:") + dice, hand = roll_dice_with_input(parent, players, money, hands, parent, bets, parent) + hands[parent] = hand + print(f"족보: {Fore.MAGENTA}{hand}") + display_status(players, money, hands, parent, bets, parent) + + # 자식들이 차례로 주사위를 던짐 + for player in players: + if player != parent and money[player] > 0: + print(f"\n{player}의 차례:") + dice, hand = roll_dice_with_input(player, players, money, hands, parent, bets, player) + hands[player] = hand + print(f"족보: {Fore.MAGENTA}{hand}") + display_status(players, money, hands, parent, bets, player) + + # 승패 결정 및 돈 이동 + for player, bet in bets.items(): + result = compare_hands(hands[parent], hands[player]) + if result > 0: + win_amount = bet + if hands[parent] == "시고로": + win_amount *= 2 + elif hands[parent].startswith("아라시"): + win_amount *= 3 + elif hands[parent] == "핀조로": + win_amount *= 5 + elif hands[player] == "히후미": + win_amount *= 2 + if hands[parent] == "시고로": + win_amount *= 2 + elif hands[parent].startswith("아라시"): + win_amount *= 3 + elif hands[parent] == "핀조로": + win_amount *= 5 + win_amount = min(win_amount, money[player]) # 가진 돈 이상으로 잃지 않도록 + money[parent] += win_amount + money[player] -= win_amount + print(f"{Fore.GREEN}{parent}가 {player}에게서 {win_amount}원을 얻었습니다.") + elif result < 0: + loss_amount = bet + if hands[player] == "시고로": + loss_amount *= 2 + elif hands[player].startswith("아라시"): + loss_amount *= 3 + elif hands[player] == "핀조로": + loss_amount *= 5 + elif hands[parent] == "히후미": + loss_amount *= 2 + if hands[player] == "시고로": + loss_amount *= 2 + elif hands[player].startswith("아라시"): + loss_amount *= 3 + elif hands[player] == "핀조로": + loss_amount *= 5 + loss_amount = min(loss_amount, money[parent]) # 가진 돈 이상으로 잃지 않도록 + money[parent] -= loss_amount + money[player] += loss_amount + print(f"{Fore.RED}{parent}가 {player}에게 {loss_amount}원을 잃었습니다.") + else: + print(f"{Fore.YELLOW}{parent}와 {player}의 승부는 무승부입니다.") + + # 파산한 플레이어 처리 + for player in players: + if money[player] <= 0: + print(f"{Fore.RED}{player}가 파산했습니다.") + + game_count += 1 + if game_count % 2 == 0: + parent_index = (parent_index + 1) % len(players) + + if len([p for p in players if money[p] > 0]) <= 1: + break + + input("\n다음 게임을 시작하려면 Enter를 누르세요...") + + input("게임이 종료됩니다. 결과를 확인하시려면 Enter...") + clear_screen() + print(Fore.CYAN + "\n===== 게임 종료 =====") + rankings = sorted(players, key=lambda p: money[p], reverse=True) + for i, player in enumerate(rankings, 1): + print(f"{i}등: {player} ({money[player]}원)") + +def main(): + while True: + clear_screen() + print_title() + choice = input().lower() + if choice == 'q': + print("게임을 종료합니다.") + break + + while True: + try: + num_players = int(input("플레이어 수를 입력하세요 (2-8): ")) + if 2 <= num_players <= 8: + break + else: + print("2에서 8 사이의 숫자를 입력해주세요.") + except ValueError: + print("유효한 숫자를 입력해주세요.") + + while True: + try: + initial_money = int(input("초기 소지금을 입력하세요 (1000-1000000): ")) + if 1000 <= initial_money <= 1000000: + break + else: + print("1000에서 1000000 사이의 숫자를 입력해주세요.") + except ValueError: + print("유효한 숫자를 입력해주세요.") + + players = ["나"] + [f"컴퓨터{i}" for i in range(1, num_players)] + play_game(players, initial_money) + + play_again = input("다시 플레이하시겠습니까? (y/n): ").lower() + if play_again != 'y': + print("게임을 종료합니다.") + break + +if __name__ == "__main__": + main() diff --git a/just_code/game/ecard.py b/just_code/game/ecard.py new file mode 100755 index 0000000..87f9f93 --- /dev/null +++ b/just_code/game/ecard.py @@ -0,0 +1,220 @@ +import os +import random +import sys + +# ANSI 색상 코드 +RED = "\033[91m" +GREEN = "\033[92m" +YELLOW = "\033[93m" +BLUE = "\033[94m" +MAGENTA = "\033[95m" +CYAN = "\033[96m" +RESET = "\033[0m" + +# 카드 ASCII 아트 +CARD_ART = { + "Emperor": f"""{YELLOW} + ┌─────────────────┐ + │E │ + │ ♔♔♔♔♔♔♔♔♔ │ + │ ♔ EMPEROR ♔ │ + │ ♔♔♔♔♔♔♔♔♔ │ + │ E│ + └─────────────────┘{RESET}""", + "Slave": f"""{BLUE} + ┌─────────────────┐ + │S │ + │ ⚓⚓⚓⚓⚓⚓⚓⚓⚓ │ + │ ⚓ SLAVE ⚓ │ + │ ⚓⚓⚓⚓⚓⚓⚓⚓⚓ │ + │ S│ + └─────────────────┘{RESET}""", + "Citizen": f"""{GREEN} + ┌─────────────────┐ + │C │ + │ ☺☺☺☺☺☺☺☺☺ │ + │ ☺ CITIZEN ☺ │ + │ ☺☺☺☺☺☺☺☺☺ │ + │ C│ + └─────────────────┘{RESET}""" +} + +def clear_screen(): + os.system('clear') + +def get_key(): + return sys.stdin.read(1) + +def title_screen(): + clear_screen() + print(f"{CYAN}========================{RESET}") + print(f"{MAGENTA} E 카드 {RESET}") + print(f"{YELLOW} 제작자: songyc.eng{RESET}") + print(f"{CYAN}========================{RESET}") + print("엔터를 눌러 시작하세요") + while True: + if get_key() == '\n': + break + +def initialize_game(): + return { + "player_money": 100, + "computer_money": 100, + "round": 1, + "player_role": "Emperor", + "computer_role": "Slave", + "set_results": [] + } + +def create_deck(role): + if role == "Emperor": + return ["Emperor"] + ["Citizen"] * 4 + elif role == "Slave": + return ["Slave"] + ["Citizen"] * 4 + +def display_cards(cards, cursor_index): + for i, card in enumerate(cards): + if i == cursor_index: + print(f"{RED}>{RESET} {CARD_ART[card]}") + else: + print(f" {CARD_ART[card]}") + +def compare_cards(player_card, computer_card): + if player_card == "Emperor" and computer_card == "Citizen": + return "Player" + elif player_card == "Citizen" and computer_card == "Slave": + return "Player" + elif player_card == "Slave" and computer_card == "Emperor": + return "Player" + elif computer_card == "Emperor" and player_card == "Citizen": + return "Computer" + elif computer_card == "Citizen" and player_card == "Slave": + return "Computer" + elif computer_card == "Slave" and player_card == "Emperor": + return "Computer" + else: + return "Draw" + +def display_menu(cursor_index): + options = ["게임 계속하기", "타이틀 화면으로 돌아가기", "게임 종료하기"] + for i, option in enumerate(options): + if i == cursor_index: + print(f"{RED}> {option} <{RESET}") + else: + print(f" {option}") + +def menu(): + cursor_index = 0 + while True: + clear_screen() + print(f"{YELLOW}메뉴{RESET}") + display_menu(cursor_index) + key = get_key() + if key == 'j' and cursor_index < 2: + cursor_index += 1 + elif key == 'k' and cursor_index > 0: + cursor_index -= 1 + elif key == '\n': + return cursor_index + +def play_round(game_state): + player_deck = create_deck(game_state["player_role"]) + computer_deck = create_deck(game_state["computer_role"]) + cursor_index = 0 + + while player_deck and computer_deck: + clear_screen() + print(f"{GREEN}플레이어 소지금: {game_state['player_money']} Ferica{RESET}") + print(f"{RED}컴퓨터 소지금: {game_state['computer_money']} Ferica{RESET}") + print(f"라운드: {game_state['round']}") + print(f"플레이어 역할: {game_state['player_role']}") + print(f"컴퓨터 역할: {game_state['computer_role']}") + print(f"{YELLOW}당신의 카드:{RESET}") + display_cards(player_deck, cursor_index) + + key = get_key() + if key == 'j' and cursor_index < len(player_deck) - 1: + cursor_index += 1 + elif key == 'k' and cursor_index > 0: + cursor_index -= 1 + elif key == '\n': + player_card = player_deck.pop(cursor_index) + computer_card = random.choice(computer_deck) + computer_deck.remove(computer_card) + + print(f"당신이 낸 카드: {CARD_ART[player_card]}") + print(f"컴퓨터가 낸 카드: {CARD_ART[computer_card]}") + + result = compare_cards(player_card, computer_card) + if result == "Player": + print(f"{GREEN}당신이 이번 라운드에서 이겼습니다!{RESET}") + game_state["player_money"] += game_state["bet"] + game_state["computer_money"] -= game_state["bet"] + elif result == "Computer": + print(f"{RED}컴퓨터가 이번 라운드에서 이겼습니다!{RESET}") + game_state["player_money"] -= game_state["bet"] + game_state["computer_money"] += game_state["bet"] + else: + print(f"{YELLOW}무승부입니다!{RESET}") + + input("계속하려면 엔터를 누르세요...") + if result != "Draw": + return result + elif key == 'm': + menu_choice = menu() + if menu_choice == 1: + return "Title" + elif menu_choice == 2: + sys.exit() + + return "Draw" + +def main(): + while True: + title_screen() + game_state = initialize_game() + + while game_state["round"] <= 10: + clear_screen() + print(f"{MAGENTA}라운드 {game_state['round']}{RESET}") + try: + game_state["bet"] = int(input("배팅 금액을 입력하세요: ")) + if game_state["bet"] <= 0 or game_state["bet"] > min(game_state["player_money"], game_state["computer_money"]): + raise ValueError + except ValueError: + print("잘못된 배팅입니다. 유효한 금액을 입력해주세요.") + input("다시 시도하려면 엔터를 누르세요...") + continue + + result = play_round(game_state) + if result == "Title": + break + game_state["set_results"].append(result) + + if game_state["player_money"] <= 0: + print(f"{RED}당신의 소지금이 모두 소진되었습니다. 게임 오버!{RESET}") + break + elif game_state["computer_money"] <= 0: + print(f"{GREEN}컴퓨터의 소지금이 모두 소진되었습니다. 당신이 승리했습니다!{RESET}") + break + + game_state["round"] += 1 + game_state["player_role"], game_state["computer_role"] = game_state["computer_role"], game_state["player_role"] + + if result != "Title": + if game_state["round"] > 10: + if game_state["player_money"] > game_state["computer_money"]: + print(f"{GREEN}당신이 게임에서 승리했습니다!{RESET}") + elif game_state["player_money"] < game_state["computer_money"]: + print(f"{RED}컴퓨터가 게임에서 승리했습니다!{RESET}") + else: + print(f"{YELLOW}게임이 무승부로 끝났습니다!{RESET}") + + print("\n세트 결과:") + for i, result in enumerate(game_state["set_results"], 1): + print(f"세트 {i}: {result}") + + input("타이틀 화면으로 돌아가려면 엔터를 누르세요...") + +if __name__ == "__main__": + main() diff --git a/just_code/lotto_sim.py b/just_code/lotto_sim.py new file mode 100644 index 0000000..9d3351d --- /dev/null +++ b/just_code/lotto_sim.py @@ -0,0 +1,102 @@ +import sys +import os +import random +import time +from datetime import datetime + +def clear_screen(): + print("\033[H\033[J", end="") + +def update_display(seed, num_tickets, num_simulations, current_sim, rank_list, combination_result): + clear_screen() + print(f"입력 시드: {seed}") + print(f"구매 티켓 수: {num_tickets}") + print(f"시뮬레이션 횟수: {num_simulations}") + print(f"시뮬레이션 진행 중 {current_sim}/{num_simulations}...") + print(f"현재 생성된 조합목록: {combination_result}") + print("\n" + "-" * 30) + print(f"1등: {rank_list[0]:5d} | 2등: {rank_list[1]:5d}") + print(f"3등: {rank_list[2]:5d} | 4등: {rank_list[3]:5d}") + print(f"낙첨: {rank_list[4]:5d}") + print(f"시도횟수: {sum(rank_list):5d}") + print("-" * 30) + +def generate_lotto_numbers(seed): + random.seed(seed) + return sorted(random.sample(range(1, 46), 6)) + +def compare_numbers(winning_numbers, my_numbers): + matches = len(set(winning_numbers) & set(my_numbers)) + if matches == 6: + return 0 + elif matches == 5: + return 1 + elif matches == 4: + return 2 + elif matches == 3: + return 3 + else: + return 4 + +def generate_complex_seed(seed): + current_time = int(time.time() * 1000000) + mixed_bits = ((current_time & 0xff000000) >> 24) + \ + ((current_time & 0x00ff0000) >> 8) + \ + ((current_time & 0x0000ff00) << 8) + \ + ((current_time & 0x000000ff) << 24) + extra_random = random.randint(0, seed) + final_seed = mixed_bits ^ extra_random + return final_seed + +def main(seed, num_tickets, num_simulations): + rank_result = [] + combination_result = [] + for i in range(num_simulations): + flag = True + itr = 0 + rank_list = [0,0,0,0,0] + while flag : + seed = generate_complex_seed(seed) + goal = generate_lotto_numbers(seed) + + for j in range(num_tickets): + seed = generate_complex_seed(seed) + combination = generate_lotto_numbers(seed) + rank = compare_numbers(goal, combination) + rank_list[rank] += 1 + itr += 1 + + if rank == 0 : + flag = False + + if itr % 191 == 0: + update_display(seed, num_tickets, num_simulations, i+1, rank_list, combination_result) + + rank_result.append(rank_list) + combination_result.append(goal) + + now = datetime.now() + filename = now.strftime('result_%y%m%d_%H%M%S.txt') + + with open(filename, 'w') as f: + for i, (rank, combination) in enumerate(zip(rank_result, combination_result), 1): + total_attempts = sum(rank) + f.write(f"{i}회째 결과 총 {total_attempts}번 시도\n") + f.write(f"1등 : {rank[0]} 2등 : {rank[1]} 3등 : {rank[2]} 4등 : {rank[3]} 낙첨 : {rank[4]}\n\n") + + f.write("최종 조합\n") + for combination in combination_result: + f.write(' '.join(map(str, combination)) + '\n') + + print(f"결과가 '{filename}' 파일에 저장되었습니다.") + +if __name__ == "__main__": + if len(sys.argv) != 4: + print("사용법: python script.py <시드> <구매_티켓_수> <시뮬레이션_횟수>") + sys.exit(1) + + seed = int(sys.argv[1]) + num_tickets = int(sys.argv[2]) + num_simulations = int(sys.argv[3]) + + main(seed, num_tickets, num_simulations) \ No newline at end of file diff --git a/just_code/result_250508_210108.txt b/just_code/result_250508_210108.txt new file mode 100644 index 0000000..3e2c919 --- /dev/null +++ b/just_code/result_250508_210108.txt @@ -0,0 +1,21 @@ +1회째 결과 총 7570590번 시도 +1등 : 1 2등 : 204 3등 : 10408 4등 : 170001 낙첨 : 7389976 + +2회째 결과 총 15633747번 시도 +1등 : 1 2등 : 448 3등 : 21421 4등 : 350808 낙첨 : 15261069 + +3회째 결과 총 3666828번 시도 +1등 : 1 2등 : 111 3등 : 4943 4등 : 81878 낙첨 : 3579895 + +4회째 결과 총 1821108번 시도 +1등 : 1 2등 : 47 3등 : 2513 4등 : 40644 낙첨 : 1777903 + +5회째 결과 총 21822072번 시도 +1등 : 1 2등 : 643 3등 : 29741 4등 : 489842 낙첨 : 21301845 + +최종 조합 +7 16 29 31 36 41 +1 4 5 11 39 41 +3 14 16 18 25 27 +6 16 27 34 35 37 +6 10 23 26 33 38