gametree1.0:fix
This commit is contained in:
73
test/pg.json
73
test/pg.json
@@ -3,7 +3,8 @@
|
||||
"0": "a",
|
||||
"1": "b",
|
||||
"2": "c",
|
||||
"3": "d"
|
||||
"3": "d",
|
||||
"4": "e"
|
||||
},
|
||||
"game_state": {
|
||||
"players_init": [
|
||||
@@ -22,87 +23,41 @@
|
||||
[
|
||||
3,
|
||||
500
|
||||
],
|
||||
[
|
||||
4,
|
||||
500
|
||||
]
|
||||
],
|
||||
"dealer_idx": 0,
|
||||
"small_blind": 5,
|
||||
"big_blind": 10,
|
||||
"current_street": "RIVER",
|
||||
"current_street": "PREFLOP",
|
||||
"all_actions": [
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 3,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 4,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 0,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"type": "ALL_IN",
|
||||
"actor": 1,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "BET",
|
||||
"actor": 1,
|
||||
"amount": 40
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"type": "ALL_IN",
|
||||
"actor": 2,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 3,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 0,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "BET",
|
||||
"actor": 1,
|
||||
"amount": 40
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 2,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 3,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 0,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "BET",
|
||||
"actor": 1,
|
||||
"amount": 40
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 2,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 3,
|
||||
"amount": null
|
||||
},
|
||||
{
|
||||
"type": "CALL",
|
||||
"actor": 0,
|
||||
"amount": null
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
57
test/pg.py
57
test/pg.py
@@ -14,6 +14,11 @@ from gametree.model import act_fold, act_call, act_check, act_bet, act_raise, ac
|
||||
|
||||
GAME_FILE = "pg.json"
|
||||
|
||||
def create_file_idx():
|
||||
files = list(Path("data").glob("pg_*.json"))
|
||||
game_id = len(files) + 1
|
||||
return f"data/pg_{game_id:03d}.json"
|
||||
|
||||
def create_simple_game(player_names: List[str],
|
||||
small_blind: int = 5,
|
||||
big_blind: int = 10,
|
||||
@@ -44,31 +49,6 @@ def save_simple_game(path: str, game: Game, players) -> None:
|
||||
}
|
||||
p.write_text(json.dumps(data, indent=2), encoding="utf-8")
|
||||
|
||||
# 单开不加载
|
||||
# def load_simple_game(path: str) -> Tuple[Game, Dict[int,str]]:
|
||||
# p = Path(path)
|
||||
# data = json.loads(p.read_text(encoding="utf-8"))
|
||||
# player_names = {int(k): v for k, v in data["player_names"].items()}
|
||||
# gs = data["game_state"]
|
||||
# players_init = [(PlayerId(pid), stack) for pid, stack in gs.get("players_init", [])]
|
||||
# game = Game(players_init=players_init,
|
||||
# dealer_idx=gs.get("dealer_idx", 0),
|
||||
# small_blind=gs.get("small_blind", 5),
|
||||
# big_blind=gs.get("big_blind", 10))
|
||||
# for ad in gs.get("all_actions", []):
|
||||
# try:
|
||||
# act = Action(type=ActionType[ad["type"]], actor=PlayerId(ad["actor"]), amount=ad.get("amount"))
|
||||
# game.add_action(act)
|
||||
# except Exception:
|
||||
# continue
|
||||
# target = gs.get("current_street")
|
||||
# if target:
|
||||
# from .model import Street as _Street
|
||||
# target_st = _Street[target]
|
||||
# while game.current_street != target_st and not getattr(game, "terminal", False):
|
||||
# game.advance_to_next_street()
|
||||
# return game, player_names
|
||||
|
||||
def display_game_status(game: Game, player_names: Dict[int,str], show_cards_for: Optional[str] = None) -> None:
|
||||
print(f"Street: {game.current_street.name}")
|
||||
board = game.get_current_board()
|
||||
@@ -184,7 +164,7 @@ def main():
|
||||
return None, None
|
||||
|
||||
def cmd_set(args):
|
||||
global GAME, P_NAME, P_IDS
|
||||
global GAME, P_NAME, P_IDS, GAME_FILE
|
||||
input_line = args.split()
|
||||
if len(input_line) < 3:
|
||||
print("usage: set <small>/<big> [player ...] [--stack N]")
|
||||
@@ -199,7 +179,7 @@ def main():
|
||||
if len(input_line) >= 4 and input_line[-2] == '--stack':
|
||||
stack = int(input_line[-1])
|
||||
names = input_line[1:-2]
|
||||
|
||||
GAME_FILE = create_file_idx()
|
||||
game, pname_map, pids = create_simple_game(names,
|
||||
small_blind=int(blinds[0]),
|
||||
big_blind=int(blinds[1]),
|
||||
@@ -257,14 +237,6 @@ def main():
|
||||
|
||||
|
||||
def cmd_status(args):
|
||||
# 单开
|
||||
# if GAME is None:
|
||||
# if os.path.exists(GAME_FILE):
|
||||
# g, names = load_simple_game(GAME_FILE)
|
||||
# display_game_status(g, names, show_cards_for=args.strip() if args else None)
|
||||
# else:
|
||||
# print("no game")
|
||||
# else:
|
||||
if GAME is None or P_NAME is None:
|
||||
print("no game to display")
|
||||
return
|
||||
@@ -288,24 +260,14 @@ def main():
|
||||
save_simple_game(GAME_FILE, GAME, P_NAME)
|
||||
print(" saved", GAME_FILE)
|
||||
|
||||
# def cmd_load(args):
|
||||
# global GAME, P_NAME, P_IDS
|
||||
# if not os.path.exists(GAME_FILE):
|
||||
# print("no saved game file.")
|
||||
# return
|
||||
# GAME, P_NAME = load_simple_game(GAME_FILE)
|
||||
# P_IDS = [PlayerId(i, name) for i, name in P_NAME.items()]
|
||||
# print(" Loaded", GAME_FILE)
|
||||
# display_game_status(GAME, P_NAME)
|
||||
# display_player_turn()
|
||||
|
||||
def cmd_reset(args):
|
||||
global GAME, P_NAME, P_IDS
|
||||
global GAME, P_NAME, P_IDS, GAME_FILE
|
||||
if os.path.exists(GAME_FILE):
|
||||
os.remove(GAME_FILE)
|
||||
GAME = None
|
||||
P_NAME = None
|
||||
P_IDS = None
|
||||
GAME_FILE = "pg.json"
|
||||
print(" reset game file")
|
||||
|
||||
def cmd_help(args):
|
||||
@@ -314,7 +276,6 @@ def main():
|
||||
print(" act <player> <fold|call|check|bet|raise|all_in> [amount]")
|
||||
print(" status [player|all] ")
|
||||
print(" save ")
|
||||
# print(" load ") 单开不加载
|
||||
print(" reset ")
|
||||
print(" ? ")
|
||||
print(" q|e ")
|
||||
|
||||
Reference in New Issue
Block a user