Re: How extending from Robot works
etoipi <[email protected]>
| Newsgroups | gmane.comp.java.robocode |
|---|---|
| Message-ID | <[email protected]> |
Thanks very much! That clear's up an awful lot for me. On Friday, 28 March 2014 21:37:45 UTC, fnl wrote: > > Okay, now I think I understand your question. > > Well, the event handlers like ``onScannedRobot()``, ``onHitByBullet()``, > ``onHitWall()`` etc. are all called at the end of the turn where they > occur. So if your robot hits a wall, scans two robots, and get hit by 3 > bullets in the same turn, you receive 1 call to ``onHitWall()``, 2 calls to > ``onScannedRobot()``, and 3 calls to ``onHitByBullet()`` in the end of that > particular turn. :-) > But notice, that you should NOT call any method like e.g. > ``ahead(distance)`` in any event handler as this will force your robot to > execute and proceed to the next turn, meaning that the other pending event > handlers is first called in the next turn. In worst case, they are never > called as the robot continue to take action (execute) in an event handler. > Hence, make sure your robot just gathers information in the event > handlers, and only call robot commands in your ``run()`` method. :-) > > Cheers, > - Flemming > > Den torsdag den 27. marts 2014 23.52.53 UTC+1 skrev etoipi: >> >> Thanks for your continued help. >> >> The last part of my question is can multiple events be called in one >> tick? i.e can I have code in both, say scanning an enemy and being hit by a >> bullet run at the same time, or would the order still go -> Event 1 on my >> bot, enemy bot turn, event 2 on my bot, enemy bot turn etc. >> >> Thanks. >> >> On Thursday, 27 March 2014 20:55:55 UTC, fnl wrote: >>> >>> Hi again, >>> >>> You got it right. Your robot will need to figure out which command that >>> is the most important to execute next. :-) >>> >>> Regarding your last question, I don't follow it. Can you explain it in >>> more detail? >>> The onScannedRobot(ScannedRobotEvent) is "just" an event handler that >>> tells your robot whenever another robot enters your robots "scan arc". >>> The event handler should just do minor stuff like recording/updating >>> data for the scanned robot, and/or do minor mathematical operations like >>> calculating the x and y coordinate or the robot etc. >>> The real work should go on within the while(true) loop in your run() >>> method. >>> >>> Cheers, >>> - Flemming >>> >>> Den onsdag den 26. marts 2014 10.44.39 UTC+1 skrev etoipi: >>>> >>>> Thanks very much for the reply. So, as I'm extending from Robot, if I'm >>>> doing same targetting based on turning the radar, gun and then firing, >>>> between my turnRadar(), turnGun() and fire() the opposition robot also gets >>>> a 'turn' where they'll perform what ever action is next. So, in my turning >>>> of the gun and firing I'd not only have to take care of the time the bullet >>>> takes to travel and future position of the enemy, but also in my case any >>>> action(s) he may take between the turn when I've scanned him, and the >>>> (potentially) few turns until I actually call fire(). One final thing, if >>>> I'm in the onScannedRobot function, does it just work it's way through this >>>> loop, including the alternating turns, before any other events are called, >>>> or can it be working through multiple functions, based on any events that >>>> happen? >>>> >>>> Thanks. >>>> >>>> On Tuesday, 25 March 2014 20:12:28 UTC, fnl wrote: >>>>> >>>>> Set instructions for an AdvancedRobot can basically be split into >>>>> commands for: 1) body, 2) turret/cannon, 3) radar, 4) fire. Here you can >>>>> call a set instruction for all 4 parts and execute these in one go (same >>>>> turn). >>>>> >>>>> An instruction like turnLeft(angle) is the same as setTurnLeft(angle) >>>>> + execute(). This means that as soon as the set instruction is called for >>>>> turnLeft(angle) this instruction is executed using one turn. In the next >>>>> turn another command like fire() or ahead() can be called and executed and >>>>> so on. So one set instruction is executed per turn. >>>>> >>>>> Please note that executing a command like setAhead(distance) and >>>>> setTurnLeft(angle) to start executing those commands till they meet their >>>>> completion condition. For example, setAhead(distance) means the robot will >>>>> stop moving ahead when getDistanceRemaining() reaches 0 (with 0.00001 >>>>> precision) or setAhead(distance) or setBack(distance) is called again. The >>>>> same thing counts for setTurnLeft(angle) which stops turning until >>>>> getTurnRemaining() reaches 0 or another command "resets" this instruction, >>>>> so the robot should turn in another direction. >>>>> >>>>> When it comes to event, the event handlers are called in the very end >>>>> of each turn. >>>>> >>>>> I hope this helps, otherwise I will be happy explaining more in >>>>> detail. :-) >>>>> >>>>> Cheers, >>>>> - Flemming >>>>> >>>>> Den tirsdag den 25. marts 2014 13.26.33 UTC+1 skrev etoipi: >>>>>> >>>>>> Lot's of example I find on the internet involved a robot that is >>>>>> extended from AdvancedRobot, where set's are used, and all actions are >>>>>> executed in one go. I'm building only from the Robot class, and was >>>>>> wandering if someone could help me understand exactly how this works behind >>>>>> the scenes. I may only call actions that happen instantly. For each action >>>>>> I take, does a tick pass before my next action can complete / the other >>>>>> robot can carry something out, or does my whole scannedRobot loop run? I >>>>>> was just wandering if someone could help with the finer points of this. >>>>>> Similarly, could I feign the action of execute if I were to put all my >>>>>> turns / moves at the very end of a block? >>>>>> >>>>> -- You received this message because you are subscribed to the Google Groups "robocode" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.