Skip to content

Commit 49c7bef

Browse files
authored
Update TI branch.
Update TI branch.
2 parents 9810bda + e7226c5 commit 49c7bef

8 files changed

Lines changed: 909 additions & 335 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ missclasification issue in the GDELT data analysis.
268268
-->
269269

270270
## Citations
271-
For citations, see our list of [Logica publications](https://logica-web.github.io/publications/).
271+
For citations, see our list of [Logica publications](https://logica-lang.github.io/publications/).
272272

273273
## Feedback
274274

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
</div>
168168
</div>
169169
</a>
170-
<a href="https://logica-web.github.io/" style="text-decoration: none; color: inherit;">
170+
<a href="https://logica-lang.github.io/" style="text-decoration: none; color: inherit;">
171171
<div class="github_button" style="float: none; margin-top: 0px; padding: 5px;" onclick="openBook()">
172172
<div style="float: none; text-align: center; display: flex; flex-direction: row;">
173173
<div id="closed_book" style="font-size: 4em; display:flex; margin: 0px; width: 80px; text-align: center; justify-content: center;"><span>📘</span></div>

docs/robots/Level12.json

Lines changed: 53 additions & 0 deletions
Large diffs are not rendered by default.

docs/robots/charger.l

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# NEW PREDICATE: Creates a table of all robots with an empty battery.
2+
DeadBot(robot_name:) :-
3+
# Find the sensor data for every robot in the simulation.
4+
Sensor(robot_name: , sensor:),
5+
# Check if that robot has a battery and its level is zero.
6+
sensor.self.has_battery == true,
7+
sensor.self.battery_level == 0;
8+
9+
# HELPER FUNCTION: Returns true if a radar ping 'r' is a charging station.
10+
IsChargingStation(r) = (
11+
r.object == "beacon" && EndsWith(r.label, "_ChargingStation")
12+
);
13+
14+
# HELPER FUNCTION: Finds the ANGLE of the closest DEAD BOT.
15+
ClosestDeadBotAngle(radar) = ArgMin{
16+
r.angle -> r.distance :-
17+
r in radar,
18+
r.object == "robot",
19+
# We check if the name of the robot we see (r.label)
20+
# exists in our table of dead bots.
21+
DeadBot(robot_name: r.label)
22+
};
23+
24+
# HELPER FUNCTION: Finds the ANGLE of the closest CHARGING STATION.
25+
ClosestChargingStationAngle(radar) = ArgMin{
26+
r.angle -> r.distance :-
27+
r in radar,
28+
IsChargingStation(r)==true
29+
};
30+
31+
# A helper function to steer towards a target angle.
32+
SteerTo(target_angle, speed) = {
33+
left_engine: speed - target_angle,
34+
right_engine: speed + target_angle
35+
};
36+
37+
# Standard obstacle avoidance logic.
38+
WeightedAverage(k->v) = Sum(k * v) / Sum(k);
39+
FreedomMotion(radar) = WeightedAverage{
40+
x.distance -> x.angle :- x in radar
41+
};
42+
43+
# Returns true if the robot should be helping a dead bot.
44+
ShouldHelpDeadBot(sensor) = (
45+
sensor.self.can_charge == true &&
46+
sensor.self.battery_level > 0 &&
47+
# We count how many of the robots we see in our radar
48+
# have a name that is in the DeadBot table.
49+
Count{ 1 :-
50+
r in sensor.radar,
51+
r.object == "robot",
52+
DeadBot(robot_name: r.label)
53+
} > 0
54+
);
55+
56+
# Returns true if the robot should be seeking a charging station.
57+
ShouldSeekCharger(sensor) = (
58+
sensor.self.can_charge == true &&
59+
sensor.self.battery_level == 0 &&
60+
Count{1 :- r in sensor.radar, IsChargingStation(r)==true} > 0
61+
);
62+
63+
# --- Main Logic Starts Here (Now Explicit) ---
64+
65+
# PRIORITY 1: A robot that can_charge will go help a dead robot it sees.
66+
Robot(robot_name:, desire:, memory:) :-
67+
Sensor(robot_name:, sensor:),
68+
# Check if the conditions for this priority are met.
69+
ShouldHelpDeadBot(sensor)==true,
70+
# Find the angle to the closest one.
71+
dead_bot_angle = ClosestDeadBotAngle(sensor.radar),
72+
desire = SteerTo(dead_bot_angle, 1),
73+
memory = "Going to help a robot in need!";
74+
75+
76+
# PRIORITY 2: If a robot that can_charge has no battery, it seeks a station.
77+
Robot(robot_name:, desire:, memory:) :-
78+
Sensor(robot_name:, sensor:),
79+
# Check if the conditions for this priority are met.
80+
ShouldSeekCharger(sensor)==true,
81+
# Find the angle to the closest one.
82+
station_angle = ClosestChargingStationAngle(sensor.radar),
83+
desire = SteerTo(station_angle, 1),
84+
memory = "My battery is empty! Seeking a charging station.";
85+
86+
87+
# PRIORITY 3 (DEFAULT): All other robots will just wander around avoiding walls.
88+
Robot(robot_name:, desire:, memory:) :-
89+
Sensor(robot_name:, sensor:),
90+
ShouldHelpDeadBot(sensor)==false,
91+
ShouldSeekCharger(sensor)==false,
92+
freedom = FreedomMotion(sensor.radar),
93+
speed = 0.5,
94+
desire = {
95+
left_engine: speed - freedom+0.1,
96+
right_engine: speed + freedom
97+
},
98+
memory = "Exploring the labyrinth.";

docs/robots/editor5.html

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,70 @@
150150
border-radius: 50%;
151151
cursor: pointer;
152152
}
153-
153+
/* The switch container */
154+
.switch {
155+
position: relative;
156+
display: inline-block;
157+
width: 50px; /* Smaller width */
158+
height: 28px; /* Smaller height */
159+
margin-left: auto; /* Aligns it to the right */
160+
}
161+
162+
/* Hide the default HTML checkbox */
163+
.switch input {
164+
opacity: 0;
165+
width: 0;
166+
height: 0;
167+
}
168+
169+
/* The slider track */
170+
.slider {
171+
position: absolute;
172+
cursor: pointer;
173+
top: 0;
174+
left: 0;
175+
right: 0;
176+
bottom: 0;
177+
background-color: #555; /* Off color to match your theme */
178+
-webkit-transition: .4s;
179+
transition: .4s;
180+
}
181+
182+
/* The slider handle (the circle) */
183+
.slider:before {
184+
position: absolute;
185+
content: "";
186+
height: 20px; /* Adjusted size */
187+
width: 20px; /* Adjusted size */
188+
left: 4px;
189+
bottom: 4px;
190+
background-color: white;
191+
-webkit-transition: .4s;
192+
transition: .4s;
193+
}
194+
195+
/* --- The Magic: What happens when the checkbox is checked --- */
196+
197+
/* Change the background of the track to green */
198+
input:checked + .slider {
199+
background-color: #34c759; /* Green to match your 'Download' button */
200+
}
201+
202+
/* Move the handle to the right */
203+
input:checked + .slider:before {
204+
-webkit-transform: translateX(22px); /* Adjusted distance */
205+
-ms-transform: translateX(22px);
206+
transform: translateX(22px);
207+
}
208+
209+
/* Rounded sliders */
210+
.slider.round {
211+
border-radius: 28px;
212+
}
213+
214+
.slider.round:before {
215+
border-radius: 50%;
216+
}
154217
/* Modal styles for alerts and editing */
155218
.modal-backdrop {
156219
position: fixed;
@@ -352,6 +415,36 @@ <h3 id="editTitle">Edit Object</h3>
352415
<label for="editOffBeacon">Off Beacon:</label>
353416
<select id="editOffBeacon"></select>
354417
</div>
418+
<div class="edit-row" id="editChargingStationRow" style="display: none;">
419+
<label for="editChargingStation">Charging Station:</label>
420+
<label class="switch">
421+
<input type="checkbox" id="editChargingStation">
422+
<span class="slider round"></span>
423+
</label>
424+
</div>
425+
<div class="edit-row" id="hasBatteryRow" style="display: none;">
426+
<label for="hasBatteryToggle">Has Battery:</label>
427+
<label class="switch">
428+
<input type="checkbox" id="hasBatteryToggle">
429+
<span class="slider round"></span>
430+
</label>
431+
</div>
432+
<div class="edit-row" id="canChargeRow" style="display: none;">
433+
<label for="canChargeToggle">Can Charge:</label>
434+
<label class="switch">
435+
<input type="checkbox" id="canChargeToggle">
436+
<span class="slider round"></span>
437+
</label>
438+
</div>
439+
<div class="edit-row" id="batteryConsumptionRow" style="display: none;">
440+
<label for="batteryConsumptionSlider">Consumption Rate:</label>
441+
<input type="range" id="batteryConsumptionSlider" min="0" max="1" step="0.01" value="1">
442+
<span id="batteryConsumptionValue" style="width: 40px; text-align: right;">1.00</span>
443+
</div>
444+
<div class="edit-row" id="batteryCapacityRow" style="display: none;">
445+
<label for="batteryCapacityInput">Battery Capacity:</label>
446+
<input type="number" id="batteryCapacityInput" value="100" min="0">
447+
</div>
355448
<div class="edit-row" id="editStickySwitchRow" style="display: none;">
356449
<label for="editStickySwitch">Sticky Switch:</label>
357450
<input type="checkbox" id="editStickySwitch">

0 commit comments

Comments
 (0)