X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=life%2F006%2Flife.ts;h=ac4b969a177ab109bbd9fb756888bd56ff0063b3;hb=6fe41dc7e88d0b191c2e8d522d66500203ed2bb8;hp=58f3f8b5d7c965f762aa1fc63db13af22d74b39c;hpb=ecf4b00f3ae28e13f666803eac456b62c4a40d66;p=cellular-automata.git
diff --git a/life/006/life.ts b/life/006/life.ts
index 58f3f8b..ac4b969 100644
--- a/life/006/life.ts
+++ b/life/006/life.ts
@@ -4,7 +4,7 @@ type GridLocation = {r: number, k: number};
interface GridInterface {
get : (location: GridLocation) => A;
- map : (f : (location: GridLocation) => A) => Grid;
+ map : (f : (location: GridLocation) => A) => void;
moore_neighbors: (origin : GridLocation) => Array;
print : (toString : (A: A) => string) => void;
};
@@ -61,9 +61,7 @@ class Grid implements GridInterface {
cells[r][k] = f(location);
}
};
- const init = ({r, k}) => cells[r][k];
- const grid = new Grid({rows: this.rows, columns: this.columns, init: init});
- return grid
+ this.cells = cells;
};
private print_border(): void {
@@ -109,7 +107,7 @@ namespace Life {
switch (i)
{ case 0 : return "Dead"
; case 1 : return "Alive"
- ; default: throw("No known State for integer: " + i)
+ ; default: throw new RangeError("No known State for integer: " + i)
}
};
@@ -117,7 +115,7 @@ namespace Life {
switch (t)
{ case "Dead" : return " "
; case "Alive": return "o"
- ; default : throw("Illegal member of Life.State.T: " + t)
+ ; default : throw new TypeError("Illegal member of Life.State.T: " + t)
}
};
@@ -125,7 +123,7 @@ namespace Life {
switch (t)
{ case "Dead" : return false
; case "Alive": return true
- ; default : throw("Illegal member of Life.State.T: " + t)
+ ; default : throw new TypeError("Illegal member of Life.State.T: " + t)
}
};
@@ -160,7 +158,7 @@ namespace Life {
};
next() : void {
- const grid = this.grid.map(
+ this.grid.map(
(location) => {
const neighbor_locations = this.grid.moore_neighbors(location);
const neighbor_states = neighbor_locations.map((l) => this.grid.get(l));
@@ -170,7 +168,6 @@ namespace Life {
return state_1
}
);
- this.grid = grid
};
print() : void {