files
Browse files
app.py
CHANGED
|
@@ -26,12 +26,16 @@ class MegaWorldEnv:
|
|
| 26 |
self.traps = [(3,3),(8,8),(12,12),(17,17),(9,10),(11,10)]
|
| 27 |
random.shuffle(self.traps)
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
self.enemies = [
|
| 31 |
{"pos":[5,5],"type":"patrol","axis":"x","range":(5,10),"dir":1},
|
| 32 |
{"pos":[15,5],"type":"patrol","axis":"x","range":(12,17),"dir":1},
|
| 33 |
-
{"pos":[12,12],"type":"hunter"},
|
| 34 |
-
{"pos":[16,16],"type":"hunter"}
|
| 35 |
]
|
| 36 |
random.shuffle(self.enemies)
|
| 37 |
|
|
@@ -44,7 +48,6 @@ class MegaWorldEnv:
|
|
| 44 |
walls += [(6,6),(7,7),(13,13),(14,14)]
|
| 45 |
return walls
|
| 46 |
|
| 47 |
-
# 🔑 STRONG SHAPING
|
| 48 |
def shaped_reward(self, old_pos, new_pos):
|
| 49 |
old_d = abs(old_pos[0]-self.goal[0]) + abs(old_pos[1]-self.goal[1])
|
| 50 |
new_d = abs(new_pos[0]-self.goal[0]) + abs(new_pos[1]-self.goal[1])
|
|
@@ -75,12 +78,13 @@ class MegaWorldEnv:
|
|
| 75 |
if e["pos"][0]>=e["range"][1] or e["pos"][0]<=e["range"][0]:
|
| 76 |
e["dir"]*=-1
|
| 77 |
else:
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
def render(self, player_pos, history, battery, score):
|
| 86 |
html="<div style='background:#000;padding:10px;border-radius:12px'>"
|
|
@@ -105,6 +109,8 @@ class MegaWorldEnv:
|
|
| 105 |
html+="</div></div>"
|
| 106 |
return html
|
| 107 |
|
|
|
|
|
|
|
| 108 |
def run_mega_simulation(file):
|
| 109 |
env=MegaWorldEnv()
|
| 110 |
if file is None:
|
|
@@ -161,7 +167,7 @@ def run_mega_simulation(file):
|
|
| 161 |
time.sleep(0.05)
|
| 162 |
|
| 163 |
with gr.Blocks() as demo:
|
| 164 |
-
gr.Markdown("# Super RL World —
|
| 165 |
with gr.Row():
|
| 166 |
game=gr.HTML(MegaWorldEnv().render((1,1),[],100,0))
|
| 167 |
with gr.Column():
|
|
@@ -170,4 +176,4 @@ with gr.Blocks() as demo:
|
|
| 170 |
log=gr.JSON()
|
| 171 |
btn.click(run_mega_simulation,file,[game,log])
|
| 172 |
|
| 173 |
-
demo.launch()
|
|
|
|
| 26 |
self.traps = [(3,3),(8,8),(12,12),(17,17),(9,10),(11,10)]
|
| 27 |
random.shuffle(self.traps)
|
| 28 |
|
| 29 |
+
# 1. REMOVED TOP LEFT CHARGER (2,18)
|
| 30 |
+
self.chargers = [(18,2),(10,10)]
|
| 31 |
+
|
| 32 |
+
# 2. DESIGNATED MOVEMENT FOR HUNTERS
|
| 33 |
+
# We add a 'path_index' to track their designated square movement
|
| 34 |
self.enemies = [
|
| 35 |
{"pos":[5,5],"type":"patrol","axis":"x","range":(5,10),"dir":1},
|
| 36 |
{"pos":[15,5],"type":"patrol","axis":"x","range":(12,17),"dir":1},
|
| 37 |
+
{"pos":[12,12],"type":"hunter", "step": 0},
|
| 38 |
+
{"pos":[16,16],"type":"hunter", "step": 0}
|
| 39 |
]
|
| 40 |
random.shuffle(self.enemies)
|
| 41 |
|
|
|
|
| 48 |
walls += [(6,6),(7,7),(13,13),(14,14)]
|
| 49 |
return walls
|
| 50 |
|
|
|
|
| 51 |
def shaped_reward(self, old_pos, new_pos):
|
| 52 |
old_d = abs(old_pos[0]-self.goal[0]) + abs(old_pos[1]-self.goal[1])
|
| 53 |
new_d = abs(new_pos[0]-self.goal[0]) + abs(new_pos[1]-self.goal[1])
|
|
|
|
| 78 |
if e["pos"][0]>=e["range"][1] or e["pos"][0]<=e["range"][0]:
|
| 79 |
e["dir"]*=-1
|
| 80 |
else:
|
| 81 |
+
# DESIGNATED MOVEMENT: Move in a 3x3 square pattern
|
| 82 |
+
# sequence: Right, Up, Left, Down
|
| 83 |
+
path = [(1,0), (1,0), (0,1), (0,1), (-1,0), (-1,0), (0,-1), (0,-1)]
|
| 84 |
+
move = path[e["step"] % len(path)]
|
| 85 |
+
e["pos"][0] += move[0]
|
| 86 |
+
e["pos"][1] += move[1]
|
| 87 |
+
e["step"] += 1
|
| 88 |
|
| 89 |
def render(self, player_pos, history, battery, score):
|
| 90 |
html="<div style='background:#000;padding:10px;border-radius:12px'>"
|
|
|
|
| 109 |
html+="</div></div>"
|
| 110 |
return html
|
| 111 |
|
| 112 |
+
# ... [Rest of the simulation and Gradio code remains the same] ...
|
| 113 |
+
|
| 114 |
def run_mega_simulation(file):
|
| 115 |
env=MegaWorldEnv()
|
| 116 |
if file is None:
|
|
|
|
| 167 |
time.sleep(0.05)
|
| 168 |
|
| 169 |
with gr.Blocks() as demo:
|
| 170 |
+
gr.Markdown("# Super RL World — UPDATED CONFIGURATION")
|
| 171 |
with gr.Row():
|
| 172 |
game=gr.HTML(MegaWorldEnv().render((1,1),[],100,0))
|
| 173 |
with gr.Column():
|
|
|
|
| 176 |
log=gr.JSON()
|
| 177 |
btn.click(run_mega_simulation,file,[game,log])
|
| 178 |
|
| 179 |
+
demo.launch()
|