Skip to content

Commit f32bec6

Browse files
committed
working on python client
1 parent 0ce9e48 commit f32bec6

File tree

5 files changed

+177
-45
lines changed

5 files changed

+177
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

bot.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
import json
5+
import socket
6+
from enum import Enum
7+
8+
class State(Enum):
9+
SELECTING_HAND = 1
10+
HAND_PLAYED = 2
11+
DRAW_TO_HAND = 3
12+
GAME_OVER = 4
13+
SHOP = 5
14+
PLAY_TAROT = 6
15+
BLIND_SELECT = 7
16+
ROUND_EVAL = 8
17+
TAROT_PACK = 9
18+
PLANET_PACK = 10
19+
MENU = 11
20+
TUTORIAL = 12
21+
SPLASH = 13
22+
SANDBOX = 14
23+
SPECTRAL_PACK = 15
24+
DEMO_CTA = 16
25+
STANDARD_PACK = 17
26+
BUFFOON_PACK = 18
27+
NEW_ROUND = 19
28+
29+
class Actions(Enum):
30+
SELECT_BLIND = 1
31+
SKIP_BLIND = 2
32+
PLAY_HAND = 3
33+
DISCARD_HAND = 4
34+
END_SHOP = 5
35+
REROLL_SHOP = 6
36+
BUY_CARD = 7
37+
BUY_VOUCHER = 8
38+
BUY_BOOSTER = 9
39+
SELECT_BOOSTER_CARD = 10
40+
SKIP_BOOSTER_PACK = 11
41+
SELL_JOKER = 12
42+
USE_CONSUMABLE = 13
43+
SELL_CONSUMABLE = 14
44+
REARRANGE_JOKERS = 15
45+
REARRANGE_CONSUMABLES = 16
46+
REARRANGE_HAND = 17
47+
PASS = 18
48+
START_RUN = 19
49+
SEND_GAMESTATE = 20
50+
51+
class Bot:
52+
53+
def __init__(self, deck: str, stake: int = 1, seed: str = None, challenge: str = None):
54+
self.deck = deck
55+
self.stake = stake
56+
self.seed = seed
57+
self.challenge = challenge
58+
59+
self.addr = ("127.0.0.1", 12345)
60+
self.running = False
61+
62+
def skip_or_select_blind(self):
63+
raise NotImplementedError("Error: Bot.skip_or_select_blind must be implemented.")
64+
65+
def play_or_discard_hand(self):
66+
raise NotImplementedError("Error: Bot.play_or_discard_hand must be implemented.")
67+
68+
def select_shop_action(self):
69+
raise NotImplementedError("Error: Bot.select_shop_action must be implemented.")
70+
71+
def select_booster_action(self):
72+
raise NotImplementedError("Error: Bot.select_booster_action must be implemented.")
73+
74+
def rearrange_jokers(self):
75+
raise NotImplementedError("Error: Bot.rearrange_jokers must be implemented.")
76+
77+
def use_or_sell_consumables(self):
78+
raise NotImplementedError("Error: Bot.use_or_sell_consumables must be implemented.")
79+
80+
def rearrange_consumables(self):
81+
raise NotImplementedError("Error: Bot.rearrange_consumables must be implemented.")
82+
83+
def rearrange_hand(self):
84+
raise NotImplementedError("Error: Bot.rearrange_hand must be implemented.")
85+
86+
def sendcmd(self, cmd, **kwargs):
87+
msg = bytes(cmd.name, 'utf-8')
88+
self.sock.sendto(msg, self.addr)
89+
90+
def verifyimplemented(self):
91+
try:
92+
self.skip_or_select_blind()
93+
self.play_or_discard_hand()
94+
self.select_shop_action()
95+
self.select_booster_action()
96+
self.rearrange_jokers()
97+
self.use_or_sell_consumables()
98+
self.rearrange_consumables()
99+
self.rearrange_hand()
100+
except NotImplementedError as e:
101+
print(e)
102+
sys.exit(0)
103+
except:
104+
pass
105+
106+
def run(self):
107+
self.verifyimplemented()
108+
109+
running = True
110+
111+
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
112+
self.sock.settimeout(1.0)
113+
114+
self.sendcmd(Actions.SEND_GAMESTATE)
115+
116+
while running:
117+
try:
118+
data = self.sock.recv(4096)
119+
G = json.loads(data)
120+
self.G = G
121+
122+
if State(G.state) == State.GAME_OVER:
123+
running = False
124+
125+
except:
126+
print('Request Timed Out')
127+
128+
running = False

bot_example.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from bot import Bot
2+
3+
if __name__=='__main__':
4+
mybot = Bot(deck ="Plasma Deck",
5+
stake = 1,
6+
seed = "1OGB5WO")
7+
8+
def skip_or_select_blind(self):
9+
pass
10+
11+
def play_or_discard_hand(self):
12+
pass
13+
14+
def select_shop_action(self):
15+
pass
16+
17+
def select_booster_action(self):
18+
pass
19+
20+
def rearrange_jokers(self):
21+
pass
22+
23+
def use_or_sell_consumables(self):
24+
pass
25+
26+
def rearrange_consumables(self):
27+
pass
28+
29+
def rearrange_hand(self):
30+
pass
31+
32+
mybot.skip_or_select_blind = skip_or_select_blind
33+
mybot.play_or_discard_hand = play_or_discard_hand
34+
mybot.select_shop_action = select_shop_action
35+
mybot.select_booster_action = select_booster_action
36+
mybot.rearrange_jokers = rearrange_jokers
37+
mybot.use_or_sell_consumables = use_or_sell_consumables
38+
mybot.rearrange_consumables = rearrange_consumables
39+
mybot.rearrange_hand = rearrange_hand
40+
41+
mybot.run()

client.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/utils.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,19 @@ end
117117
function Utils.getGameData()
118118
local _game = { }
119119

120+
if G and G.STATE then
121+
_game.state = G.STATE
122+
end
123+
120124
return _game
121125
end
122126

123127
function Utils.getGamestate()
124128
-- TODO
125129
local _gamestate = { }
126-
_gamestate.game = Utils.getGameData()
130+
131+
_gamestate = Utils.getGameData()
132+
127133
_gamestate.deckback = Utils.getBackData()
128134
_gamestate.deck = Utils.getDeckData() -- Ensure this is not ordered
129135
_gamestate.hand = Utils.getHandData()

0 commit comments

Comments
 (0)