fixed wrong order of commands and missing command list for board elements
This commit is contained in:
parent
845c6b1cf1
commit
61605cb2ab
20
app.py
20
app.py
|
@ -22,6 +22,9 @@ class Game:
|
||||||
self.comm_socket = socket.socket() # socket for communicating with the program controlling the robots
|
self.comm_socket = socket.socket() # socket for communicating with the program controlling the robots
|
||||||
try:
|
try:
|
||||||
self.comm_socket.connect(('192.168.1.222', 1337))
|
self.comm_socket.connect(('192.168.1.222', 1337))
|
||||||
|
|
||||||
|
pass
|
||||||
|
print("connected!")
|
||||||
except socket.error:
|
except socket.error:
|
||||||
print("could not connect to robot control socket!")
|
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
|
# 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)
|
cmd_list = self.board.apply_actions(chosen_cards)
|
||||||
|
|
||||||
if False:
|
if True:
|
||||||
# send movements to the controller program
|
# send movements to the controller program
|
||||||
for c in cmd_list:
|
for c in cmd_list:
|
||||||
self.comm_socket.sendall(c.encode())
|
if not 'nop' in c:
|
||||||
data = self.comm_socket.recv(32)
|
self.comm_socket.sendall((c + "\n").encode())
|
||||||
|
data = self.comm_socket.recv(32)
|
||||||
|
|
||||||
if data != b'OK\n':
|
if data != b'OK\n':
|
||||||
print("an error occurred while processing the commands")
|
print("an error occurred while processing the commands")
|
||||||
self.processing_done = True
|
self.processing_done = True
|
||||||
self.action_stack = {}
|
self.action_stack = {}
|
||||||
return
|
return
|
||||||
# for c in current_actions:
|
# for c in current_actions:
|
||||||
# if c[0] == 0:
|
# if c[0] == 0:
|
||||||
# print("{}, {}\n".format(c[1].action, 11))
|
# print("{}, {}\n".format(c[1].action, 11))
|
||||||
|
|
10
roborally.py
10
roborally.py
|
@ -146,7 +146,7 @@ class Robot:
|
||||||
# change the orientation of the robot
|
# change the orientation of the robot
|
||||||
self.orientation = Robot.resulting_orientation[self.orientation][type]
|
self.orientation = Robot.resulting_orientation[self.orientation][type]
|
||||||
|
|
||||||
return "{}, {}".format(self.marker_id, type)
|
return "{}, {}".format(type, self.marker_id)
|
||||||
|
|
||||||
def move(self, type):
|
def move(self, type):
|
||||||
# move the robot forward or backward
|
# move the robot forward or backward
|
||||||
|
@ -165,7 +165,7 @@ class Robot:
|
||||||
self.y = target_tile.y
|
self.y = target_tile.y
|
||||||
|
|
||||||
# return the move for sending to the controller
|
# return the move for sending to the controller
|
||||||
return "{}, forward".format(self.marker_id)
|
return "forward, {}".format(self.marker_id)
|
||||||
elif type == 'backward':
|
elif type == 'backward':
|
||||||
opposite_orientation = self.get_opposite_orientation()
|
opposite_orientation = self.get_opposite_orientation()
|
||||||
target_tile = self.get_adjecent_tile(opposite_orientation)
|
target_tile = self.get_adjecent_tile(opposite_orientation)
|
||||||
|
@ -180,14 +180,14 @@ class Robot:
|
||||||
self.y = target_tile.y
|
self.y = target_tile.y
|
||||||
|
|
||||||
# return the move for sending to the controller
|
# return the move for sending to the controller
|
||||||
return "{}, backward".format(self.marker_id)
|
return "backward, {}".format(self.marker_id)
|
||||||
else:
|
else:
|
||||||
print("error: invalid move")
|
print("error: invalid move")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def nop(self):
|
def nop(self):
|
||||||
# do nothing command
|
# do nothing command
|
||||||
return "{}, nop".format(self.marker_id)
|
return "nop, {}".format(self.marker_id)
|
||||||
|
|
||||||
def board_element_processable(self):
|
def board_element_processable(self):
|
||||||
# check if we can directly process the board element for the tile the current robot is located on
|
# 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)
|
print(self)
|
||||||
|
|
||||||
# apply the actions caused by board elements at the end of the phase
|
# 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)
|
print(self)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user