fixed wrong order of commands and missing command list for board elements
This commit is contained in:
parent
845c6b1cf1
commit
61605cb2ab
8
app.py
8
app.py
|
@ -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,10 +53,11 @@ 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())
|
||||
if not 'nop' in c:
|
||||
self.comm_socket.sendall((c + "\n").encode())
|
||||
data = self.comm_socket.recv(32)
|
||||
|
||||
if data != b'OK\n':
|
||||
|
|
10
roborally.py
10
roborally.py
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user