class Actor {
constructor(pos) {
this.x = pos[0];
this.y = pos[1];
this.color = 'grey';
this.score = 0;
}
choice() {
return '0';
}
compute_score(matrix, scores_obj) {
this.score = 0;
var nei;
for (nei of get_neighbours(this.x, this.y, matrix)) {
this.score += compute_score(this.choice(), nei.choice(), scores_obj);
}
}
next_generation(matrix, avg) {
var best_performer = get_neighbours(this.x, this.y, matrix).reduce(
(acc, val) => {
return val === undefined || val.score < acc.score ? acc : val;
},
{ score: -1 }
);
var new_born = Object.create(Object.getPrototypeOf(best_performer));
new_born.color = best_performer.color;
new_born.type = best_performer.type;
new_born.x = this.x;
new_born.y = this.y;
new_born.score = 0;
return new_born;
}
}