feature_counts = {
const SAND = 0;
const OASIS = 1;
const SWAMP = 2;
const ROCK = 3;
let count = function(item, board) {
return board
.map(row => row.filter(n => n===item).reduce((acc, n) => acc += 1, 0))
.reduce((a,b) => a += b, 0);
}
let one_of = function(items) { return items[Math.floor(Math.random() * items.length)]; }
let populate = function(board) {
let n = 32;
game.board = board;
game.assign(OASIS, game.d6(), game.d4());
for (let x = 0; x < n; x++) {
let feature = one_of([SWAMP, SWAMP, ROCK, SWAMP]);
game.assign(feature, game.d6(), game.d4());
}
return board;
}
let samples = [];
let N = 100;
for (let x = 0; x < N; x++) {
let board = populate(empty_board());
samples.push({"category":"sand","count":count(SAND, board)});
samples.push({"category":"swamp","count":count(SWAMP, board)});
samples.push({"category":"rock","count":count(ROCK, board)});
}
return samples;
}