From d5fb388db4609347e98a371a81d3ab1bf94d2607 Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 13 Feb 2018 16:48:15 +0200 Subject: [PATCH] Make queen food movement match reference implementation - fix from trichoplaxify --- games/formic/GameManager.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/games/formic/GameManager.js b/games/formic/GameManager.js index a2daad7..3f3e62c 100644 --- a/games/formic/GameManager.js +++ b/games/formic/GameManager.js @@ -328,6 +328,7 @@ define([ } moveAnt(index, ant, action, rotation) { + /* jshint maxcomplexity:15 */ //Complex interactions for a complex game const p = this.offsetPos(ant, ROTATIONS[rotation][action.cell]); if(action.color) { setColourAtI(this.board, p.i, action.color); @@ -356,7 +357,26 @@ define([ ant.y = p.y; ant.i = p.i; } - if(ant.type !== QUEEN) { + if(ant.type === QUEEN) { + for(let i = 0; i < 9; ++ i) { + const target = this.antGrid[this.offsetPos(ant, i).i]; + if( + target && target.type !== QUEEN && + target.entry !== ant.entry + ) { + transferFood(target, ant); + } + } + for(let i = 0; i < 9; ++ i) { + const target = this.antGrid[this.offsetPos(ant, i).i]; + if( + target && target.type !== QUEEN && + target.entry === ant.entry + ) { + transferFood(target, ant); + } + } + } else { for(let i = 0; i < 9; ++ i) { const target = this.antGrid[this.offsetPos(ant, i).i]; if(