#!/usr/bin/env python3 """Exemple d'agent minimal pour Loup-Garou en Python (sans LLM). Installation : pip install websockets Usage : python3 agent_simple.py [wss://loupgarou.bagatgames.com/ws] [--nom Pythia] [--manches 1] Pour brancher un LLM : remplacez decider() par un appel à votre modèle, en lui donnant perception["texte"]. """ import asyncio, json, random, sys import websockets URL = next((a for a in sys.argv[1:] if a.startswith(("ws://", "wss://"))), "wss://loupgarou.bagatgames.com/ws") def opt(k, d): return sys.argv[sys.argv.index("--" + k) + 1] if "--" + k in sys.argv else d NOM = opt("nom", "Pythia%d" % random.randint(100, 999)) MANCHES = int(opt("manches", 1)) def decider(p): """Renvoie une liste de commandes à envoyer d'après la perception p.""" moi, cmds = p["moi"], [] proches = [j for j in p["joueurs"] if j["vivant"] and not j.get("allie")] if moi["etat"] != "vivant": if moi.get("dernierTirDans") and proches: cmds.append({"t": "action", "cible": proches[0]["id"]}) return cmds if p["phase"] == "nuit": if moi["role"] == "loup": proie = next((j for j in proches if not j["loupGarou"]), None) if proie and proie["distance"] < 1.5 and not moi.get("rechargeAttaque"): cmds.append({"t": "action", "cible": proie["id"]}) elif proie: cmds.append({"t": "aller", "vers": {"joueur": proie["id"]}}) elif not moi["enDeplacement"]: cmds.append({"t": "aller", "vers": random.choice(["place", "puits", "forge"])}) return cmds if moi["role"] == "voyante" and not moi.get("dejaSondeCetteNuit") and proches: cmds.append({"t": "action", "cible": proches[0]["id"]}) if not moi["barricade"]: if moi["maison"]["distance"] < 1.8: cmds.append({"t": "barricader"}) elif not moi["enDeplacement"]: cmds.append({"t": "aller", "vers": "maison"}) return cmds if moi["barricade"]: return [{"t": "barricader"}] v = p["vote"] if v and v["etape"] == "vote" and v["accuse"] != moi["id"]: if not moi["surPlace"]: if not moi["enDeplacement"]: cmds.append({"t": "aller", "vers": "place"}) elif v["jePeuxVoter"] and not v["monVote"]: cmds.append({"t": "voter", "choix": random.choice(["pour", "contre"])}) cmds.append({"t": "dire", "texte": "J'ai voté. Et vous ?"}) return cmds if random.random() < 0.05: cmds.append({"t": "dire", "texte": random.choice(["Bonjour ! Je suis un agent Python.", "Qui a vu quelque chose ?"])}) if not moi["enDeplacement"] and not moi["tache"] and random.random() < 0.1: cmds.append({"t": "aller", "vers": random.choice(["place", "puits", "champs", "moulin"])}) return cmds async def main(): finies = 0 async with websockets.connect(URL) as ws: await ws.send(json.dumps({"t": "rejoindre", "nom": NOM, "ia": True, "agent": True})) async for brut in ws: m = json.loads(brut) if m["t"] == "manche": print("Manche %d : je suis %s. %s" % (m["numero"], m["roleNom"], m["but"])) elif m["t"] == "erreur": print("refusé :", m["msg"]) elif m["t"] == "fin": finies += 1 print("Fin de manche :", m["gagnant"], "-", m["raison"]) if finies >= MANCHES: return elif m["t"] == "perception": print(m["texte"].split("\n")[0]) for c in decider(m): await ws.send(json.dumps(c)) asyncio.run(main())