Course web page: Introduction to Computer Science for non-majors II James Tam Return to the course web page

## CPSC 219: Full Assignment 1

Due Monday Feb 6 at 4 PM

### New concepts to be applied for this assignment

• Creating an Object-Oriented program

### Creating a fight simulator

Write a simple a fight simulator (in case you have never seen a "2-man" kombat sequence here is a video). Your program will have two opponents: an attacker (that only launches attacks) and a defender (that can only defend against the attacks). There's three types of attacks categorized by height: high, medium and low. Similarily three types of defences: high, medium and low. If the heights of the attack and defence match then the attack is blocked. Otherwise the attack is counted as a 'hit'. The simulation runs a fixed number of attack-defence sequences (from 1 - 100 'rounds' of attacks and defences). The user can determine the number of rounds at runtime. If a value outside the range is entered then the default number of rounds (ten) will be executed (no re-querying needed). For stylistic reasons you should define class constants  (i.e.., final static int HIGH = 1;) whenever unchanging attributes are needed such  as these but because this is your first Object-Oriented program this requirement is waived for this assignment).

Also when the program is first run the user can determine the proportion of attacks that originate at the three different heights (e.g., high = 50%, medium = 30%, low = 20%). These three proportions must sum to 100% otherwise the program will use the defaults (equal probability of each type of attack although the proportions in this case don't have to sum to 100%).

The defender will be entirely controlled by the computer. The 'unskilled' defender has an equal chance of employing one of the three types of defences. A program that implements an 'intelligent' defender will analyze the pattern of attacks and adjust the probability of each type of defence being employed over time. (For example if the attacker always throws high attacks then the defender will eventually extrapolate the pattern and use high defences more frequently). It is up to you to decide how many rounds are needed before the defender begins to adjust to  the pattern of attacks. And the value determining the adjustment period can be hard-coded (fixed) into the program (no user input needed at run-time). The minimum number of rounds needed to analyze the pattern should be one (with zero attacks thrown there is no pattern to analyze). Prior to analyzing and determining the pattern of attacks the defender should have an equal probability of employing each type of defence.

Exactly what constitutes 'intelligent' for this assignment? Because this isn't a formal class in Artificial Intelligence the definition is fairly broad: as long the program demonstrates the ability to adapt to the pattern of attackers and the marker can clearly see the pattern as the program executes (the display of statistics each round will be very useful for communicating this). If for instance the attacker throws only medium attacks, after the learning period is over the defender should eventually employ only medium height defences (or at least have an extremely high probability of employing this type of defence). You can either come up with your own algorithm for the defender or you can freely research algorithms online. In the latter case make sure you clearly cite all your sources. (Failing to list a source may be regarded as academic misconduct).

Note: it is important that youroutput statements clearly demonstrate to your marker that features are working (e.g., that the attacker and defender generated something ( an attack/defence) and how that combination produced a result). Consequently your output must not only present the needed information but must also be reasonably formatted. The program output is even more crucial when you have implemented an intelligent defender. The marker must be able to see the effects of the defender adapting to the pattern of attacks otherwise you may not get credit for your work. He/she won't have the time to trace through your program.

The program will tally a number of statistics and display them during each round *and* at the end of the simulation.  Here is the minimum amount of information to display:

Statistics displayed each round: the round number, the type of attack and defence chosen, the result of the attack-defence combination (hit or block).

Statistics displayed when the program ends:  the total number of successful attacks and blocks and the probabilities of each type of attack-defence at the end (the values for the attacker won't change but an intelligent defender's proportions should go from equal values to more closely reflect the proportions of the attacker).

In the assignment directory you can find a [text file] that are records of the output of the program. As you will see my 'intelligent' defender is not particularly 'intelligent' but it's sufficient for this class. Note however how the defender adapts after round 20, quite dramatically in this case because the probability of attacks is 100% for one of the 'heights'.

Program design [Click here for overview]: the program will consist of 3 Java source code files (Attacker, Defender, Manager). Each class definition must be in it's own file and that file name must match the class name.

• The 'Manager' is not just the start or the 'driver' of the program (contains the 'main' method) but as the name implies it also acts as an intermediary between the other two classes (e.g., communicates to the defender the type of attack generated by the attacker). (The other two classes can send messages/invoke methods to each other if necessary).

• The 'Attacker' will be responsible for generating attacks so it should track all information associated with attacking (e.g., numbers of each attack type generated).

• Likewise the 'Defender' will receive the attack generated by the attacker, generate a defence and determine the result of the attack-defence combination. Also the defender should track information associated with defence (e.g., the numbers of each type of defence used).  Since the information for the attacks and defences must be tracked by this class the methods for displaying the round-by-round report and the end of simulation report should be displayed here.

### Marking

As well as being marked on whether "your program works" you will also be marked on non-functional requirements such as style and documentation. Consequently each full assignment will include a separate [marking checklist]

Points to keep in mind:

1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. The latest versions of the files that you have submitted in D2L as of the due date is what will be marked.
2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that you submit your assignment with enough time before it comes due for you to do a check).
4. Identifying information: All assignments should include contact information (full name and student ID number) at the very top of your program in the class where the 'main()' method resides.
5. Collaboration: Assignments must reflect individual work; group work is not allowed in this class nor can you copy the work of others.  For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
6. Execution: programs must run on the computer science network running Java 8.x. If you write you code in the lab and work remotely using a remote login program such as Putty or SSH then should be using the correct version. If you choose to install Java on your own computer, then it is your responsibility to ensure that your program will run properly on the CPSC computers. It's not recommended that you use an IDE for writing your programs but if you use one then make sure that you submit your program in the form of text ".java" file or files. If you only submit your byte code files (e.g. Driver.class) then you will not be awarded any credit.
7. Use of pre-created Python libraries: unless otherwise told you are to write the code yourself and not use any pre-created functions from the Python libraries. For this assignment the usual acceptable functions include: System.out.print(), System.out.println(), the methods of the Console class and for some assignments the methods of the Random class.
8. Style conventions, programming decomposition: the marking points from the previous assignment also apply to this assignment. The one blanket exception is the use of a static debugging flag (or flags) if you choose to implement multiple flags.

D2L configuration:

• Multiple submissions are possible for each assignment: You can and should submit many times before the due date. D2L will simply overwrite previous submissions with newer ones.
• Important!  Multiple files can be submitted for each assignment. I am allowing you to submit multiple files for each assignment so you don't have to worry about archiving/compressing multiple files using a utility such as zip. However, this means that TAs will only mark the latest versions of each file submitted via D2L. Even if the version of a document that you want marked has been uploaded into D2L if it isn't the latest version then you will only get marks for the latest version. (It's unfair to have the TAs check versions or to remark assignments because marking is enough work as-is).

### Using pre-written Java code

You will need to use the built in code class Random. Beyond that (and common sense operators and functions such as those for input/output and mathematical operators), unless you told otherwise, you will need to write your own code and cannot use other pre-written Java classes or operators.