class Move {
    constructor(toward, enemyBot = true) { //true = move toward / false = flee from
        this.toward = toward;
        this.enemyBot = enemyBot;
    }

    do(robot) {
        if (this.enemyBot) {
            if (robot.verifyTarget()) {
                if (this.toward === true) {
                    return this.moveToward(robot);
                } else {
                    return this.fleeFrom(robot);
                }
            }
        } else {
            let bonusTarget = chooseTarget(robot, listBonus);
            if (bonusTarget !== undefined) {
                let ret;
                if (this.toward === true) {
                    ret = this.moveToward(robot, bonusTarget);
                } else {
                    ret = this.fleeFrom(robot, bonusTarget);
                }
                if (!ret) {
                    bonusTarget.useOn(robot);
                    listBonus.splice(listBonus.indexOf(bonusTarget), 1);
                    robot.target = null;
                }
                return true;
            }
        }
        return false;
    }

    moveToward(robot, target = robot.target) {
        return robot.advanceTo(target);

    }

    fleeFrom(robot, target = robot.target) {
        return robot.fleeFrom(target);
    }

    getFrame() {
        let frame;
        if (this.toward)
            frame = 0;
        else
            frame = 2;
        if (!this.enemyBot)
            frame += 1;
        return frame;
    }

    getOptionJson() {
        return this.toward + ',' + this.enemyBot;
    }
}