11#!/usr/bin/python3
22
3- import sys
43import json
4+ import random
55import socket
6+ import subprocess
7+ import sys
68import time
79from enum import Enum
10+ from weakref import proxy
11+
812from gamestates import cache_state
9- import subprocess
10- import random
1113
1214
1315class State (Enum ):
@@ -72,7 +74,7 @@ def __init__(
7274
7375 self .bot_port = bot_port
7476
75- self .addr = ("localhost " , self .bot_port )
77+ self .addr = ("127.0.0.1 " , self .bot_port )
7678 self .running = False
7779 self .balatro_instance = None
7880
@@ -131,7 +133,7 @@ def stop_balatro_instance(self):
131133
132134 def sendcmd (self , cmd , ** kwargs ):
133135 msg = bytes (cmd , "utf-8" )
134- self .sock .sendto (msg , self . addr )
136+ self .sock .send (msg )
135137
136138 def actionToCmd (self , action ):
137139 result = []
@@ -148,15 +150,15 @@ def actionToCmd(self, action):
148150
149151 def verifyimplemented (self ):
150152 try :
151- self .skip_or_select_blind (self , {})
152- self .select_cards_from_hand (self , {})
153- self .select_shop_action (self , {})
154- self .select_booster_action (self , {})
155- self .sell_jokers (self , {})
156- self .rearrange_jokers (self , {})
157- self .use_or_sell_consumables (self , {})
158- self .rearrange_consumables (self , {})
159- self .rearrange_hand (self , {})
153+ self .skip_or_select_blind ({})
154+ self .select_cards_from_hand ({})
155+ self .select_shop_action ({})
156+ self .select_booster_action ({})
157+ self .sell_jokers ({})
158+ self .rearrange_jokers ({})
159+ self .use_or_sell_consumables ({})
160+ self .rearrange_consumables ({})
161+ self .rearrange_hand ({})
160162 except NotImplementedError as e :
161163 print (e )
162164 sys .exit (0 )
@@ -168,11 +170,13 @@ def random_seed(self):
168170 return "" .join (random .choices ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" , k = 7 ))
169171
170172 def chooseaction (self ):
173+ print ("Choosing action based on game state:" , self .G ["state" ])
171174 if self .G ["state" ] == State .GAME_OVER :
172175 self .running = False
173176
174177 match self .G ["waitingFor" ]:
175178 case "start_run" :
179+ print ("Starting run with deck:" , self .deck )
176180 seed = self .seed
177181 if seed is None :
178182 seed = self .random_seed ()
@@ -184,23 +188,32 @@ def chooseaction(self):
184188 self .challenge ,
185189 ]
186190 case "skip_or_select_blind" :
187- return self .skip_or_select_blind (self , self .G )
191+ print ("Choosing action: skip_or_select_blind" )
192+ return self .skip_or_select_blind (self .G )
188193 case "select_cards_from_hand" :
189- return self .select_cards_from_hand (self , self .G )
194+ print ("Choosing action: select_cards_from_hand" )
195+ return self .select_cards_from_hand (self .G )
190196 case "select_shop_action" :
191- return self .select_shop_action (self , self .G )
197+ print ("Choosing action: select_shop_action" )
198+ return self .select_shop_action (self .G )
192199 case "select_booster_action" :
193- return self .select_booster_action (self , self .G )
200+ print ("Choosing action: select_booster_action" )
201+ return self .select_booster_action (self .G )
194202 case "sell_jokers" :
195- return self .sell_jokers (self , self .G )
203+ print ("Choosing action: sell_jokers" )
204+ return self .sell_jokers (self .G )
196205 case "rearrange_jokers" :
197- return self .rearrange_jokers (self , self .G )
206+ print ("Choosing action: rearrange_jokers" )
207+ return self .rearrange_jokers (self .G )
198208 case "use_or_sell_consumables" :
199- return self .use_or_sell_consumables (self , self .G )
209+ print ("Choosing action: use_or_sell_consumables" )
210+ return self .use_or_sell_consumables (self .G )
200211 case "rearrange_consumables" :
201- return self .rearrange_consumables (self , self .G )
212+ print ("Choosing action: rearrange_consumables" )
213+ return self .rearrange_consumables (self .G )
202214 case "rearrange_hand" :
203- return self .rearrange_hand (self , self .G )
215+ print ("Choosing action: rearrange_hand" )
216+ return self .rearrange_hand (self .G )
204217
205218 def run_step (self ):
206219 if self .sock is None :
0 commit comments