aggression blaance

This commit is contained in:
biglyderv 2024-09-02 14:26:20 -04:00
parent ba526c16a5
commit 1cb3b42adb
No known key found for this signature in database
GPG key ID: 33AC87E9ACE66954

View file

@ -44,6 +44,7 @@ function Game(baseMap) {
this.baseMap = baseMap; this.baseMap = baseMap;
this.colors = {}; this.colors = {};
this.aggression = {}; this.aggression = {};
this.strength = {};
} }
Game.prototype.main = function() { Game.prototype.main = function() {
@ -52,6 +53,7 @@ Game.prototype.main = function() {
var data = dat.data; var data = dat.data;
var out = new Uint8Array(4); var out = new Uint8Array(4);
for (let k = 0; k < width*height; k++) { for (let k = 0; k < width*height; k++) {
let i = k; let i = k;
if (!colonized[i]) continue; if (!colonized[i]) continue;
@ -64,7 +66,7 @@ Game.prototype.main = function() {
if (isLand(rgba)) if (isLand(rgba))
setRGBA(data,i,this.colors[colonized[i]]); setRGBA(data,i,this.colors[colonized[i]]);
let weight = 10; let weight = 11;
let broken = false; let broken = false;
@ -83,7 +85,9 @@ Game.prototype.main = function() {
let rgbaH = rgba[0] * 0x10000 + rgba[1] * 0x100 + rgba[2]; let rgbaH = rgba[0] * 0x10000 + rgba[1] * 0x100 + rgba[2];
let bias = ((rgbaH in BIASES) ? BIASES[rgbaH] : 0.2) / weight; let bias = ((rgbaH in BIASES) ? BIASES[rgbaH] : 0.2) / weight;
if (colonized[y2 * width + x2] != 0) bias /= this.aggression[colonized[i]]; if (colonized[y2 * width + x2] != 0) {
bias *= this.aggression[colonized[i]];
}
if (Math.random() > bias) { if (Math.random() > bias) {
continue; continue;
@ -93,6 +97,7 @@ Game.prototype.main = function() {
} }
colonized[y2 * width + x2] = colonized[i2]; colonized[y2 * width + x2] = colonized[i2];
this.strength[colonized[i]]++;
broken = true; broken = true;
break; break;
} }
@ -140,6 +145,7 @@ Game.prototype.place = function() {
colonized[i] = count; colonized[i] = count;
this.aggression[count] = Math.random(); this.aggression[count] = Math.random();
this.colors[count] = [Math.floor(Math.random() * 255),Math.floor(Math.random() * 255),Math.floor(Math.random() * 255),255]; this.colors[count] = [Math.floor(Math.random() * 255),Math.floor(Math.random() * 255),Math.floor(Math.random() * 255),255];
this.strength[count] = 1;
} }
} }