Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,6 +1,15 @@
[[wp:Wireworld|Wireworld]] is a cellular automaton with some similarities to [[Conway's Game of Life]]. It is capable of doing sophisticated computations with appropriate programs (it is actually [[wp:Turing-complete|Turing complete]]), and is much simpler to program for.
{{omit from|GUISS}}
[[wp:Wireworld|Wireworld]] is a cellular automaton with some similarities to [[Conway's Game of Life]].
A wireworld arena consists of a cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneously. The cell transition rules are this:
It is capable of doing sophisticated computations with appropriate programs
(it is actually [[wp:Turing-complete|Turing complete]]),
and is much simpler to program for.
A wireworld arena consists of a cartesian grid of cells,
each of which can be in one of four states.
All cell transitions happen simultaneously.
The cell transition rules are this:
{| class=wikitable
|-
! Input State

View file

@ -46,12 +46,11 @@ int main()
int f;
for (f = 0; ; f = 1 - f) {
#ifdef ANIMATE_VT100_POSIX
puts("\x1b[H");
#endif
puts(world_7x14[f]);
next_world(world_7x14[f], world_7x14[1-f], 14, 7);
#ifdef ANIMATE_VT100_POSIX
printf("\x1b[%dA", 8);
printf("\x1b[%dD", 14);
{
static const struct timespec ts = { 0, 100000000 };
nanosleep(&ts, 0);

View file

@ -1,8 +1,8 @@
import std.stdio, std.algorithm;
void wireworldStep(char[][] W1, char[][] W2) pure nothrow {
foreach (r; 1 .. W1.length - 1)
foreach (c; 1 .. W1[0].length - 1)
void wireworldStep(char[][] W1, char[][] W2) pure nothrow @safe @nogc {
foreach (immutable r; 1 .. W1.length - 1)
foreach (immutable c; 1 .. W1[0].length - 1)
switch (W1[r][c]) {
case 'H': W2[r][c] = 't'; break;
case 't': W2[r][c] = '.'; break;
@ -28,10 +28,10 @@ void main() {
foreach (row; world)
world2 ~= row.dup;
foreach (step; 0 .. 7) {
foreach (immutable step; 0 .. 7) {
writefln("\nStep %d: ------------", step);
foreach (row; world[1 .. $-1])
writeln(row[1 .. $-1]);
foreach (row; world[1 .. $ - 1])
row[1 .. $ - 1].writeln;
wireworldStep(world, world2);
swap(world, world2);
}

View file

@ -2,7 +2,7 @@ class Wireworld {
has @.line;
multi method new(@line) { self.new: :@line }
multi method new($str ) { self.new: $str.split: "\n" }
multi method new($str ) { self.new: $str.lines }
method gist { join "\n", @.line }
method postcircumfix:<[ ]>($i) { @.line[$i].comb }

View file

@ -0,0 +1,65 @@
/*REXX program displays a wire world cartesuab grid of four─state cells.*/
signal on halt /*handle cell growth interruptus.*/
parse arg iFID . '(' generations rows cols bare eHead eTail conductor clearScreen repeats
if iFID=='' then iFID='WIREWORLD.TXT' /*use the default file for input?*/
blank = 'BLANK' /*the "name" for blank*/
generations = p(generations 100) /*#generations allowed*/
rows = p(rows 3) /*number of cell rows.*/
cols = p(cols 3) /* " " " cols.*/
bare = pickChar(bare blank) /*an empty cell thingy*/
clearScreen = p(clearScreen 0) /*1 = clear the screen*/
eHead = pickchar(eHead 'H')
eTail = pickchar(eTail 't')
conductor = pickchar(conductor . )
repeats = p(repeats 2) /*stop if 2 repeats.*/
fents=max(linesize()-1,cols) /*fence width shown after display*/
#repeats=0; $.=bare /*the universe is new, and barren*/
gens=abs(generations) /*use this for convenience. */
/* [↓] read the input file. */
do r=1 while lines(iFID)\==0 /*keep reading until end-of-file.*/
q=strip(linein(iFID),'T') /*get a single line from the file*/
_=length(q) /*obtain the length of this row. */
cols=max(cols,_) /*calculate the maximum # of cols*/
do c=1 for _; $.r.c=substr(q,c,1); end /*assign row cells*/
end /*r*/
rows=r-1
cycle=0; !.=0; call showCells /*show initial state of the cells*/
/*─────────────────────────────────────watch cells evolve 4 poss. states*/
do cycle=1 for gens; @.=bare
do r=1 for rows
do c=1 for cols; ?=$.r.c; ??=?
select
when ?==eHead then ??=eTail
when ?==eTail then ??=conductor
when ?==conductor then do; n=neighbors()
if n==1 | n==2 then ??=eHead
end
otherwise nop
end /*select*/
@.r.c=??
end /*c*/
end /*r*/
call assign$ /*assign alternate cells ──► real*/
if generations>0 | cycle==gens then call showCells
end /*cycle*/
/*─────────────────────────────────────stop watching the universe (life)*/
halt: cycles=life-1; if cycles\==gens then say 'REXX program interrupted.'
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────SHOWCELLS subroutine───────────────────*/
showCells: if clearScreen then 'CLS' /* ◄─── change this for your OS.*/
call showRows /*show the rows in proper order. */
say right(copies('',fents)cycle,fents) /*show&tell for a bunch of cells*/
if _=='' then exit /*if no life, then stop the run. */
if !._ then #repeats=#repeats+1 /*we detected a repeated pattern.*/
!._=1 /*existence state & compare later*/
if repeats\==0 & #repeats<=repeats then return /*so far, so good.*/
say '"Wireworld" repeated itself' repeats "times, program is stopping."
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────1─liner subroutines───────────────────────────────────────────────────────────────────────*/
$: parse arg _row,_col; return $._row._col==eHead
assign$: do r=1 for rows; do c=1 for cols; $.r.c=@.r.c; end; end; return
err: say;say;say center(' error! ',max(40,linesize()%2),"*");say;do j=1 for arg();say arg(j);say;end;say;exit 13
neighbors: return $(r-1,c-1)+$(r-1,c)+$(r-1,c+1)+$(r,c-1)+$(r,c+1)+$(r+1,c-1)+$(r+1,c)+$(r+1,c+1)
p: return word(arg(1),1)
pickChar: _=p(arg(1));if translate(_)==blank then _=' ';if length(_)==3 then _=d2c(_);if length(_)==2 then _=x2c(_);return _
showRows: _=; do r=1 for rows; z=; do c=1 for cols; z=z||$.r.c; end; z=strip(z,'T'); say z; _=_||z; end; return