|
2 | 2 |
|
3 | 3 | import logging |
4 | 4 |
|
5 | | -from balatrobot import BalatroClient, BalatroError, State |
| 5 | +from src.balatrobot.client import BalatroClient |
| 6 | +from src.balatrobot.exceptions import BalatroError |
6 | 7 |
|
7 | 8 | logger = logging.getLogger(__name__) |
| 9 | +logging.basicConfig(level=logging.INFO) |
8 | 10 |
|
9 | 11 |
|
10 | 12 | def main(): |
11 | 13 | """Example of using the new BalatroBot API.""" |
12 | | - logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s") |
13 | 14 | logger.info("BalatroBot API Example") |
14 | | - logger.info("=" * 50) |
15 | 15 |
|
16 | | - # Create client and connect |
17 | 16 | with BalatroClient() as client: |
18 | 17 | try: |
19 | | - # Get initial game state |
20 | | - logger.info("Getting initial game state...") |
21 | | - game_state = client.get_game_state() |
22 | | - logger.info(f"Current state: {game_state.state_enum.name}") |
23 | | - |
24 | | - # Go to menu if not already there |
25 | | - if game_state.state_enum != State.MENU: |
26 | | - logger.info("Going to menu...") |
27 | | - game_state = client.go_to_menu() |
28 | | - logger.info(f"Now in state: {game_state.state_enum.name}") |
29 | | - |
30 | | - # Start a new run |
31 | | - logger.info("Starting new run...") |
32 | | - game_state = client.start_run(deck="Red Deck", stake=1, seed="EXAMPLE") |
33 | | - logger.info(f"Run started, state: {game_state.state_enum.name}") |
34 | | - |
35 | | - # Select the blind |
36 | | - logger.info("Selecting blind...") |
37 | | - game_state = client.skip_or_select_blind("select") |
38 | | - logger.info(f"Blind selected, state: {game_state.state_enum.name}") |
39 | | - logger.info(f"Hand size: {len(game_state.hand)}") |
40 | | - |
41 | | - # Play a hand (first 4 cards) |
42 | | - if len(game_state.hand) >= 4: |
43 | | - logger.info("Playing hand with first 4 cards...") |
44 | | - game_state = client.play_hand_or_discard("play_hand", [0, 1, 2, 3]) |
45 | | - logger.info(f"Hand played, state: {game_state.state_enum.name}") |
46 | | - |
47 | | - # If we won the round, cash out |
48 | | - if game_state.state_enum == State.ROUND_EVAL: |
49 | | - logger.info("Cashing out...") |
50 | | - game_state = client.cash_out() |
51 | | - logger.info(f"Cashed out, state: {game_state.state_enum.name}") |
52 | | - |
53 | | - # Go to next round |
54 | | - logger.info("Going to next round...") |
55 | | - game_state = client.shop("next_round") |
56 | | - logger.info(f"Next round, state: {game_state.state_enum.name}") |
57 | | - |
58 | | - # Go back to menu at the end |
59 | | - logger.info("Going back to menu...") |
60 | | - game_state = client.go_to_menu() |
61 | | - logger.info(f"Back to menu, state: {game_state.state_enum.name}") |
| 18 | + client.send_message("go_to_menu", {}) |
| 19 | + client.send_message( |
| 20 | + "start_run", |
| 21 | + {"deck": "Red Deck", "stake": 1, "seed": "OOOO155"}, |
| 22 | + ) |
| 23 | + client.send_message( |
| 24 | + "skip_or_select_blind", |
| 25 | + {"action": "select"}, |
| 26 | + ) |
| 27 | + client.send_message( |
| 28 | + "play_hand_or_discard", |
| 29 | + {"action": "play_hand", "cards": [0, 1, 2, 3]}, |
| 30 | + ) |
| 31 | + client.send_message("cash_out", {}) |
| 32 | + client.send_message("shop", {"action": "next_round"}) |
| 33 | + client.send_message("go_to_menu", {}) |
| 34 | + logger.info("All actions executed successfully") |
62 | 35 |
|
63 | 36 | except BalatroError as e: |
64 | 37 | logger.error(f"API Error: {e}") |
65 | 38 | logger.error(f"Error code: {e.error_code}") |
66 | | - logger.error(f"Context: {e.context}") |
67 | 39 |
|
68 | 40 | except Exception as e: |
69 | 41 | logger.error(f"Unexpected error: {e}") |
|
0 commit comments