mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Fixed the awful rule110 implementation
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
#include "lib_standard.h"
|
#include "lib_standard.h"
|
||||||
|
|
||||||
|
#include "toy_common.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
static int nativeClock(Interpreter* interpreter, LiteralArray* arguments) {
|
static int nativeClock(Interpreter* interpreter, LiteralArray* arguments) {
|
||||||
//no arguments
|
//no arguments
|
||||||
if (arguments->count != 0) {
|
if (arguments->count != 0) {
|
||||||
|
|||||||
@@ -1,66 +1,49 @@
|
|||||||
var size: int const = 100;
|
//number of iterations
|
||||||
|
var SIZE: int const = 100;
|
||||||
|
|
||||||
var prev = [];
|
//lookup table
|
||||||
for (var i = 0; i < size; i++) {
|
var lookup = [
|
||||||
prev.push(false);
|
"*": [
|
||||||
|
"*": [
|
||||||
|
"*": " ",
|
||||||
|
" ": "*"
|
||||||
|
],
|
||||||
|
" ": [
|
||||||
|
"*": "*",
|
||||||
|
" ": " "
|
||||||
|
]
|
||||||
|
], " ": [
|
||||||
|
"*": [
|
||||||
|
"*": "*",
|
||||||
|
" ": "*"
|
||||||
|
],
|
||||||
|
" ": [
|
||||||
|
"*": "*",
|
||||||
|
" ": " "
|
||||||
|
]
|
||||||
|
]];
|
||||||
|
|
||||||
|
//initial line to build from
|
||||||
|
var prev: string = "";
|
||||||
|
for (var i = 0; i < SIZE -1; i++) {
|
||||||
|
prev += " ";
|
||||||
}
|
}
|
||||||
|
prev += "*"; //initial
|
||||||
|
print prev;
|
||||||
|
|
||||||
prev.set(size - 1, true);
|
//run
|
||||||
|
|
||||||
|
|
||||||
fn calc(p, i) {
|
|
||||||
if (p[i-1] && p[i] && p[i+1]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p[i-1] && p[i] && !p[i+1]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p[i-1] && !p[i] && p[i+1]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p[i-1] && !p[i] && !p[i+1]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!p[i-1] && p[i] && p[i+1]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!p[i-1] && p[i] && !p[i+1]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!p[i-1] && !p[i] && p[i+1]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!p[i-1] && !p[i] && !p[i+1]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (var iteration = 0; iteration < 100; iteration++) {
|
for (var iteration = 0; iteration < 100; iteration++) {
|
||||||
var line = [false];
|
//left
|
||||||
for (var i = 1; i < size-1; i++) {
|
var output = (lookup[" "][prev[0]][prev[1]]);
|
||||||
line.push(calc(prev, i));
|
|
||||||
}
|
|
||||||
line.push(false);
|
|
||||||
|
|
||||||
var output = "";
|
//middle
|
||||||
for (var i = 0; i < line.length(); i++) {
|
for (var i = 1; i < SIZE-1; i++) {
|
||||||
if (line[i]) {
|
output += (lookup[prev[i-1]][prev[i]][prev[i+1]]);
|
||||||
output += "*";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
output += " ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//right
|
||||||
|
output += (lookup[prev[SIZE-2]][prev[SIZE-1]][" "]);
|
||||||
|
|
||||||
print output;
|
print output;
|
||||||
prev = line;
|
prev = output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1592,7 +1592,8 @@ static bool execIndex(Interpreter* interpreter, bool assignIntermediate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_ARRAY(compound) && !IS_DICTIONARY(compound) && !IS_STRING(compound)) {
|
if (!IS_ARRAY(compound) && !IS_DICTIONARY(compound) && !IS_STRING(compound)) {
|
||||||
interpreter->errorOutput("Unknown compound found in indexing notation\n");
|
interpreter->errorOutput("Unknown compound found in indexing notation: ");
|
||||||
|
printLiteralCustom(compound, interpreter->errorOutput);
|
||||||
freeLiteral(third);
|
freeLiteral(third);
|
||||||
freeLiteral(second);
|
freeLiteral(second);
|
||||||
freeLiteral(first);
|
freeLiteral(first);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#define TOY_VERSION_PATCH 5
|
#define TOY_VERSION_PATCH 5
|
||||||
#define TOY_VERSION_BUILD __DATE__ " " __TIME__
|
#define TOY_VERSION_BUILD __DATE__ " " __TIME__
|
||||||
|
|
||||||
|
//NOTE: I don't know why the time headers are here, need to try moving them back to the correct spots again
|
||||||
//platform exports/imports
|
//platform exports/imports
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#define TOY_API extern
|
#define TOY_API extern
|
||||||
|
|||||||
Reference in New Issue
Block a user