Introduction
C‑Robots consists of a Pseudo-C language interpreter, a virtual machine, and a battlefield display. The C‑Robots interpreter accepts a limited (but useful) subset of the C language. C robot programs are assisted by hardware functions to locate opponents, start and stop movement mechanisms, fire the cannon, and more. Once the programs are interpreted and loaded into separate robots, the battle is observed. Moving robots, flying and exploding missiles, and some status information are displayed on the screen in real-time.
Credits
C‑Robots is inspired by the original 1985 version created by Tom Poindexter and brought to Italy thanks to the articles written by Corrado Giustozzi on MC‑Microcomputer, probably the best computer magazine ever published in Italy. Compared to the original version, this game does not use a compiler and a real virtual machine, but limits itself to interpreting the pseudo‑C language and executing each robot‑program in a dedicated thread, thus allowing execution parallelism. The graphics of the original version, which were necessarily exclusively textual, were created using Apple’s SpriteKit.
Game Parameters
Battlefield
The battlefield is a 1,000 by 1,000 meter square. A wall surrounds the perimeter, so that a robot running into the wall will incur damage. The lower left corner has the coordinates x = 0, y = 0; the upper right corner has the coordinates x = 999, y = 999. The compass system is oriented so that due east (right) is 0 degrees, 90 is north, 180 is west, 270 is south. One degree below due east is 359.
Robot Offense
The main offensive weapons are the cannon and scanner. The cannon has a range of 700 meters. There are an unlimited number of missiles that can be fired, but a reloading factor limits the number of missiles in the air at any one time to two. The cannon is mounted on an independent turret, and therefore can fire in any direction, 0–359, regardless of robot heading.
The scanner is an optical device that can instantly scan any chosen heading, 0–359. The scanner has a maximum resolution of ±10 degrees. This enables the robot to quickly scan the field at a low resolution, then use maximum resolution to pinpoint an opponent.
Robot Defense
The only defense available are the motor drive and status registers. The motor can be engaged on any heading, 0–359, at speeds from 0–100 percent of power. There are acceleration and deceleration factors. A speed of 0 stops the motor. Turns can be negotiated at speeds of 50% and less, in any direction. The motor drive can be engaged anytime, and is necessary on offense when a target is beyond the 700‑meter cannon range.
Certain status registers provide feedback to the robot. The primary registers indicate the percent of damage and current x and y locations on the battlefield. Another register provides current drive speed.
Disabling Opponents
- 2% damage on collision into another robot or a wall (also disengages motor drive).
- 3% damage from a missile exploding within a 40 m radius.
- 5% damage from a missile exploding within a 20 m radius.
- 10% damage from a missile exploding within a 5 m radius.
Damage is cumulative and cannot be repaired. A robot at 99% damage performs as well as one with no damage.
Main Commands
drive(angle, speed): moves the robot.cannon(angle, distance): fires a projectile.scan(angle, resolution): returns –1 if recharging, 0 if no target, otherwise distance.atan(dy, dx): computes angle in degrees (like atan2).
Language Syntax
The CROBOTS interpreter accepts a limited subset of C. Missing features include floating‑point, pointers, arrays, structures, unions, preprocessor directives, and various control statements (switch, for, do…while, etc.). Supported constructs are if…else, while, and function calls. Recursion is not supported.
📋 Specifica BNF del linguaggio — apri la grammatica formale in una nuova scheda.
Comments: // and /* … */. Variables: int x;. Mathematical functions: sqrt(), sin(), cos(), atan(). Postfix/prefix ++ not supported.
Note: I
...else if () is NOT available, only ...else..
CRobots library of functions and commands
The intrinsics library provides machine-level control and some arithmetic functions. These functions do not consume any program code or data stack space, except for the three words for the call/return sequences. No explicit linking is required to use any intrinsic function.
print("string_format", args...)
As in the C language, there is a print() function that allows you to output values to the console and is generally used during debugging. The available format specifier is %d for int variables (the only type allowed in C_Robot).
For example, print("The value is: %d", 10) prints to the console: “The value is: 10”
loc_x()
loc_y()
The loc_x() function returns the robot's current x axis location. loc_x() takes no arguments, and returns 0-999. The loc_y() function is similar to loc_x(), but returns the current y axis position. Examples: drive (180,50); /* start heading for west wall */ while (loc_x() > 20) { }. /* do nothing until we are close */ drive (180,0); /* stop drive */
scan (degree,resolution)
The scan() function invokes the robot's scanner, at a specified degree and resolution. scan() returns -1 if the scanner is reloading, 0 if no robots are within the scan range or a positive integer representing the range to the closest robot. Degree should be within the range 0-359, otherwise degree is forced into 0-359 by a modulo 360 operation, and made positive if necessary. Resolution controls the scanner's sensing resolution, up to +/- 10 degrees.
cannon (degree,range)
The cannon() function fires a missile heading a specified range and direction. cannon() returns 1 (true) if a missile was fired, or 0 (false) if the cannon is reloading. Degree is forced into the range 0-359 as in scan(). Range can be 0-700, with greater ranges truncated to 700. Examples: degree = 45; /* set a direction to test */ if ((range=scan(degree,2)) > 0) /* see if a target is there */ cannon(degree,range); /* fire a missile */
drive (degree,speed)
The drive() function activates the robot's drive mechanism, on a specified heading and speed. Degree is forced into the range 0-359 as in scan(). Speed is expressed as a percent, with 100 as maximum. A speed of 0 disengages the drive. Changes in direction can be negotiated at speeds of less than 50 percent. Examples: drive(0,100); /* head due east, at maximum speed */ drive(90,0); /* stop motion */
damage()
The damage() function returns the current amount of damage incurred. damage() takes no arguments, and returns the percent of damage, 0-99. (100 percent damage means the robot is completely disabled, thus no longer running!) Examples: d = damage(); /* save current state */ ; ; ; /* other instructions */ if (d != damage()) /* compare current state to prior state */ { drive(90,100); /* robot has been hit, start moving */ d = damage(); /* get current damage again */ }
speed()
The speed() function returns the current speed of the robot. speed() takes no arguments, and returns the percent of speed, 0-100. Note that speed() may not always be the same as the last drive(), because of acceleration and deceleration. Examples: drive(270,100); /* start drive, due south */ ; ; ; /* other instructions */ if (speed() == 0) /* check current speed */ { drive(90,20); /* ran into the south wall, or another robot */ }
rand(limit)
The rand() function returns a random number between 0 and limit, up to 32767. Examples: degree = rand(360); /* pick a random starting point */ range = scan(degree,0); /* and scan */
sin (degree)
cos (degree)
tan (degree)
atan (ratio)
These functions provide trigonometric values. sin(), cos(), and tan(), take a degree argument, 0-359, and returns the trigonometric value times 100. The scaling is necessary since the CROBOT cpu is an integer only machine, and trig values are between 0.0 and 1.0. atan() takes a ratio argument that has been scaled up by 100, and returns a degree value, between -90 and +90. The resulting calculation should not be scaled to the actual value until the final operation, as not to lose accuracy.
Patrol the field, avoid walls, run away if hit, and shoot when you spot an opponent.
← Back