diff --git a/README.md b/README.md
index e4cd891..32950d5 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
# AI in the Browser
## In this Repo:
-- [Snake Lab](src/components/snake) - [Live](https://beefslab.com/webapps/snake-lab)
+- [Snake Lab](src/site/snake) - [Live](https://beefslab.com/webapps/snake-lab)
diff --git a/src/index.tsx b/src/index.tsx
index 73158d3..c84846c 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,6 +1,6 @@
import { createRoot } from 'react-dom/client';
-import App from './components/app';
+import App from './site/app';
import './index.scss';
diff --git a/src/components/app/index.tsx b/src/site/app/index.tsx
similarity index 100%
rename from src/components/app/index.tsx
rename to src/site/app/index.tsx
diff --git a/src/components/snake/brain-neat.ts b/src/site/snake/brain-neat.ts
similarity index 100%
rename from src/components/snake/brain-neat.ts
rename to src/site/snake/brain-neat.ts
diff --git a/src/components/snake/brain.ts b/src/site/snake/brain.ts
similarity index 100%
rename from src/components/snake/brain.ts
rename to src/site/snake/brain.ts
diff --git a/src/components/snake/canvas.ts b/src/site/snake/canvas.ts
similarity index 100%
rename from src/components/snake/canvas.ts
rename to src/site/snake/canvas.ts
diff --git a/src/components/snake/game-engine.ts b/src/site/snake/game-engine.ts
similarity index 100%
rename from src/components/snake/game-engine.ts
rename to src/site/snake/game-engine.ts
diff --git a/src/components/snake/hashset.ts b/src/site/snake/hashset.ts
similarity index 100%
rename from src/components/snake/hashset.ts
rename to src/site/snake/hashset.ts
diff --git a/src/components/snake/index.scss b/src/site/snake/index.scss
similarity index 100%
rename from src/components/snake/index.scss
rename to src/site/snake/index.scss
diff --git a/src/components/snake/index.tsx b/src/site/snake/index.tsx
similarity index 97%
rename from src/components/snake/index.tsx
rename to src/site/snake/index.tsx
index d82c599..d0b4eea 100644
--- a/src/components/snake/index.tsx
+++ b/src/site/snake/index.tsx
@@ -94,9 +94,7 @@ const SnakePage: FC = () => {
5,000 snakes per generation
Press Spacebar for Slow Motion
diff --git a/src/components/snake/ioset.ts b/src/site/snake/ioset.ts
similarity index 100%
rename from src/components/snake/ioset.ts
rename to src/site/snake/ioset.ts
diff --git a/src/components/snake/neat.pdf b/src/site/snake/neat.pdf
similarity index 100%
rename from src/components/snake/neat.pdf
rename to src/site/snake/neat.pdf
diff --git a/src/components/snake/network.ts b/src/site/snake/network.ts
similarity index 100%
rename from src/components/snake/network.ts
rename to src/site/snake/network.ts
diff --git a/src/components/snake/readme.md b/src/site/snake/readme.md
similarity index 100%
rename from src/components/snake/readme.md
rename to src/site/snake/readme.md
diff --git a/src/components/snake/snake-brain.ts b/src/site/snake/snake-brain.ts
similarity index 100%
rename from src/components/snake/snake-brain.ts
rename to src/site/snake/snake-brain.ts
diff --git a/src/components/snake/snake-lab-screenshot.png b/src/site/snake/snake-lab-screenshot.png
similarity index 100%
rename from src/components/snake/snake-lab-screenshot.png
rename to src/site/snake/snake-lab-screenshot.png
diff --git a/src/components/snake/toposort.pdf b/src/site/snake/toposort.pdf
similarity index 100%
rename from src/components/snake/toposort.pdf
rename to src/site/snake/toposort.pdf
diff --git a/src/components/snake/types.ts b/src/site/snake/types.ts
similarity index 100%
rename from src/components/snake/types.ts
rename to src/site/snake/types.ts
diff --git a/src/test/test-brain-neat.ts b/src/test/test-brain-neat.ts
index b400f4f..cecd5ff 100644
--- a/src/test/test-brain-neat.ts
+++ b/src/test/test-brain-neat.ts
@@ -1,93 +1,93 @@
-import { alignGenome, compatibilityDistance } from '../components/snake/brain-neat';
+import { alignGenome, compatibilityDistance } from '../site/snake/brain-neat';
import { assert, addTest } from './tests';
function testAlignGenome() {
- // these genomes are taken from the NEAT paper's example
- const genomeA = [
- { innovation: 1, src_id: 'A', dst_id: 'D', weight: 4, enabled: true },
- { innovation: 2, src_id: 'B', dst_id: 'D', weight: 0, enabled: false },
- { innovation: 3, src_id: 'C', dst_id: 'D', weight: 3, enabled: true },
- { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
- { innovation: 5, src_id: 'E', dst_id: 'D', weight: 5, enabled: true },
- // disjoint
- { innovation: 8, src_id: 'A', dst_id: 'E', weight: 7, enabled: true },
- ];
- const genomeB = [
- { innovation: 1, src_id: 'A', dst_id: 'D', weight: 8, enabled: true },
- { innovation: 2, src_id: 'B', dst_id: 'D', weight: 1, enabled: false },
- { innovation: 3, src_id: 'C', dst_id: 'D', weight: 2, enabled: true },
- { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
- { innovation: 5, src_id: 'E', dst_id: 'D', weight: 3, enabled: false },
- // disjoint
- { innovation: 6, src_id: 'E', dst_id: 'F', weight: 5, enabled: true },
- { innovation: 7, src_id: 'F', dst_id: 'D', weight: 5, enabled: true },
- // excess
- { innovation: 9, src_id: 'C', dst_id: 'E', weight: 5, enabled: true },
- { innovation: 10, src_id: 'A', dst_id: 'F', weight: 5, enabled: true },
- ];
+ // these genomes are taken from the NEAT paper's example
+ const genomeA = [
+ { innovation: 1, src_id: 'A', dst_id: 'D', weight: 4, enabled: true },
+ { innovation: 2, src_id: 'B', dst_id: 'D', weight: 0, enabled: false },
+ { innovation: 3, src_id: 'C', dst_id: 'D', weight: 3, enabled: true },
+ { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
+ { innovation: 5, src_id: 'E', dst_id: 'D', weight: 5, enabled: true },
+ // disjoint
+ { innovation: 8, src_id: 'A', dst_id: 'E', weight: 7, enabled: true },
+ ];
+ const genomeB = [
+ { innovation: 1, src_id: 'A', dst_id: 'D', weight: 8, enabled: true },
+ { innovation: 2, src_id: 'B', dst_id: 'D', weight: 1, enabled: false },
+ { innovation: 3, src_id: 'C', dst_id: 'D', weight: 2, enabled: true },
+ { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
+ { innovation: 5, src_id: 'E', dst_id: 'D', weight: 3, enabled: false },
+ // disjoint
+ { innovation: 6, src_id: 'E', dst_id: 'F', weight: 5, enabled: true },
+ { innovation: 7, src_id: 'F', dst_id: 'D', weight: 5, enabled: true },
+ // excess
+ { innovation: 9, src_id: 'C', dst_id: 'E', weight: 5, enabled: true },
+ { innovation: 10, src_id: 'A', dst_id: 'F', weight: 5, enabled: true },
+ ];
- const alignment = alignGenome(genomeA, genomeB);
+ const alignment = alignGenome(genomeA, genomeB);
- assert(alignment.matching.length === 5);
- assert(alignment.disjoint.length === 3);
- assert(alignment.excess.length === 2);
+ assert(alignment.matching.length === 5);
+ assert(alignment.disjoint.length === 3);
+ assert(alignment.excess.length === 2);
- const matchingPair = alignment.matching[1]!;
- assert(matchingPair.a === genomeA[1]);
- assert(matchingPair.b === genomeB[1]);
+ const matchingPair = alignment.matching[1]!;
+ assert(matchingPair.a === genomeA[1]);
+ assert(matchingPair.b === genomeB[1]);
- const disjointPairA = alignment.disjoint[0]!;
- assert(disjointPairA.a === null);
- assert(disjointPairA.b === genomeB[5]);
+ const disjointPairA = alignment.disjoint[0]!;
+ assert(disjointPairA.a === null);
+ assert(disjointPairA.b === genomeB[5]);
- const disjointPairB = alignment.disjoint[2]!;
- assert(disjointPairB.a === genomeA[5]);
- assert(disjointPairB.b === null);
+ const disjointPairB = alignment.disjoint[2]!;
+ assert(disjointPairB.a === genomeA[5]);
+ assert(disjointPairB.b === null);
- const excessPair = alignment.excess[0]!;
- assert(excessPair.a === null);
- assert(excessPair.b === genomeB[7]);
+ const excessPair = alignment.excess[0]!;
+ assert(excessPair.a === null);
+ assert(excessPair.b === genomeB[7]);
}
addTest(testAlignGenome);
function testCompatibilityDistance() {
- // these genomes are taken from the NEAT paper's example
- const genomeA = [
- { innovation: 1, src_id: 'A', dst_id: 'D', weight: 4, enabled: true },
- { innovation: 2, src_id: 'B', dst_id: 'D', weight: 0, enabled: false },
- { innovation: 3, src_id: 'C', dst_id: 'D', weight: 3, enabled: true },
- { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
- { innovation: 5, src_id: 'E', dst_id: 'D', weight: 5, enabled: true },
- // disjoint
- { innovation: 8, src_id: 'A', dst_id: 'E', weight: 7, enabled: true },
- ];
- const genomeB = [
- { innovation: 1, src_id: 'A', dst_id: 'D', weight: 8, enabled: true },
- { innovation: 2, src_id: 'B', dst_id: 'D', weight: 1, enabled: false },
- { innovation: 3, src_id: 'C', dst_id: 'D', weight: 2, enabled: true },
- { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
- { innovation: 5, src_id: 'E', dst_id: 'D', weight: 3, enabled: false },
- // disjoint
- { innovation: 6, src_id: 'E', dst_id: 'F', weight: 5, enabled: true },
- { innovation: 7, src_id: 'F', dst_id: 'D', weight: 5, enabled: true },
- // excess
- { innovation: 9, src_id: 'C', dst_id: 'E', weight: 5, enabled: true },
- { innovation: 10, src_id: 'A', dst_id: 'F', weight: 5, enabled: true },
- ];
+ // these genomes are taken from the NEAT paper's example
+ const genomeA = [
+ { innovation: 1, src_id: 'A', dst_id: 'D', weight: 4, enabled: true },
+ { innovation: 2, src_id: 'B', dst_id: 'D', weight: 0, enabled: false },
+ { innovation: 3, src_id: 'C', dst_id: 'D', weight: 3, enabled: true },
+ { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
+ { innovation: 5, src_id: 'E', dst_id: 'D', weight: 5, enabled: true },
+ // disjoint
+ { innovation: 8, src_id: 'A', dst_id: 'E', weight: 7, enabled: true },
+ ];
+ const genomeB = [
+ { innovation: 1, src_id: 'A', dst_id: 'D', weight: 8, enabled: true },
+ { innovation: 2, src_id: 'B', dst_id: 'D', weight: 1, enabled: false },
+ { innovation: 3, src_id: 'C', dst_id: 'D', weight: 2, enabled: true },
+ { innovation: 4, src_id: 'B', dst_id: 'E', weight: 9, enabled: true },
+ { innovation: 5, src_id: 'E', dst_id: 'D', weight: 3, enabled: false },
+ // disjoint
+ { innovation: 6, src_id: 'E', dst_id: 'F', weight: 5, enabled: true },
+ { innovation: 7, src_id: 'F', dst_id: 'D', weight: 5, enabled: true },
+ // excess
+ { innovation: 9, src_id: 'C', dst_id: 'E', weight: 5, enabled: true },
+ { innovation: 10, src_id: 'A', dst_id: 'F', weight: 5, enabled: true },
+ ];
- const alignment = alignGenome(genomeA, genomeB);
+ const alignment = alignGenome(genomeA, genomeB);
- const dist1 = compatibilityDistance(alignment, { c1: 1, c2: 0, c3: 0 });
- const dist2 = compatibilityDistance(alignment, { c1: 0, c2: 1, c3: 0 });
- const dist3 = compatibilityDistance(alignment, { c1: 0, c2: 0, c3: 1 });
- assert(dist1 === 2 / 10);
- assert(dist2 === 3 / 10);
- // |8 - 4| + |1 - 0| + |2 - 3| + |9 - 9| + |3 - 5|
- // 4 + 1 + 1 + 0 + 2
- // 8 / 5
- assert(dist3 === 8 / 5);
+ const dist1 = compatibilityDistance(alignment, { c1: 1, c2: 0, c3: 0 });
+ const dist2 = compatibilityDistance(alignment, { c1: 0, c2: 1, c3: 0 });
+ const dist3 = compatibilityDistance(alignment, { c1: 0, c2: 0, c3: 1 });
+ assert(dist1 === 2 / 10);
+ assert(dist2 === 3 / 10);
+ // |8 - 4| + |1 - 0| + |2 - 3| + |9 - 9| + |3 - 5|
+ // 4 + 1 + 1 + 0 + 2
+ // 8 / 5
+ assert(dist3 === 8 / 5);
- const distCombo = compatibilityDistance(alignment, { c1: 2, c2: 3, c3: 4 });
- assert(distCombo === 2 * (2 / 10) + 3 * (3 / 10) + 4 * (8 / 5));
+ const distCombo = compatibilityDistance(alignment, { c1: 2, c2: 3, c3: 4 });
+ assert(distCombo === 2 * (2 / 10) + 3 * (3 / 10) + 4 * (8 / 5));
}
addTest(testCompatibilityDistance);
diff --git a/src/test/test-ioset.ts b/src/test/test-ioset.ts
index 0092edd..b698fa2 100644
--- a/src/test/test-ioset.ts
+++ b/src/test/test-ioset.ts
@@ -1,31 +1,31 @@
-import IOSet from "../components/snake/ioset";
-import { addTest, assert, assertArrayEqual } from "./tests";
+import IOSet from '../site/snake/ioset';
+import { addTest, assert, assertArrayEqual } from './tests';
function testOrderMaintained() {
- const s = new IOSet();
- s.add('A');
- s.add('B');
- s.add('C');
- s.add('D');
- s.add('E');
- s.add('F');
- assert(s.size === 6);
- assertArrayEqual(Array.from(s), ['A', 'B', 'C', 'D', 'E', 'F']);
+ const s = new IOSet();
+ s.add('A');
+ s.add('B');
+ s.add('C');
+ s.add('D');
+ s.add('E');
+ s.add('F');
+ assert(s.size === 6);
+ assertArrayEqual(Array.from(s), ['A', 'B', 'C', 'D', 'E', 'F']);
}
addTest(testOrderMaintained);
function testOrderMaintainedWithDelete() {
- const s = new IOSet();
- s.add('A');
- s.add('B');
- s.add('C');
- s.add('D');
- s.add('E');
- s.delete('D');
- s.add('F');
- s.delete('B');
- s.add('G');
- assert(s.size === 5);
- assertArrayEqual(Array.from(s), ['A', 'C', 'E', 'F', 'G']);
+ const s = new IOSet();
+ s.add('A');
+ s.add('B');
+ s.add('C');
+ s.add('D');
+ s.add('E');
+ s.delete('D');
+ s.add('F');
+ s.delete('B');
+ s.add('G');
+ assert(s.size === 5);
+ assertArrayEqual(Array.from(s), ['A', 'C', 'E', 'F', 'G']);
}
addTest(testOrderMaintainedWithDelete);
diff --git a/src/test/test-network.ts b/src/test/test-network.ts
index 754c2be..8c3c1f9 100644
--- a/src/test/test-network.ts
+++ b/src/test/test-network.ts
@@ -1,4 +1,4 @@
-import { Network, Edge, Node, RawEdge } from '../components/snake/network';
+import { Network, Edge, Node, RawEdge } from '../site/snake/network';
import { addTest, assert, assertArrayEqual } from './tests';
function testEdgesToNodesBasic() {
@@ -135,8 +135,8 @@ function testEdgesToNodesMaintainsData() {
addTest(testEdgesToNodesMaintainsData);
function testCopyNodesPreventsModify() {
- type MyNode = Node;
- type MyEdge = Edge;
+ type MyNode = Node;
+ type MyEdge = Edge;
const edges = [
{ src_id: 'A', dst_id: 'B' },
{ src_id: 'B', dst_id: 'C' },
@@ -145,15 +145,15 @@ function testCopyNodesPreventsModify() {
const nodesCopy = Network.copyNodes(nodes);
- assert(nodes.size === nodesCopy.size);
+ assert(nodes.size === nodesCopy.size);
- // ensure that modifying a copied node does not modify the source node
- const nodeA = nodes.get('A')!;
- const nodeACopy = nodesCopy.get('A')!;
+ // ensure that modifying a copied node does not modify the source node
+ const nodeA = nodes.get('A')!;
+ const nodeACopy = nodesCopy.get('A')!;
- nodeACopy.dsts.pop()
+ nodeACopy.dsts.pop();
- assert(nodeA.dsts.size === 1);
- assert(nodeACopy.dsts.size === 0);
+ assert(nodeA.dsts.size === 1);
+ assert(nodeACopy.dsts.size === 0);
}
addTest(testCopyNodesPreventsModify);