Skip to content
Snippets Groups Projects
Commit efe7cfbc authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Mapping not yet working

parent 378d7fff
Branches
No related tags found
1 merge request!1merge Nico
id = [0,0] id = [0,0]
def display_id(): def display_id():
afficher_texte("{}, {}".format(id[0], id[1]), speed=0.001) afficher_texte("{}, {}".format(id[0], id[1]), speed=0.01)
def msg_to_str(msg): def msg_to_str(msg):
return str(msg)[2:-1] return str(msg)[2:-1]
def send_passthrough(msg, x, y):
def handle_receive(msg, dir): x = int(x)
y = int(y)
newx = x
newy = y
if x > id[0]:
d = O
newx += 1
elif x < id[0]:
d = E
newx -= 1
elif y > id[1]:
d = S
newy += 1
else:
d = N
newy -= 1
envoyer_msg(d, "PT;{},{};{}".format(newx, newy, msg))
def send_xy(x, y, msg):
send_passthrough(msg, x, y)
def check_presence(d):
envoyer_msg(d, "PING")
time.sleep(0.05)
ret = recevoir_msg(d)
print("checking pres for {} : {}".format(d, ret))
if ret == b"": return False
return True
def update_id(new_id):
global id global id
id[0] = int(new_id[0])
id[1] = int(new_id[1])
envoyer_msg(N, "SET_ID:{},{}".format(id[0], id[1] + 1))
envoyer_msg(E, "SET_ID:{},{}".format(id[0] + 1, id[1]))
if not check_presence(N) and not check_presence(E):
send_xy(0, 0, "MATSIZE:{},{}".format(id[0], id[1]))
display_id()
def handle_receive(msg, d):
msg = msg_to_str(msg) msg = msg_to_str(msg)
if msg.startswith("SET_ID"): if msg.startswith("SET_ID"):
id = msg[7:].split(",") tmp_id = msg[7:].split(",")
display_id() update_id(tmp_id)
elif msg == "PING": elif msg == "PING":
envoyer_msg(dir, "PONG") envoyer_msg(d, "PONG")
elif msg == "DISP_ID": elif msg == "DISP_ID":
display_id() display_id()
elif msg.startswith("PT;"):
print(msg)
msgs = msg.split(";")
m = msgs[2]
x, y = msgs[1].split(",")
if x == id[0] and y == id[1]:
handle_receive(m, d)
return
send_passthrough(m, int(x), int(y))
afficher_texte("Ready", VERT, speed=0.01) afficher_texte("Ready", VERT, speed=0.01)
while True: while True:
msg = recevoir_msg(S)
handle_receive(msg, S) for d in [N, S, E, O]:
time.sleep(0.5) msg = recevoir_msg(d)
handle_receive(msg, d)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment