C++Robots is On-Line! (again) From: rrognlie@netcom.com (Richard Rognlie) Date: Mon, 24 Oct 1994 14:11:55 +0000 I think I've worked out the worst of the C++Robots problems from over the weekend, but for now, please use it gently... Here is the C++Robots Help file for those show are interested. NOTE the change in program and delete syntax has changed from prior versions Help For C++Robots ((c) 1994 Richard Rognlie) [1] Introduction Welcome to the network C++Robots server. C++Robots is an ongoing "King of the Hill" (KotH) tournament in which players use the C++ language to create a control program for a robot. Your program controls a robot whose mission is to seek out and destroy any other robots it finds. You submit your C++ control program to the C++Robots server for evaluation. Your program is compiled by the GNU C++ compiler and loaded into a robot. Your robot then fights each of the robots "on the hill", one at a time. Each match consists of 5 rounds. You get 3 points for winning a round, and 1 point for a draw. If your total score is better than any of the other robots currently on the hill, you have "made the hill", assuming the appropriate position, and bumping the lowest scoring robot from the hill. Robots have the ability to scan for opponents, fire a cannon, move, and determine current position and status. C++Robots is conceptually based on CROBOTS written for the IBM PC by Tom Pointdexter. [2] C++Robots Command Summary | standings | | info [ <program-name-1> ... <program-name-N> ] | C++Robots | program <program-name> <password> | | delete <program-name> <password> | Each command should be put in the subject of a mail message to the PBeM Server (pbmserv@netcom.com). Response time is usually very quick, and you should always get a response (unless something goes wrong) If pbmserv does not respond to a command, you can try the simple command "help" to see if the system is down or not. If pbmserv responds to "help" and you don't have a response from your other command, something may have gone wrong. Try again or ask rrognlie@netcom.com for help if problems persist. help This sends a list of ALL the commands in brief, including those for other games and projects that are run through the PBeM Server. help C++Robots This sends this file (the one you are reading) list C++Robots *or* C++Robots standings This gives a list of all programs on the hill along with their scores. C++Robots program <program-name> <password> Attempt to place a new program on the hill. The body of your mail message is assumed to contain the C++ code for a robot control program. C++Robots will expect your code to be bracketed by a 'BEGIN' and 'END' line. If no 'BEGIN' line is found, the start of the mail message will be used as the start of the program. If no 'END' line is found, and a line that looks like a .sig is found (e.g. '--'), that line will be used as the end. If no 'END' and no '--' are found, the end of the mail message will mark the end of the program. Any comments found between the start of the mail message and the start of the program will be assumed to be comments that will be returned to people who request the 'info' for that program. C++Robots info [ <program-name-1> ... <program-name-N> ] Get the "info" for each of the named programs. If no program names are specified, the info for all programs on the hill will be returned. C++Robots delete <program-name> <password> Delete one of your robots from the hill. *Why* you would want to do this is unclear, but the named robot will be removed from the hill when the next robot program is received. [3] C++Robots Parameters C++Robots combat takes place in walled a 1000m x 1000m arena. Ranges and locations are expressed in 1/10ths of meters. Speeds are expressed in 1/10ths of meters/second. All angles are expressed in degrees. 0 is due east, 90 due north, 180 due west and 270 due south. Angles outside [0..359] are adjusted to be within the correct range. The builtin scanner has a maximum arc of +/- 10 degrees. If you attempt to scan a wider arc than that, only +/- 10 degrees of arc are scanned. Maximum forward robot velocity is +10 meters/second. Maximum reverse robot velocity is -7.5 meters/second. Maximum robot acceleration is +/- 2 meters/second/second. Maximum turn speed is 5 meters/second. If you attempt to turn and your current speed is greater than 5 meters/second, you will slow down to 5 meters/second, make the turn and then accelerate to your desired speed. Maximum direction change is 15 degrees/second. Cannon shots travel at ~100 meters/second. With a blast radius of 40 meters. Maximum damage (8 points) is done within 5 meters. Medium damage (4 points) within 10 meters. Light damage (2 points) within 20 meters. And Minimum damage (1 point) within 40 meters. If a robot attempts to leave the arena (hits a wall), it will take speed/25 points of damage (rounded up). If two robots collide, they will each take (total relative speed/25) points of damage (rounded up). If a robot has a collision (wall or robot), its motor will disengage, and its speed will become 0. [4] C++Robots Restrictions Your program may only reference those functions you implement in your code, or those specified in <robots.h>. There is no <iostream.h>, etc. new and delete do not yet work. You may use classes and pointers to things, but no dynamic creation of objects (beyond that already done at the function/ block level). [5] C++Robots Function Library (#include <robots.h>) /* robots.h */ /* typedefs */ typedef int DEGREE; /* 0..359 (modulo 360) */ /* Control Functions */ int scan(DEGREE dir,int resolution); /* range to nearest target */ int cannon(DEGREE dir,int range); /* 1 if fired. 0 if still loading. */ int drive(DEGREE dir,int speed); /* 1 if direction changed. 0 if not. */ int damage(void); /* 0..99. 100 => dead robot */ int speed(void); /* 0..100 */ int loc_x(void); /* 0..9999 */ int loc_y(void); /* 0..9999 */ int time(void); /* Current time (in CPU cycles) */ /* Math Functions */ unsigned int rand(unsigned int limit); /* random number [ 0..limit-1 ] */ int sqrt(int number); double sin(DEGREE angle); double cos(DEGREE angle); double tan(DEGREE angle); DEGREE atan(double ratio); DEGREE atan2(int y,int x); /* Macros */ #define status(x,y,s,d,t) { \ (x) = loc_x(); \ (y) = loc_y(); \ (s) = speed(); \ (d) = damage(); \ (t) = time(); \ } #define abs(x) ((x)<0 ? -(x) : (x)) [6] Function Definitions scan(DEGREE dir, int resolution) Scans from dir-resolution to dir+resolution looking for targets. Returns range to nearest target in scan arc if one is found. Returns 0 if no target is found in scan arc. Maximum scan arc is +/- 10 degrees. Attempts to scan an arc greater than +/- 10 degrees will be truncated to +/- 10 degrees. cannon(DEGREE dir, int range) Fires a cannon volley in the direction/range specified. The slower your current speed, the more accurate your shot. Returns 0 if unable to fire at this time. Returns 1 if shot was successfully fired. Cannon shells travel at a volocity of ~100 meters/second. You may only have three volleys in the air at any time. If you are in the blast area of one of your own shots, you will take damage. drive(DEGREE dir,int speed) Change direction and speed. Maximum forward robot velocity is +10 meters/second. Maximum reverse robot velocity is -7.5 meters/second. Maximum robot acceleration is +/- 2 meters/second/second. Maximum turn speed is 5 meters/second. If you attempt to turn and your current speed is greater than 5 meters/second, you will slow down to 5 meters/second, make the turn and then accelerate to your desired speed. Maximum direction change is 15 degrees/second. [7] Example C++Robot // cylon.c // // Randomly move around the arena. While moving, scan back and forth up // to 45 degrees (like the cylon robots from "Battlestar Galactica". // If it sees something, it shoots it... #include "robots.h" Distance(int x1, int y1, int x2, int y2) { int dx = x1-x2; int dy = y1-y2; return sqrt(dx*dx + dy*dy); } Goto(int x, int y) { int dir = atan2(y-loc_y(),x-loc_x()); int dist = Distance(x,y,loc_x(),loc_y()); int t = time(); int sc = 0; int sd = 1; int range=0; drive(dir,100); while (speed() && time()-t < dist) { if (abs(sc) == 45) sd *= -1; sc += 3*sd; range = scan(dir+sc,5); if (range > 200 && range < 7000) cannon(dir+sc,range); int tdir = atan2(y-loc_y(),x-loc_x()); if (tdir != dir) drive(dir=tdir,100); } drive(dir,0); while (speed()) ; } main() { while (1) Goto(rand(9000)+500,rand(9000)+500); } -- /\/\/\ | Richard Rognlie / Sr. Computer Analyst / PRC Inc. / McLean, VA / \ \ \ | E-Mail: rrognlie@netcom.com *or* rognlie_richard@prc.com \ / / / | Phone: (Home) (703) 361-4764 (Office) (703) 556-2458 \/\/\/ | (Fax) (703) 556-1174 Referenced By Up