Robocode debugging skills

Source: Internet
Author: User
Tags java format
Robocode debugging skills

Friends who initially played robocode may complain that robocode is not easy to edit and Debug. In fact, although robocode is very simple, it still provides us with a lot of extended functions. As long as you are good at using it, debugging robocode is very convenient.

Tip: define your own robots path
Assuming that your robocode is installed in X:/robocode-setup, the default robot code is stored in X:/robocode-setupextract/robots, the jar package of robot code can be placed in it (for example, most of the robot source code downloaded from the Internet has been packaged into a jar package, and these jar files are directly dropped to X: /robocode-setupextract/robots directory to see their performances), you can also create your own package directory, directly put the code *. java format. For example, I create a freedebug directory under the robots directory and I write my own robot *. java is directly stored in X:/robocode-setupextract/robots/freedebug, which is the default robot code management method. However, I generally won't do this-because I generally don't need to write robots in the robocode editor. I usually use my ide for editing and compiling. Therefore, I also put my robot source code in the directory of my java project, such as X:/sourcejava/robots, enter X:/sourcejava/robots in the menu options> preferences> development options of the main robot form to find my robot. Multiple Robot paths can be separated by semicolons, such as X:/sourcejava/robots; X:/sourcejavadownload_robots.

Tip 2: Compile the robot with your own editor
To compile a robot with your own IDE, you just need to add robocode. jar to the environment variable of the classpath of the system. For example, my classpath is set as follows:
Classpath =.; % java_home %/lib/tools. jar; X:/robocode-setupextract/robocode. Jar
In this way, you can compile and debug the robot code in your ide.
If you do not understand how to set classpath, refer to setting up the Java environment variables in windows. If you are a beginner in Java and do not know which ide to use to compile robots, refer to compile "Build your Java ide with textpad".

Tip 3: Use a custom class library
I think you must have discovered that the system is inserted into the robot source code. out. println (); the statement can output the runtime variables to an applet window. You will surely feel that the system is frequently written. out. println (); to output variables is very tired. My practice (* Note 1) is to define a class P to simplify the output, below is a simplified version of my class P:
//: Freedebug: Tools: P. Java
Package freedebug. tools;

Public class P {
Public static void RINT (string s ){
System. Out. Print (s );
}
Public static void rintln (string s ){
System. Out. println (s );
}
}

////:~
In this way, in my robot code, P. rintln () can be used to replace system. Out. println (). Is it very convenient? If you want to write a lot of robots, the best way is not to copy the class P code to each of your robot source code, but to put it in a Java file as I did above, create a tools directory under the freedebug directory and set. java is put in it, and my position is as follows:
X:/sourcejava/robots/freedebug/tools/P. Java
In this way, you can use import freedebug. Tools. *; in my robot code to reference my tool class. Of course this is just an example. You can promote it and build a complete set of tool libraries, which is very convenient.

I 've been writing for an hour at work, so I went to work. Hey, I'll talk about it next time!

--------------------
Note 1: This method is not original. It is described by Bruce Eckel in think in Java II. It is only referenced here.

Freedebug on

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.