Robocode Learning Notes (III.)

Source: Internet
Author: User
-->
-->

Yesterday saw the basic knowledge of Robocode, himself wrote a bot, put on the battlefield on the lack of repeated war repeatedly defeated ... Sad ing.

Bot has a very limited understanding of the surrounding environment. It can know the distance, azimuth, direction, speed and energy level of other robots. However, it does not see the bullets. How can we effectively avoid each other's bullets?

Although the bot can not see the bullet, but the other side of the energy level is still able to scan. The other side will consume energy as long as the bullets are fired, and the energy consumed is between 0 and 3. Based on these clues, how can we find that other robots are firing at it for the "stupid" bot is a breeze? ^_^

When the bot detects the other side to launch the bullet information, move left or right one small step, hey, the bullets can not hit the ~ and most of the bot's aim is either directly to the target, or try to calculate the speed and direction of the bot position. If my bot doesn't move, both algorithms will be firing at the current location of the bot. hahaha, then my bot move again, not all can not hit. (is not quite a martial arts fiction in the master taste of static braking?) ^_^)

Here are some of the code and comments:

Double previousenergy = 100;  The initial state of each other energy is movementdirection = 1; moving direction int gundirection = 1; Gun Tube Direction

/** * When the opposing bot is detected, triggers the event * @param e */public void Onscannedrobot (Scannedrobotevent e) {//adjusts the angle between himself and the other side Setturnri Ght (e.getbearing () +90-30*movementdirection);

If the other person's energy loss a certain value, carry out evasive action double changeinenergy = Previousenergy-e.getenergy ();      if (changeinenergy>0 && changeinenergy<=3) {//Dodge! Movementdirection =-movementdirection;    And the last evasion direction opposite Setahead ((E.getdistance ()/4+25) *movementdirection);    ///point the gun tube to the other's current position gundirection =-gundirection; Setturngunright (99999*gundirection);

Shooting Fire (1);

Reset each other's energy Previousenergy = E.getenergy (); }

Is it simple? There are still problems with this technique. As soon as the bullet is fired, my bot moves, so it may eventually move back into the trajectory. It is better to move the bullets when they are expected to arrive.

I have a bolder assumption: Because now my bot hit rate is not high, if my bot has not opened fire, but to avoid the other side of the bullets, can not drag to the other side of the energy of 0?

-->
<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.