ゲームを作りました
「とりあえずプロトタイプ版(初期の文字だけのバージョンなど)のコードはここに置いておきます。コピペすれば誰でもすぐ遊べます!」
コンセント
「AIと作った、人間を狂わせる紙幣デスゲーム」
import random
import os
import time
class Player:
def __init__(self, name, man_pre, go_pre, sen_pre, is_com=False):
self.name = name
self.is_com = is_com
# 紙幣の枚数
self.wallet = {
10000: man_pre,
5000: go_pre,
1000: sen_pre
}
self.max_satiety = 5 # 初期最大満腹度(最大10まで上昇)
self.satiety = 5 # 初期満腹度
self.is_alive = True
def get_total_money(self):
return sum(k * v for k, v in self.wallet.items())
def show_private_status(self):
print(f"\n--- 【{self.name}の財布(秘密)】 ---")
print(f"満腹度: {'★' * self.satiety}{'☆' * (self.max_satiety - self.satiety)} ({self.satiety}/{self.max_satiety})")
print(f"10,000円札: {self.wallet[10000]}枚")
print(f" 5,000円札: {self.wallet[5000]}枚")
print(f" 1,000円札: {self.wallet[1000]}枚")
print(f"総資産: {self.get_total_money():,}円")
def show_public_status(self):
total_sheets = sum(self.wallet.values())
print(f"【{self.name}】 満腹度: {self.satiety}/{self.max_satiety} | 所持紙幣の総枚数: {total_sheets}枚")
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def setup_player():
print(f"\nあなたの元手50万円の内訳を設定してください(計500,000円ちょうどにすること)")
while True:
try:
man = int(input("10,000円札の枚数: ") or 0)
go = int(input(" 5,000円札の枚数: ") or 0)
sen = int(input(" 1,000円札の枚数: ") or 0)
total = (man * 10000) + (go * 5000) + (sen * 1000)
if total == 500000:
return Player("YOU(あなた)", man, go, sen, is_com=False)
else:
print(f"合計金額が {total:,}円 です。500,000円ちょうどにしてください。")
except ValueError:
print("有効な数値を入力してください。")
def setup_com():
archetypes = [
(45, 8, 10), # 1万円札特化型(新ルールで大器晩成型に進化)
(25, 30, 100), # バランス型
(5, 60, 150) # 低額紙幣特化型
]
man, go, sen = random.choice(archetypes)
return Player("COM(人工知能)", man, go, sen, is_com=True)
def process_attack(player):
# 【新ルール】満腹度が高いほど襲撃率が下がる(最大50%軽減)
stealth_modifier = 1.0 - (player.satiety / player.max_satiety) * 0.5
go_attack_pct = int(min(player.wallet[5000] * 2, 80) * stealth_modifier)
sen_attack_pct = int(min(player.wallet[1000] * 1, 80) * stealth_modifier)
attacked = False
if player.wallet[5000] > 0 and random.randint(1, 100) <= go_attack_pct:
lost = min(random.randint(1, 3), player.wallet[5000])
player.wallet[5000] -= lost
print(f"【⚠️怪物襲撃】5,000円ハンターに襲われ、5,000円札を {lost} 枚強奪された!(襲撃率: {go_attack_pct}%)")
attacked = True
if player.wallet[1000] > 0 and random.randint(1, 100) <= sen_attack_pct:
lost = min(random.randint(2, 6), player.wallet[1000])
player.wallet[1000] -= lost
print(f"【⚠️怪物襲撃】1,000円ハンターに襲われ、1,000円札を {lost} 枚強奪された!(襲撃率: {sen_attack_pct}%)")
attacked = True
if not attacked:
print(f"怪物の気配はあったが、高い満腹度による俊敏さ(襲撃率軽減)で逃げ切った!")
def process_sabotage(attacker, defender, amount):
temp_amount = amount
for denom in [10000, 5000, 1000]:
while temp_amount >= denom and attacker.wallet[denom] > 0:
attacker.wallet[denom] -= 1
temp_amount -= denom
if temp_amount > 0:
return False
temp_amount = amount
for denom in [10000, 5000, 1000]:
while temp_amount >= denom and defender.wallet[denom] > 0:
defender.wallet[denom] -= 1
temp_amount -= denom
print(f"💣 自爆スイッチ発動!{attacker.name}は {amount:,}円を犠牲に、{defender.name}の資産を同額分吹き飛ばした!")
return True
def get_com_choice(com, human, was_previous_pass):
# COMの思考ロジック(新ルール対応)
# 連続パスペナルティの回避策
if was_previous_pass and random.random() < 0.7:
if com.wallet[1000] > 0 or com.wallet[5000] > 0:
return "1", 0
elif com.wallet[10000] > 0:
return "2", 0
# 1万円の最大満腹度バフを狙う(胃袋が最大でなく、1万円札があるなら積極的に購入)
if com.max_satiety < 10 and com.wallet[10000] > 0 and com.satiety <= com.max_satiety - 3:
return "2", 0
# 餓死回避
if com.satiety <= 2:
if com.wallet[1000] > 0 or com.wallet[5000] > 0:
return "1", 0
elif com.wallet[10000] > 0:
return "2", 0
# 自爆のトドメ
human_sheets = sum(human.wallet.values())
if com.satiety > 2 and com.get_total_money() >= 50000 and (human_sheets > 30 or human.satiety <= 2):
sabotage_amount = random.choice([10000, 20000, 30000])
if sabotage_amount <= com.get_total_money():
return "3", sabotage_amount
return "4", 0
def apply_pass_penalty(player):
# 【新ルール】ランダムで所持紙幣が1枚消滅するペナルティ
available_denoms = [d for d, count in player.wallet.items() if count > 0]
if available_denoms:
chosen_denom = random.choice(available_denoms)
player.wallet[chosen_denom] -= 1
print(f"💀【連続パスペナルティ】お互いに様子を見すぎた!怪物の呪いにより、{player.name}の財布から {chosen_denom:,}円札 が1枚消滅した!")
else:
print(f"💀【連続パスペナルティ】{player.name}はすでに一銭も持っていなかった!")
def main_game():
clear_screen()
print("==================================================")
print(" 対COM戦:紙幣サバイバル人狼ゲーム 【Ver 2.0】 ")
print("==================================================")
p1 = setup_player()
p2 = setup_com()
day = 1
was_previous_pass = False # 前のターンでパスが発生したかのフラグ
while p1.is_alive and p2.is_alive:
players = [p1, p2] if day % 2 != 0 else [p2, p1]
for current_p in players:
target_p = p2 if current_p == p1 else p1
clear_screen()
print(f"=== 【DAY {day}】 {current_p.name} の行動ターン ===")
p1.show_public_status()
p2.show_public_status()
if was_previous_pass:
print("⚠️ 警告: 前のプレイヤーが【パス】しています。連続パスはペナルティ対象です!")
if not current_p.is_com:
current_p.show_private_status()
print("\n【コマンドを選択してください】")
print("1: 200円おにぎりを買う (1,000円/5,000円札が必要 / 満腹度+5 / 通常米)")
print("2: 2,000円高級おにぎりを買う (10,000円札が必要 / ★永続:最大満腹度+1 & 満腹度+5)")
print("3: 同額自爆スイッチを押す (自分の金を燃やして相手の同額を偽札化)")
print("4: 何もしない(パス)")
choice = input("選択 (1-4): ")
sabotage_amount = 0
else:
print("\nCOMが思考中...")
time.sleep(1.5)
choice, sabotage_amount = get_com_choice(current_p, target_p, was_previous_pass)
# 行動の処理
action_is_pass = False
if choice == "1":
if current_p.wallet[1000] > 0:
current_p.wallet[1000] -= 1
current_p.satiety = min(current_p.max_satiety, current_p.satiety + 5)
print(f"🛒 {current_p.name}は1,000円でおにぎり5個を購入。お腹が満たされた!")
elif current_p.wallet[5000] > 0:
current_p.wallet[5000] -= 1
current_p.wallet[1000] += 4
current_p.satiety = min(current_p.max_satiety, current_p.satiety + 5)
print(f"🛒 {current_p.name}は5,000円でおにぎり5個を購入。お釣り(千円札4枚)の匂いで怪物が興奮している!")
else:
print(f"❌ {current_p.name}は通常おにぎり用の札がありません!強制的にパスになります。")
action_is_pass = True
elif choice == "2":
if current_p.wallet[10000] > 0:
current_p.wallet[10000] -= 1
# 【新ルール】最大満腹度の永続バフ(最大10)
if current_p.max_satiety < 10:
current_p.max_satiety += 1
print(f"📈 【高級米の効果】{current_p.name}の胃袋が拡張され、最大満腹度が {current_p.max_satiety} に上昇した!")
current_p.satiety = min(current_p.max_satiety, current_p.satiety + 5)
print(f"🛒 {current_p.name}は10,000円で高級おにぎり5個を堪能した!(現在の満腹度: {current_p.satiety}/{current_p.max_satiety})")
else:
print(f"❌ {current_p.name}は10,000円札がありません!強制的にパスになります。")
action_is_pass = True
elif choice == "3":
if not current_p.is_com:
try:
sabotage_amount = int(input("いくら分自爆しますか? (1,000円単位): "))
except ValueError:
sabotage_amount = 0
if 0 < sabotage_amount <= current_p.get_total_money():
process_sabotage(current_p, target_p, sabotage_amount)
else:
print("❌ 無効な金額、または資金不足。自爆失敗。強制的にパスになります。")
action_is_pass = True
else:
print(f"💤 {current_p.name}はパスした。じっと息を潜めている。")
action_is_pass = True
# 【新ルール】連続パスペナルティの判定
if action_is_pass:
if was_previous_pass:
apply_pass_penalty(current_p)
was_previous_pass = True
else:
was_previous_pass = False
# 怪物の襲撃フェーズ
print(f"\n--- {current_p.name} の帰路 ---")
process_attack(current_p)
# 満腹度の減少
current_p.satiety -= 1
if current_p.satiety <= 0:
current_p.is_alive = False
print(f"\n💀💀💀 {current_p.name} は飢えに耐えかねて白旗をあげた(リタイア) 💀💀💀")
break
input("\nEnterを押して次のターンへ...")
day += 1
# 勝敗判定
print("\n==================================================")
print(" GAME OVER ")
print("==================================================")
if not p1.is_alive and not p2.is_alive:
print("両者同時に力尽きました。引き分けです。")
elif p1.is_alive:
print(f"🎉 勝者: {p1.name}! COMを干からびさせ、賞金100万円を獲得!")
else:
print(f"💀 勝者: {p2.name}。 あなたは1万分の1の遅い空間に呑まれました。")
if __name__ == "__main__":
main_game()