-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
95 lines (92 loc) · 3.79 KB
/
cli.py
File metadata and controls
95 lines (92 loc) · 3.79 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from projectl import ProjectLGame, ActionEnum, Piece, Rotation
from pydantic import ValidationError
game = ProjectLGame(2)
while True:
game.render()
print("------------------")
print("choose an action:")
for action in list(ActionEnum):
print(f"- {action.value}) {action.name}")
action_number = int(input("enter a number: "))
try:
if action_number == ActionEnum.GET_DOT.value:
game.step({"action": ActionEnum.GET_DOT.value, "action_data": {}})
elif action_number == ActionEnum.UPGRADE_PIECE.value:
for piece in list(Piece):
print(f"- {piece.value}) {piece.name}")
from_piece = int(input("from piece: "))
to_piece = int(input("to piece: "))
game.step(
{
"action": ActionEnum.UPGRADE_PIECE.value,
"action_data": {"from_piece": from_piece, "to_piece": to_piece},
}
)
elif action_number == ActionEnum.TAKE_PUZZLE.value:
puzzle_number = int(input("puzzle number: "))
game.step(
{
"action": ActionEnum.TAKE_PUZZLE.value,
"action_data": {"which_puzzle": puzzle_number},
}
)
elif action_number == ActionEnum.PLACE_PIECE.value:
puzzle_number = int(input("puzzle number: "))
for piece in list(Piece):
print(f"- {piece.value}) {piece.name}")
piece_number = int(input("piece number: "))
x_coord = int(input("x position: "))
y_coord = int(input("y position: "))
for rot in list(Rotation):
print(f"- {rot.value}) {rot.name}")
rotation = int(input("rotation: "))
print("- 1) True")
print("- 2) False")
reversed = input("reversed: ") == "1"
game.step(
{
"action": ActionEnum.PLACE_PIECE.value,
"action_data": {
"puzzle": puzzle_number,
"piece": piece_number,
"x_coord": x_coord,
"y_coord": y_coord,
"rotation": rotation,
"reversed": reversed,
},
}
)
elif action_number == ActionEnum.MASTER.value:
actions = []
for puzzle_number in range(len(game.players_puzzles[game.current_player])):
for piece in list(Piece):
print(f"- {piece.value}) {piece.name}")
piece_number = int(input("piece number: "))
x_coord = int(input("x position: "))
y_coord = int(input("y position: "))
for rot in list(Rotation):
print(f"- {rot.value}) {rot.name}")
rotation = int(input("rotation: "))
print("- 1) True")
print("- 2) False")
reversed = input("reversed: ") == "1"
actions.append(
{
"puzzle": puzzle_number,
"piece": piece_number,
"x_coord": x_coord,
"y_coord": y_coord,
"rotation": rotation,
"reversed": reversed,
}
)
game.step(
{
"action": ActionEnum.MASTER.value,
"action_data": {"place_piece_actions": actions},
}
)
elif action_number == ActionEnum.STOP.value:
game.step({"action": ActionEnum.STOP.value, "action_data": {}})
except (ProjectLGame.InvalidAction, ValidationError, ValueError) as e:
print(e)