paint on robocode map?

View: New views
6 Messages — Rating Filter:   Alert me  

paint on robocode map?

by asdasddsa321 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everybody,
I'm implementing an anti-gravity movement, but I think it's not
working at best, so I want print my anti-gravity point on the map.
I have to grab the object Graphics and then paint without breaking any
robocode security rule.
There is a (simple) way to do that? Have anybody do that?
thank for your attention

p.s. I'm sorry for my poor English, I hope you have understand :-)


Re: paint on robocode map?

by Julian Kent :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

asdasddsa321 wrote:
> Hello everybody,
> I'm implementing an anti-gravity movement, but I think it's not
> working at best, so I want print my anti-gravity point on the map.
> I have to grab the object Graphics and then paint without breaking any
> robocode security rule.
> There is a (simple) way to do that? Have anybody do that?
> thank for your attention
>  
There is a event provided for this, onPaint. You can modify the
Graphics2D object which is given as a parameter. Look at the Robocode
API for more details.

However, many people have had better luck with Minimum Risk Movement.
What this does is generate a bunch of points around you, and then
decides which is the least dangerous to go to, depending on where
enemies are etc. This prevents you from getting stuck in a 'local minimum'.

> p.s. I'm sorry for my poor English, I hope you have understand :-)
>  

Your english is fine =)

Julian (AKA Skilgannon)

Re: paint on robocode map?

by asdasddsa321 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

solved:

1: enable the button "paint" on your robot console <<< always to do!

2: in your robot you can get the Grapics2D calling the method
"getGraphics()" of Robot class, and then paint with this.

2b: you can also use the method "onPaint(Graphics2D)" of the Robot class.




Re: paint on robocode map?

by flemmingnlarsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- In Robocode@..., "asdasddsa321" <asdasddsa321@...>
wrote:
>
> solved:
>
> 1: enable the button "paint" on your robot console <<< always to do!
>
> 2: in your robot you can get the Grapics2D calling the method
> "getGraphics()" of Robot class, and then paint with this.
>
> 2b: you can also use the method "onPaint(Graphics2D)" of the Robot
class.


Please notice that the new getGraphics() method is only available in
Robocode 1.6.1, which has been release as a Beta some days ago. :-)

- Flemming



Re: paint on robocode map?

by asdasddsa321 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- In Robocode@..., "flemmingnlarsen"
<flemming.n.larsen@...> wrote:
>
>
> Please notice that the new getGraphics() method is only available in
> Robocode 1.6.1, which has been release as a Beta some days ago. :-)
>
> - Flemming
>

so if I want to package my bot for export I have to comment the method
or the bot will crash on previously version, right?
thanks jkflying and flemmingnlarsen for your answer


Re: paint on robocode map?

by flemmingnlarsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

{snip]
> so if I want to package my bot for export I have to comment the method
> or the bot will crash on previously version, right?
> thanks jkflying and flemmingnlarsen for your answer

Yes, you cannot use the getGraphics() with older versions of Robocode,
and thus have to comment the method out, or do something like this:

final static boolean ENABLE_GRAPHICS = true;

...
public void onScannedRobot(ScannedRobotEvent e) {
  if (ENABLE_GRAPHICS) {
    getGraphics().setColor(Color.RED);
    ...
  }
}

.. and then set the flag to false before you package your robot. This
way you don't have to worry about all the places where you call
getGraphics() as long as you make the check against ENABLE_GRAPHICS
first. :-)

- Flemming