Coder Social home page Coder Social logo

Comments (2)

kuviman avatar kuviman commented on August 16, 2024

Looks like that one is bug in your code

from raic-2019.

alvinalvord avatar alvinalvord commented on August 16, 2024

Okay, i found the problem. Apparently I shouldn't reuse the unit action object. The problem fixes itself when I reinitialize a new unit action every time get action is called. I've inserted the code I've been testing for a while :)) thanks anyway.

import model.*;

public class MyStrategy {
	UnitAction action;
	
	MyStrategy () {
		action = new UnitAction ();
	}
	
	public UnitAction getAction(Unit unit, Game game, Debug debug) {
		Unit ally = null;
		Unit enemy = null;
		for (Unit u: game.getUnits ()) {
			if (u.getPlayerId () == unit.getPlayerId () && u.getId () != unit.getId ()) {
				ally = u;
			} else if (u.getPlayerId () != unit.getPlayerId ()) {
				enemy = u;
			}
		}

		// uncomment to fix bug lol
		// action = new UnitAction();
		if (ally != null && unit.getId () < ally.getId ()) {
			action.setAim (new Vec2Double (-40, 0));
			action.setShoot (true);
		} else {
			action.setAim (new Vec2Double (40, 0));
			action.setShoot (false);
		}
		
		action.setVelocity (enemy.getPosition ().getX () - unit.getPosition ().getX ());
		action.setJump (enemy.getPosition ().getY () > unit.getPosition ().getY ());
		action.setJumpDown (false);
		action.setReload (false);
		action.setSwapWeapon(false);
		action.setPlantMine(false);
		return action;
	}
}

from raic-2019.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.