generated from michael/webpack-base
add smoke test for neat-snake-brain.ts
This commit is contained in:
parent
72a761eb3d
commit
e0838d091c
@ -9,6 +9,7 @@ import './test/test-network';
|
|||||||
import './test/test-ioset';
|
import './test/test-ioset';
|
||||||
import './test/test-neat';
|
import './test/test-neat';
|
||||||
import './test/test-neat-brain';
|
import './test/test-neat-brain';
|
||||||
|
import './test/test-neat-snake-brain';
|
||||||
import './test/test-util';
|
import './test/test-util';
|
||||||
|
|
||||||
const main = document.querySelector('main');
|
const main = document.querySelector('main');
|
||||||
|
@ -50,7 +50,7 @@ const _BASE_GENOME_SNAKE_BRAIN_NEAT_EDGES = completeBipartiteEdges(
|
|||||||
],
|
],
|
||||||
[OUTPUTS.U, OUTPUTS.D, OUTPUTS.L, OUTPUTS.R],
|
[OUTPUTS.U, OUTPUTS.D, OUTPUTS.L, OUTPUTS.R],
|
||||||
);
|
);
|
||||||
const BASE_GENOME_SNAKE_BRAIN_NEAT = _BASE_GENOME_SNAKE_BRAIN_NEAT_EDGES.map((e, idx) => ({
|
export const BASE_GENOME_SNAKE_BRAIN_NEAT = _BASE_GENOME_SNAKE_BRAIN_NEAT_EDGES.map((e, idx) => ({
|
||||||
...e,
|
...e,
|
||||||
data: { innovation: -_BASE_GENOME_SNAKE_BRAIN_NEAT_EDGES.length + idx, weight: 0, enabled: true },
|
data: { innovation: -_BASE_GENOME_SNAKE_BRAIN_NEAT_EDGES.length + idx, weight: 0, enabled: true },
|
||||||
}));
|
}));
|
||||||
|
29
src/test/test-neat-snake-brain.ts
Normal file
29
src/test/test-neat-snake-brain.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { vec2 } from '../site/snake/game-engine';
|
||||||
|
import { mutate } from '../site/snake/neat';
|
||||||
|
import { BASE_GENOME_SNAKE_BRAIN_NEAT, NEATSnakeBrain } from '../site/snake/neat-snake-brain';
|
||||||
|
import { addTest, assert } from './tests';
|
||||||
|
|
||||||
|
function testThink() {
|
||||||
|
const mc = {
|
||||||
|
mutate_rate: 0.25,
|
||||||
|
assign_rate: 0.1,
|
||||||
|
assign_mag: 1.0,
|
||||||
|
perturb_mag: 0.1,
|
||||||
|
new_node_rate: 0.2,
|
||||||
|
new_connection_rate: 0.1,
|
||||||
|
};
|
||||||
|
const genome = mutate(BASE_GENOME_SNAKE_BRAIN_NEAT, mc);
|
||||||
|
const brain = NEATSnakeBrain.fromGenome(genome);
|
||||||
|
|
||||||
|
const sgs = {
|
||||||
|
dead: false,
|
||||||
|
snake: [vec2(2, 2), vec2(2, 3), vec2(2, 4)],
|
||||||
|
apple: vec2(2, 6),
|
||||||
|
};
|
||||||
|
|
||||||
|
const move = brain.think(sgs);
|
||||||
|
|
||||||
|
assert(move !== 'dead');
|
||||||
|
assert(move !== vec2(0, -1));
|
||||||
|
}
|
||||||
|
addTest(testThink);
|
Loading…
Reference in New Issue
Block a user