Robocode debugging skills

zhaozj2021-02-16  70

Robocode debugging skills

Friends who originally played Robocode may complain that Robocode is not good to edit, debug, in fact, although Robocode is very simple, it still gives us a lot of expansion features. As long as it is good at using, debug robocode is still very convenient.

One of the skills: Define your own Robots path to assume Your Robocode is installed under x: / robocode-setup, then the default Robot code is stored in X: / Robocode-Setupextract / Robots, you can place robotics JAR Package (such as the motor source code downloaded from the Internet has already been packed in JAR package, directly throwing these JAR files in x: / robode-setupextract / robots can see them to show them), or build your own Package directory, store the code directly in * .java. For example: I created a FREEDEBUG directory under the robots directory, I wrote the robot * .java directly in X: / Robocode-setupextract / Robots / Freedebug, which is the way Robot default management Robot code. However, I will not do this - because I usually write robots with the Robocode combo editor. I usually use my IDE editor, compile, so I also put my own robot source in my Java project, such as: x: / sourcejava / robots, as long as the menu of the Robot main form Options- > Preferences-> Development Options Fill in X: / Sourcejava / Robots, Robocode can find my robot. If there are multiple robot paths, you can separately separately, such as x: / sourcejava / robots; x: / sourcejavadownload_robots.

Tips 2: Compiling the robot with your own editor If you want to compile the robot with your IDE, it is very simple, just add robodode.jar to the environment variable of the system's ClassPath. For example, my classpath is set to: classpath =.;% Java_home% / lib / Tools.jar; x: x: x: x: x: /robocode-setupextRACTRACTRACTRACTROBOCODE.JAR This can be compiled in its own IDE. The debug robot code. If you don't understand how ClassPath is set, please refer to the "Setup of the Java environment variable under Windows". If you are a java newbie, I don't know which IDE chooses to write robots, please refer to the "TEXTPAD to build your Java IDE"

Tips 3: Use custom class libraries I think you must find it, insert system.out.println () in the robot source code; statement can output the running variable to an applet window, you will definitely feel I often write system.out.println (); to output variables very tired, my approach (* Note 1) Yes, define a class Class P, used to simplify the output, the following is a simplified version of my class P: / /:freedebug :tools :p.java package freedebug.tool;

Public class p {public static void rint (string s) {system.out.print (s);} public static void rintln (String s) {system.out.println (s);}}: ~ This is in mine P.RINTLN () can be used in the robot code instead of system.out.println (), is it easy? If you want to write a lot of robots, the best way is not to copy the Class P code into each of your robot, but do it on a java file, in a java file, in the freedebug directory as you do it. Create a Tools directory, put the P.Java in it, the location I put is as follows: x: /sourcejava/robots/freedebug/tools/p.java This can be used in my robot code can via Import Freedebug.Tools. * To reference my tool class. Of course, this is just an example, you can promote it, build a complete set of your own tool class, very convenient, 嘿嘿. I have been sneaking for an hour, I went to work, hey, chat again!

-------------------- Note 1: This method is not my original, and Bruce Eckel is in the "Think in Java II", which is only reference only.

Freedebug on 2003-12-19

转载请注明原文地址:https://www.9cbs.com/read-17230.html

New Post(0)