This project will require you to write at least one typical Java class (BasicSoldier ), which defines the characteristics and behavior of a soldier. We hope you will also be motivated to think creatively about some ideas related to the field of Artificial Intelligence as you try to develop (just for fun) some additional classes representing soldiers who fight differently and perhaps more successfully. If you choose to write additional soldier classes, you may name them anything you wish, just be sure to submit at least one class called BasicSoldier for grading.
We have developed a framework in which two armies (red and blue) will engage in battle. Below is a screenshot of a typical battle on a small battlefield:
Each army can be selected from various classes of soldiers that are available. There are three built-in soldier classes: Easy,Medium, and Smart. You will write at least one of your own, called BasicSoldier, and you may choose to write others just for fun if you'd like to experiment with different strategies. You can have classes you write fight against each other, or against any of the built-in classes. Do you think you can design soldier classes that are smart enough to beat the built-in AI's? You could win a prize if you develop a class of fighters who can routinely defeat in-built Smart soldiers (see the contest details at the bottom of the page.)
The battles will take place in a BattleField, which is a rectangular grid. Each location in the grid could contain a red soldier, a blue soldier, an obstacle, or nothing at all. Each soldier will have access to a grid variable, which is a reference to the BattleField he is fighting in. When the soldier is deciding on his current action, he can query the battlefield for information about his surroundings. A typical query to the battlefield would be something like "tell me what is in row 2, column 3". The battlefield will respond with a code representing either "red soldier", "blue soldier", "obstacle", "nothing", or "you asked me about a location that is out of bounds".
More details about how a soldier must interact with the battlefield will follow when we describe the instance methods that you will be implementing. Also, please see the Javadoc for the BattleField class.
We have started you with an empty shell for this class. Look in the package called fighters and you will find it. When complete, your BasicSoldier class must contain the following public members.
final static constants
The four constants below represent the relative fighting attributes of all soldiers of this class. These attributes dictate what happens when a soldier of this class attacks someone or is attacked by someone. The intricacies of how these constants are interpreted internally will remain our secret -- you will have to experiment to see what combinations work well. The numerical values listed below are just an example -- You may assign these four attributes any values you want (between 1 and 97), but they must add up to 100 total . These variables are static because all soldiers in the class share the same attributes. They are final because they never change while the program runs.
Each soldier has his own copy of these variables. All of these variables will be initialized in the constructor for the class. You may add other instance variables, if you choose to.
You must implement a constructor with the prototype below. The constructor will be called by the framework to initialize your soldiers at the beginning of a battle. The constructor will assign the four parameters to the corresponding instance variables. It must also set the health variable equal to the value INITIAL_HEALTH . (You may have your constructor do additional things as well, if you wish.)
public BasicSoldier(BattleField gridIn, int teamIn, int rowIn, int colIn)
Instance Methods
You'll find that while implementing these methods, the current soldier will need to interact with the battlefield. In particular, the soldier will need to ask the battlefield about his surroundings using the battlefield's get method. Please see the Javadoc for the BattleField class for more information about using the battlefield. You may add instance methods of your own, if you choose to.
To simulate a battle, run the main method in the class called Driver (it's in the package called GUI). By default, this will initiate a battle between two built-in soldier classes, Easy and Medium.
You can modify the game parameters at the top of the GUI and then press "Begin New Game" to start a completely new battle. If you would like to replay the same battle that is currently being fought, just press the "Replay This Battle" button. There is a slider at the bottom which allows you to control the speed of the simulation.
The Red Team and Blue Team boxes can be used to choose different classes for the battle. The built-in classes are Easy, Medium, and Smart. If you'd like to see your own soldiers fighting, then just enter the name of one of your classes (e.g. BasicSoldier) into one or both of these boxes. (You can have both teams use the same class if you want -- that works fine).
If you would like to change the default start-up parameters for the game (for example, you would like it to always start off with a 20 by 20 battlefield where the blue team is BasicSoldier and the red team is Smart) you may modify the Driver class in the obvious way to suit your needs.
You are only required to implement one class, BasicSoldier. We hope that some of you will enjoy this project and will have fun creating some additional fighting classes in a quest to produce the ultimate soldiers! See the contest rules, below, for more motivation. If you choose to write some additional classes, you may name them anything you wish. Be sure to put your fighting classes in the package called fighters so that the framework can find them. Any additional fighting classes you write must contain the following elements, which were described above for the BasicSoldier:
(This section is optional reading, and is only important if you want the "Replay This Battle" button in the GUI to function correctly for battles involving classes you have written.) It is likely that you will want your soldiers to sometimes behave randomly. Rather than using one of the usual random number generators, please use the one we invented. It is called Random131. If you use this generator, the very same "random" numbers will be reproduced after you press "Replay This Battle", so that the exact same battle can be studied repeatedly.
The Random131 class has a static method called getRandomInteger that you can call whenever you need a random integer in a range that you specify. For example, if you would like to obtain a random number from 0 to 9, then you could use this:
int randomValue = Random131.getRandomInteger(10);
// randomValue will be assigned a random integer from 0 to 9
After the project due date has passed, it might be fun to have your soldiers do battle against a classmate's soldiers to see who wins! Or after the due date, you may choose to work with other students as a team to try to win the contest. But... be sure that all work you do before the due date (including the 24-hour late period) is done individually, without collaboration! You may not share code before the due date under any circumstances.
So... you think your soldiers are pretty smart, huh? If you manage to develop a class that will beat the built-in Smart AI most of the time on a big battlefield with lots of soldiers, then send an email to Nayeem. Note: In order to qualify, your AI must not be appreciably slower than mine. If I find that your AI is better than my Smart AI, you will win a prize. What kind of prize? I don't know yet -- maybe a T-shirt. Or a free lunch. You tell me. We will certainly post the name(s) of anyone who wins the contest on the class webpages so that you can bask in your glory!
Submission
Submit your project from Eclipse by right-clicking the project folder and selecting "submit". You may submit as many times as you want -- we we only grade the submission that scores the highest on the automated tests. After you have submitted your project, you should visit the submit server. There you can obtain limited feedback about how well your project is performing. The number of times you can run our tests on your project (before the due date) is limited. The earlier you begin working on the project, the more opportunities you will have to see how your project performs on our tests before the due date!
Grading90% of your grade on this project will be from the automated tests on the submit server (both public tests and release tests). 10% of your grade on the project will be based on using correct "style" for Java programming.