home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make Grid object mutable.
[cellular-automata.git]
/
life
/
006
/
life.ts
diff --git
a/life/006/life.ts
b/life/006/life.ts
index
e99d3fd
..
ac4b969
100644
(file)
--- a/
life/006/life.ts
+++ b/
life/006/life.ts
@@
-4,7
+4,7
@@
type GridLocation = {r: number, k: number};
interface GridInterface<A> {
get : (location: GridLocation) => A;
interface GridInterface<A> {
get : (location: GridLocation) => A;
- map : (f : (location: GridLocation) => A) =>
Grid<A>
;
+ map : (f : (location: GridLocation) => A) =>
void
;
moore_neighbors: (origin : GridLocation) => Array<GridLocation>;
print : (toString : (A: A) => string) => void;
};
moore_neighbors: (origin : GridLocation) => Array<GridLocation>;
print : (toString : (A: A) => string) => void;
};
@@
-61,9
+61,7
@@
class Grid<A> implements GridInterface<A> {
cells[r][k] = f(location);
}
};
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 {
};
private print_border(): void {
@@
-160,7
+158,7
@@
namespace Life {
};
next() : void {
};
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));
(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
}
);
return state_1
}
);
- this.grid = grid
};
print() : void {
};
print() : void {
This page took
0.027821 seconds
and
4
git commands to generate.