-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsample_player_client.py
74 lines (63 loc) · 2.2 KB
/
sample_player_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import argparse
from typing import NoReturn
from chronobio.network.client import Client
class PlayerGameClient(Client):
def __init__(
self: "PlayerGameClient", server_addr: str, port: int, username: str
) -> None:
super().__init__(server_addr, port, username, spectator=False)
self._commands: list[str] = []
def run(self: "PlayerGameClient") -> NoReturn:
while True:
game_data = self.read_json()
for farm in game_data["farms"]:
if farm["name"] == self.username:
my_farm = farm
break
else:
raise ValueError(f"My farm is not found ({self.username})")
print(my_farm)
if game_data["day"] == 0:
self.add_command("0 EMPRUNTER 100000")
self.add_command("0 ACHETER_CHAMP")
self.add_command("0 ACHETER_CHAMP")
self.add_command("0 ACHETER_CHAMP")
self.add_command("0 ACHETER_TRACTEUR")
self.add_command("0 ACHETER_TRACTEUR")
self.add_command("0 EMPLOYER")
self.add_command("0 EMPLOYER")
self.add_command("1 SEMER PATATE 3")
self.send_commands()
def add_command(self: "PlayerGameClient", command: str) -> None:
self._commands.append(command)
def send_commands(self: "PlayerGameClient") -> None:
data = {"commands": self._commands}
print("sending", data)
self.send_json(data)
self._commands.clear()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Game client.")
parser.add_argument(
"-a",
"--address",
type=str,
help="name of server on the network",
default="localhost",
)
parser.add_argument(
"-p",
"--port",
type=int,
help="location where server listens",
default=16210,
)
parser.add_argument(
"-u",
"--username",
type=str,
help="name of the user",
default="unknown",
required=True,
)
args = parser.parse_args()
client = PlayerGameClient(args.address, args.port, args.username).run()