diff --git a/mapping/main.py b/mapping/main.py
index 14b9c57e44c388687c29169d6063fa7f93fce216..3a3c98c7142f058e7c1b5430f809f66693941cbc 100644
--- a/mapping/main.py
+++ b/mapping/main.py
@@ -1,30 +1,92 @@
 id = [0,0]
  
 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):
 	return str(msg)[2:-1]
  
- 
-def handle_receive(msg, dir):
+def send_passthrough(msg, x, y):
+	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
- 
+
+	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)
  
 	if msg.startswith("SET_ID"):
-		id = msg[7:].split(",")
-		display_id()
+		tmp_id = msg[7:].split(",")
+		update_id(tmp_id)
  
 	elif msg == "PING":
-		envoyer_msg(dir, "PONG")
+		envoyer_msg(d, "PONG")
  
 	elif msg == "DISP_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)
  
 while True:
-	msg = recevoir_msg(S)
-	handle_receive(msg, S)
-	time.sleep(0.5)
+
+	for d in [N, S, E, O]:
+		msg = recevoir_msg(d)
+		handle_receive(msg, d)