shithub: orca

Download patch

ref: b5c616a3de3d5c9c473e3ddd6b0d733fd5833c1a
parent: dcb00be88047faa9edb80fdce3ed5299a008239f
author: Devine Lu Linvega <aliceffekt@gmail.com>
date: Sun Nov 25 10:23:42 EST 2018

Added m

--- a/sim.c
+++ b/sim.c
@@ -29,6 +29,14 @@
   return indexed_terms[(ia + ib) % Terms_array_num];
 }
 
+static inline Term terms_mod(Term a, Term b) {
+  size_t ia = index_of_term(term_lowered(a));
+  size_t ib = index_of_term(term_lowered(b));
+  if (ia == SIZE_MAX) ia = 0;
+  if (ib == SIZE_MAX) ib = 0;
+  return indexed_terms[ia % ib];
+}
+
 static inline void act_a(Field* f, U32 y, U32 x) {
   Term inp0 = field_peek_relative(f, y, x, 0, 1);
   Term inp1 = field_peek_relative(f, y, x, 0, 2);
@@ -38,6 +46,15 @@
   }
 }
 
+static inline void act_m(Field* f, U32 y, U32 x) {
+  Term inp0 = field_peek_relative(f, y, x, 0, 1);
+  Term inp1 = field_peek_relative(f, y, x, 0, 2);
+  if (inp0 != '.' && inp1 != '.') {
+    Term t = terms_mod(inp0, inp1);
+    field_poke_relative(f, y, x, 1, 0, t);
+  }
+}
+
 void orca_run(Field* f) {
   size_t ny = f->height;
   size_t nx = f->width;
@@ -49,6 +66,9 @@
       switch (c) {
         case 'a':
           act_a(f, iy, ix);
+          break;
+        case 'm':
+          act_m(f, iy, ix);
           break;
       }
     }