fixed wrong order of commands and missing command list for board elements

master
Simon Pirkelmann 2020-09-25 16:29:15 +02:00
parent 845c6b1cf1
commit 61605cb2ab
2 changed files with 17 additions and 13 deletions

20
app.py
View File

@ -22,6 +22,9 @@ class Game:
self.comm_socket = socket.socket() # socket for communicating with the program controlling the robots
try:
self.comm_socket.connect(('192.168.1.222', 1337))
pass
print("connected!")
except socket.error:
print("could not connect to robot control socket!")
@ -50,17 +53,18 @@ class Game:
# process the chosen commands and generate a list of robot commands to send to the controller program
cmd_list = self.board.apply_actions(chosen_cards)
if False:
if True:
# send movements to the controller program
for c in cmd_list:
self.comm_socket.sendall(c.encode())
data = self.comm_socket.recv(32)
if not 'nop' in c:
self.comm_socket.sendall((c + "\n").encode())
data = self.comm_socket.recv(32)
if data != b'OK\n':
print("an error occurred while processing the commands")
self.processing_done = True
self.action_stack = {}
return
if data != b'OK\n':
print("an error occurred while processing the commands")
self.processing_done = True
self.action_stack = {}
return
# for c in current_actions:
# if c[0] == 0:
# print("{}, {}\n".format(c[1].action, 11))

View File

@ -146,7 +146,7 @@ class Robot:
# change the orientation of the robot
self.orientation = Robot.resulting_orientation[self.orientation][type]
return "{}, {}".format(self.marker_id, type)
return "{}, {}".format(type, self.marker_id)
def move(self, type):
# move the robot forward or backward
@ -165,7 +165,7 @@ class Robot:
self.y = target_tile.y
# return the move for sending to the controller
return "{}, forward".format(self.marker_id)
return "forward, {}".format(self.marker_id)
elif type == 'backward':
opposite_orientation = self.get_opposite_orientation()
target_tile = self.get_adjecent_tile(opposite_orientation)
@ -180,14 +180,14 @@ class Robot:
self.y = target_tile.y
# return the move for sending to the controller
return "{}, backward".format(self.marker_id)
return "backward, {}".format(self.marker_id)
else:
print("error: invalid move")
sys.exit(1)
def nop(self):
# do nothing command
return "{}, nop".format(self.marker_id)
return "nop, {}".format(self.marker_id)
def board_element_processable(self):
# check if we can directly process the board element for the tile the current robot is located on
@ -474,7 +474,7 @@ class Board:
print(self)
# apply the actions caused by board elements at the end of the phase
self.apply_board_element_actions()
cmd_list += self.apply_board_element_actions()
print(self)