MechManiaII tutorial
This will get you started with the MechManiaII API. It will take you
through the making of a simple ship that goes around, fires on other
ships, picks up flags and drops them off at the home base. You will
see that designing a ship is pretty easy - the hard part is figuring
out a good strategy.
Team Name
The most important thing (or maybe not) to do is to change the name of
your team. Edit Team.C and change the Name() method.
Intialization
The tutorial uses drand48 for generating random numbers. That class
of functions is "more random" than the standard rand() function. Use
srand48(time(NULL)) to initialize the random number seed based on the
time. Since this should only be done once, and at the beginning of
the game, it should be placed in Ship::GameBegin.
void team::gamebegin(word players)
{
srand48(time(NULL));
}
There are two ways we suggest you control the ship, either by writing
a global "AI" which replaces Team::Turn (a virtual method derived from
TeamSuper::Turn, so you have to add the method in Team.C) or by
attaching an AI to each ship, which then controls the ship. The
following examples use the latter method.
To set things up for that, do the following: edit Team.h and to the
end of the file add
class SimpleAI : public AI {
public:
virtual void Turn(int);
};
and at the end of Team.C, add the following code for the
sleeper
void SimpleAI::Turn(int)
{
}
Make and run the code. (See the programmer's API for info on how to
do this.)
The traveler
Dull, wasn't it?
Here's one
that moves about it bit. It picks one of
the neighboring stars at random, then jumps to it. Try it out
with a server. Isn't everything pretty?
The fighter
The previous example put all the power in the engines, and left the
ship defenseless. If there was no war in the universe, that would
work, but the enemy is a wonton cut-throat pirate likely to bring a
magnet near your hard disk, so you need to fight back as well as move
around.
Here's a short piece of code that does just
that. It implements the following strategy: If there is an enemy ship
at this star, split 1/3 of the power between engines, weapons and
shields. Find the lowest numbered enemy ship and fire at it until
there are no enemy ships left. Once they are destroyed, jump at
random.
Mover
At the end of the game, you get points for having a flag on a ship,
and more points for having the flag at your home base. Lets worry
about the former for now. After you've destroyed the enemy at a star,
if there is a flag, and you are not already carrying one, pick it up.
The other complication is in power allocation. You must have
transport power to hold the flag, so the configure code in the combat
and transport sections must be altered.
Here's the modified code.
Homeboy
You get more points by taking the flag to your home base. Since there
may be more flags than ships (or your ships might get destroyed), you
might want to drop them off at home then go and collect more. This
last example modifies the flag pick-up line
so it doesn't pick up flags at your home star, and if it is your home
star, drops a flag if it is carrying one.
Final Comments
There are a lot of things to consider just tweaking this code. When
fighting around a star, is it better to drop the flag before engaging
the enemy? Should the energy distribution be split in thirds?
Should I go directly home after picking up the flag? Should I leave
forces at home to protect things? What about escorts? What do I do
if I find the (putative) enemy home base with lots of flags? We
thought of a dozen or so strategies, so you might want to implement a
few to compare them to each other.
Also, there is no real reason SimpleAI had to be part of Team.C and
Team.h. It would be easier for you, and shorter for your recompiles,
if you put your new classes in new files. Add the new .C file names
to the Makefile on the EXTRA_FILES line.
Good luck, and have fun!
Last modified: Sat Oct 12 01:53:34 CDT