]> git.cworth.org Git - zombocom-ai/blobdiff - index.js
Assign different default code to each boy
[zombocom-ai] / index.js
index 6aef48c06360b598ef68eb9d5bbaa0e02efce188..606fba79adbd99c68135ced4f9efa854c601980e 100644 (file)
--- a/index.js
+++ b/index.js
@@ -180,6 +180,52 @@ function start_bus_timer() {
     bus_interval = setInterval(emit_bus_timer, 1000);
 }
 
+bus_code = [
+    `def random_dot():
+  x = random_within(512)
+  y = random_within(512)
+  radius = 4 + random_within(6)
+  circle(x, y, radius)
+  fill()
+
+for i in range(400):
+  set_color('midnight blue' if i % 2 == 0 else 'navy blue')
+  set_opacity(0.5)
+  random_dot()`,
+
+    `def random_line():
+  x = random_within(512) - 60
+  y = random_within(512) - 60
+  dx = 60 + random_within(20)
+  dy = 40 + random_within(20)
+  set_opacity(random_within(0.5))
+  line(x, y, dx, dy)
+  stroke()
+
+for i in range(200):
+  set_color('black')
+  random_line()`,
+
+    `def random_blob():
+  move_to(random_within(512), random_within(512))
+  wiggle()
+  set_opacity(random_within(1.0))
+  fill()
+
+for i in range(100):
+  set_random_color()
+  random_blob()`,
+
+    `def random_curve():
+  move_to(random_within(512), random_within(512))
+  wiggle()
+  stroke()
+
+for i in range(200):
+  set_color('pink' if i % 2 == 0 else 'lime green')
+  random_curve()`
+];
+
 io_bus.on("connection", (socket) => {
     if (! socket.request.session.name) {
        console.log("Error: Someone showed up at the Magic School Bus without a name.");
@@ -188,6 +234,7 @@ io_bus.on("connection", (socket) => {
 
     const name = socket.request.session.name;
     const bus = state.bus;
+    var player_number;
 
     // Let the new user know the state of the bus
     socket.emit("state", bus.state);
@@ -196,6 +243,32 @@ io_bus.on("connection", (socket) => {
        start_bus_timer();
     }
 
+    // Assign each boy a different portion of the solution
+    switch (name[0]) {
+    case 'C':
+    case 'c':
+       player_number = 0;
+       break;
+    case 'H':
+    case' h':
+       player_number = 1;
+       break;
+    case 'A':
+    case 'a':
+       player_number = 2;
+       break;
+    case 'S':
+    case 's':
+       player_number = 3;
+       break;
+    default:
+       player_number = Math.floor(Math.random()*4);
+       break;
+    }
+
+    // And send them different code based on their number
+    socket.emit("code", bus_code[player_number]);
+
     if (! bus.students.names.includes(name)) {
        bus.students.count = bus.students.count + 1;
        io_bus.emit('students', bus.students.count);
@@ -204,7 +277,7 @@ io_bus.on("connection", (socket) => {
 
     socket.on('run', code => {
        try {
-           output = child_process.execFileSync(python_path, [interpret_cairo_script, code], { input: code });
+           output = child_process.execFileSync(python_path, [interpret_cairo_script, player_number], { input: code });
            // Grab just first line of output
            const nl = output.indexOf("\n");
            if (nl === -1)