Assignment title: Information
Prepared for s4371809. Do not distribute.
The University of Queensland
School of Information Technology and Electrical Engineering
Semester Two, 2016
CSSE2310 / CSSE7231 - Assignment 4
Due: 11:10pm 28th October, 2016
Marks: 50
Weighting: 25% of your overall assignment mark (CSSE2310).
Version: 4.4
1 Introduction
In this assignment, you will write two C99 programs to carry out the "agent" simulation described below. The
first program (2310team) will be used to represent a team of agents in the simulation. The second program
(2310controller) will control the simulation environment. There will be no user input in this assignment.
Instead, the configuration for the simulation will be read from files.
Your programs must not create any files on disk not mentioned in this specification. Your programs must
not execute other programs. Your assignment submission must comply with the C style guide (version 2.0.3)
available on the course blackboard area. This is an individual assignment. You should feel free to discuss
aspects of C programming and the assignment specification with fellow students. You should not actively help
(or seek help from) other students with the actual coding of your assignment solution. It is cheating to look at
another student's code and it is cheating to allow your code to be seen or shared in printed or electronic form.
You should note that all submitted code may be subject to automated checks for plagiarism and collusion.
If we detect plagiarism or collusion, formal misconduct proceedings will be initiated against you. A likely
penalty for a first offence would be a mark of 0 for the assignment. Don't risk it! If you're having trouble,
seek help from a member of the teaching staff. Don't be tempted to copy another student's code. You should
read and understand the statements on student misconduct in the course profile and on the school web-site:
http://www.itee.uq.edu.au/itee-student-misconduct-including-plagiarism.
You are not to give this specification to anyone else.
2 Context
The simulation will involve teams battling each other through thå use of agents and their attacks.
A team will have four agents which will battle against the four agents of an opposing team.An agent has a
type and a set of attacks it can use.Each attack, which also has a type, will have a different level of effectiveness
(high, normal or low) against an opponent agent, depending on the types of the both the attack and the
opponent. Agents will take damage from an attack based on its effectiveness.Once an agent has lost 10 health,
it is eliminated and the next agent in the team will take its place in the battle..The battle is over once all agents
in one team have been eliminated.
Teams can also participate in a larger simulation with multiple teams, through a controller. The controller
will wait for a number of teams to join, then play out one or more rounds. In each round, a team will battle all
the other teams in its zone, then report back to the contrîller. After all of the battles in a round are complete,
teams will move to new zones to battle the teams there. This continues until all of the rounds are complete.
3 Team
3.1 Invocation / Modes
The 2310team program will have three modes of operation.The first mode ("simulation") will connect to a
controller process to be part of a larger simulation.The second("wait") and third("challenge") forms are used
for a single battle between two teams (i.e. there is no controller involved).In this case the description of the
battle will be printed by both teams and then they will both exit.
3.1.1 Simulation
Usage: 2310team controllerport teamfile
This mode will connect the team to a 2310controller process so it can be part of a simulation..As soon as
the team connects, it will receive the sinister information from the contrîller. After this, it will load its team
and start waiting on an OS assigned port for challenges from other teams. The team then lets the controller
know that it would like to be involved in the simulation by sending an iwannaplay message.
Following this setup, the team will follow the sequence of operations outlined in Section 4.2.
356983-29492-32236081Prepared for s4371809. Do not distribute.
3.1.2 Wait
Usage: 2310team wait teamfile sinisterfile
The wait process will listen on an OS chosen port for a challenge team. Upon starting, the process will
print out the port it is listening on. For example:
57829
After a challenge team connects to the port, both teams will engage in a battle, followed by the narrative
being printed to stdout.
3.1.3 Challenge
Usage: 2310team challenge teamfile sinisterfile targetport
The challenge team will connect to the wait team on the specified target port. A battle will then play out
between the two teams, followed by the narrative being printed to stdout.
3.2 Sequence
The two teams will start by setting up ready for a battle:
1. Challengers send team name using fightmeirl
2. Waiting team responds using haveatyou
3. Challengers select first agent and notify the waiting team
4. Waiting team responds with their first agent
Once the setup is complete, the battle can commence. The challengers will attack first. The battle will
consist of attacks made in the following order:
1. Team 1 attacks using its current agent
2. Team 2 takes damage from the attack
3. Team 2 attacks using its current agent
4. Team 1 takes damage from the attack
5. Repeat, until all agents of one team are eliminated
Each agent in a team starts with 10 points of health.An attack will remove a number of points of health
from the targeted agent, as indicated in Table 1.When a team's current agent is eliminated, it is replaced by
the next agent and the opposition is sent an iselectyou message.
Effectiveness Points lost
High 3
Normal 2
Low 1
Table 1: Damage taken from attacks
When all agents of one team have been eliminated, the battle is over.Both teams will then print out a
narrative for the battle, in the following format:
otherteam has a difference of opinion
challengeteam chooses agent
waitteam chooses agent
agent uses attack: result string
agent uses attack: result string
...
agent uses attack: result string - agent was eliminated.
...
Team teamname was eliminated.
Note:
3356983-29492-32236082Prepared for s4371809. Do not distribute.
• In challenge and wait modes, only the messages sent from Team to Team are used. See Section 5 for
the message formats.
• The narrative will include the details of attacks made and agents selected by both teams.
• Both sides detect the loss of the other by a read failure. Write calls could also fail, but your program
should ignore these failures and wait for the associated read failure. Such write failures must not cause
your program to crash.
3.3 Exit Statuses
All messages are to be printed to stderr..
Condition Exit Message
Normal exit due to game over 0
Wrong number of arguments 1 Usage: 2310team controllerport teamfile
or: 2310team wait teamfile sinisterfile
or: 2310team challenge teamfile sinisterfile targetport
Unable to open sinister file for
reading
2 Unable to access sinister file
Contents of sinister file are invalid
3 Error reading sinister file
Unable to open team file for
reading
4 Unable to access team file
Contents of team file are invalid 5 Error reading team file
Port number is invalid 6 Invalid port number
Cannot open a connection to the
controller
7 Unable to connect to controller
Cannot open a connection to the
waiting team (ONLY used during challenge mode)
8 Unable to connect to team
Controller disconnected
early (NOT used during
wait/challenge mode)
9 Unexpected loss of controller
Other team disconnected
early (ONLY used during
wait/challenge mode)
10 Unexpected loss of team
Problem encountered while parsing message, etc
19 Protocol error
System error (eg. malloc failure) 20 System error
Table 2: Exit statuses for team
4 Controller
4.1 Invocation
The parameters to start the controller are:
• The height and width of the grid of zones.
• The path to the sinister file.
• Simulations to run, given as triples of: the number of rounds in the simulation, port number and number
of teams expected on that port. If the port number is a dash, then the port number should be chosen
by the OS. eg: 3 - 5 9 3500 8 would run two simulations, the first on an OS assigned port requiring 5
teams with three rounds and the second on port 3500 requiring 8 teams and taking nine rounds.
For example:
2310controller 3 7 files/sinister3 3 - 4
would create a grid of zones 3 high and 7 wide. Agent capabilities will be read from files/sinister3. The
controller will wait for 4 teams to connect on a port chosen by the OS. The simulation will run for 3 rounds.
356983-29492-32236083Prepared for s4371809. Do not distribute.
As soon as the controller has checked its arguments, it should prınt out (on a new line) the port used for
each simulation (in the order given on the command line). For example:
2310controller 4 4 files/sinister2 7 - 2 6 7502 8 6 - 5
might print:
59010
7502
55033
Another run with the same parameters might prınt:
54323
7502
60010
4.2 Sequence
The controller will run until all simulations have completed (successfully or unsuccessfully). Each simulation
will do the following:
Once the required number of teams have connected, the controller will run the required number of rounds.
The simulation environment will consist of a grid of zones and a number of teams (each team being in a zone).
In each round of the simulation, any teams in the same zone will battle.
At the start of each round, the controller will send a message to each team telling them which zone they are
in and which other teams they need to challenge (the other teams in the same zone). Each team will display a
message indicating their location:
Team is in zone x y
where x y is replaced with the coordinates of the zone.
The teams will then receive a battle message to tell them which other teams they are going to fight. The
ports listed in the battle message should be arranged as follows:
1. Teams in the simulation should be sorted in lexicographic order by name (the first in sequence being Team
0).
2. Ports are to be listed in their team number order.
3. Each team will be told to challenge all teams with a higher team number than themselves, not including
the last team. The last team will challenge everyone. For example: Suppose 4 teams must battle in a
given zone (t0, t1, t2, t3), where t0 has the lowest team number.
• t0 will challenge t1, t2
• t1 will challenge t2
• t2 will not challenge anyone
• t3 will challenge t0, t1, t2
Upon receiving a battle message, a team will engage in a battle with each of the opposition teams they
were sent. Such battles follow the same sequence as described earlier in Section 3.2. After a battle is complete,
the team will send either a donefighting message to indicate the battle completed successfully, or a disco
message to indicate the opposition disconnected early or sent invalid setup information. At the end of each
round, each team will output their narratives in order (lexicographic order by opponent team names). Note
that this is done by the 2310team process responsible for the team, not by the controller.
When the controller has recieved enough donefighting messages, the round is over and it will send each
team either:
• a wherenow? to ask for their next move, or
• a gameoverman message to indicate the end of the simulation.
If the controller receives a disco message from a team instead of a donefighting message, the simulation
will end early. When the simulation has ended, all teams will be sent a gameoverman message. Teams that
receive this message will then exit normally.
Note:
• The borders of the grid wrap. For example, this means if a team tries to move off the top of the grid,
they will reappear at the bottom.
• As per team battles, both sides detect the loss of the other by a read failure. A write failure must not
crash your program.
3356983-29492-32236084Prepared for s4371809. Do not distribute.
4.3 Exit Statuses
All messages are to be printed to stderr.
Condition Exit Message
Normal exit due to game over 0
Wrong number of arguments 1 Usage: 2310controller height width sinisterfile
rounds port teams [[rounds port teams] ...]
Invalid grid height 2 Invalid height
Invalid grid width 3 Invalid width
Unable to open sinister file for
reading
4 Unable to access sinister file
Contents of sinister file are invalid
5 Error reading sinister file
Invalid number of rounds 6 Invalid number of rounds
Port number is invalid 7 Invalid port number
Port number is in use 8 Unable to listen on port
Invalid number of teams 9 Invalid number of teams
Problem encountered while parsing message, etc
19 Protocol error
System error (eg. malloc failure) 20 System error
Table 3: Exit statuses for controller
3356983-29492-32236085Prepared for s4371809. Do not distribute.
5 Messages
Message Params From To Meaning
sinister This is a multi-line message
Controller Team Used to send the sinister
file to a team
iwannaplay x y N P x y are grid coordinates
where the team wants to
start. N is the team
name. P is the port the
team is waiting on.
Team Controller A new team wants to join
the simluation
battle x y P x and y are grid coordinates where the team is
currently located. P is
a space separated list of
port numbers (it could be
empty).
Controller Team Starts a new round. Connect to all those ports and
challenge the team at each
one.
fightmeirl n n is a team name Team Team Used by challenger to send
name to team they are
challenging
haveatyou n n is a team name Team Team Response to fightmeirl
to send name back
iselectyou a a is an agent name Team Team Tell the opposition team
which agent they are using
attack a m a is an agent name, m is
an attack name
Team Team Indicate an attack
donefighting Team Controller Sent by both teams once
their battle has successfully completed
disco Team Controller Sent by a team when the
battle finished early due
to the opposition disconnecting or sending invalid
setup information
gameoverman Controller Team Sent to all teams to indicate the simulation is over
wherenow? Controller Team After a round is over, ask
team which direction to
move next
travel d d is a single character direction (N, E, S, W)
Team Controller Direction to move after
all fights (in response to
wherenow?)
6 File Formats
There are two types of file that are used by the team and controller when running a simulation or battle.
6.1 Team file
The members of each team, the attacks to be used in battle and the directions to move to new zones are recorded
in a teamfile.
Here is an example team file:
teamdoomed
cobra slither poison
gull flap swoop swoop
flying_fox flap poison
cobra poison poison slither slither
3 4
N N E E W N W E
3356983-29492-32236086Prepared for s4371809. Do not distribute.
The first line gives the name of the team. The next four lines give team members and a sequence of attacks
they will try to use (in order). The next line gives the coordinates which this team will start at when joining a
full simulation being run by a 2310controller (the controller will mod these by the relevant dimension). The
final line gives the sequence of moves that this team will make after each round of the simulation.
6.2 Sinister file
The capabilities of the agents are described in a common sinister file.
Here is an example sinister file:
# Type names
bird
mammal
reptile
australian
.
# Type effectiveness strings
mammal it_worked_well ok something_went_wrong
bird it_worked_great ok not_great
australian bonza ok it_was_pretty_average
reptile it_was_effective it_was_ok it_was_ineffective
.
# Type relations
australian +bird +mammal +reptile -australian
bird -reptile +mammal
reptile -mammal +bird
mammal +reptile -bird
.
# Attacks
add_beetroot australian
add_vegemite australian
eat_egg mammal
pounce mammal
slither reptile
poison reptile
lose_tail reptile
flap bird
peck bird
swoop bird
scratch mammal
.
# Agents
mongoose mammal pounce scratch swoop
cobra reptile poison slither swoop
gull bird peck swoop flap
flying_fox mammal flap poison add_beetroot
croc australian pounce add_beetroot add_vegemite
.
The file consists of five sections, each ending with a . on a newline. The items on each line should be
separated by a space. A line beginning with a # is a comment and should be discarded. The sections will be as
follows:
Section 1 List of available types on separate lines. Each agent has a type and each attack has a type.
Section 2 Attacks will have have one of three levels of effectiveness: High, Normal and Low. Each line of this section
will give a type followed by an effectiveness string for each level of effectiveness in order from High to
Low. These are phrases to be used when an attack of that type and effectiveness is performed.
Section 3 Describes thå effectiveness of each type against the other types.
Each line gives the type followed by a list of other types preceded by +, = or - indicating whether the first
type has High, Normal or Low effectiveness against that type. If a type relationship is not listed, then it
defaults to Normal effectiveness.
356983-29492-32236087Prepared for s4371809. Do not distribute.
Section 4 List of available attacks. Eack line gives an attack and which type the attack is.
Section 5 List of agents. Each line gives an agent, its type and then three attacks which that agent can perform.
Since the file uses the space character as a delimiter, types, attacks and effectiveness strings can use an
underscore ('_') to have it replaced by a space.
7 Marking
As with previous assignments, up to 8 marks will be given for style and up to 42 marks for functionality. Style
marks will be calculated as follows:
Let A be the number of style violations detected by simpatico plus the number of build warnings. Let H be the
number of style violations detected by human markers. Let F be the functionality mark for your assignment.
• If A > 10, then your style mark will be zero and M will not be calculated.
• Otherwise, let MA = 4 × 0.8A and MH = MA − 0.5 × H your style mark S will be MA + max{0, MH}.
Your total mark for the assignment will be F + min{F, S}.
Functionality marks will be allocated as follows:
• With fixed sinister file:
– Team operating in challenge mode. (4 marks)
– Team operating in wait mode. (4 marks)
• With unknown sinister file:
– Team operating in challenge mode. (4 marks)
– Team operating in wait mode. (4 marks)
• Teams used with controller:
– Controller and team argument checking for use with controller (3 marks)
– Two teams in a single round simulation (4 marks)
– Multiple rounds with at most one battle per round (5 marks)
– Multiple simualtions, multiple rounds with at most one battle per round (4 marks)
– Multiple simulations, multiple rounds (10 marks)
7.1 Banned functions/features
One of the aims of this assignment is to operate with threads and TCP networking. Your programs are not
permitted to start additional processes or create additional files on the filesystem or make use of IPC pipes.
Further, you are not permitted to make use of gnu language extensions or any of the following:
__attribute__, getdelim, getline, setjump, longjump, goto, select.
You are not permitted to use posix regex features.
You are also not to use non-blocking IO nor setbuff() or equivalents to switch off buffering on FILE*.
Late Penalties
Late penalties will apply as outlined in the course profile.
Specification Updates
It is possible that this specification contains errors or inconsistencies or missing information. It is possible that
clarifications will be issued via the course website. Any such clarifications posted 5 days (120 hours) or more
before the due date will form part of the assignment specification. If you find any inconsistencies or omissions,
please notify the teaching staff.
356983-29492-32236088Prepared for s4371809. Do not distribute.
Test Data
Test data and scripts for this assignment will be made available. (testa4.sh, reptesta4.sh) The idea is to help
clarify some areas of the specification and to provide a basic sanity check of code which you have committed.
They are not guaranteed to check all possible problems nor are they guaranteed to resemble the tests which will
be used to mark your assignments. Testing that your assignment complies with this specification is still your
responsibility.
8 Tips
• You will need a map data structure.
• You will need a list/queue/iterable sequence.
9 Changes
• 4.3 → 4.4
– Explain the 2310team simulation mode setup and operations order
– Change order of 2310team exit statuses to reflect order of validation (sinister then team) and remove
Invalid setup information received exit status
• 4.2 → 4.3
– Consistent spelling of flying_fox
– flying_fox now uses legal moves in team file.
– Effectiveness strings are chosen from the move type not the attacking agent type.
– corrected an indefinite article.
• 4.1 → 4.2
– Added missing moves to teamfile
• 4.0 → 4.1
– Fixed Due date.
– Added posix regex to the banned list.
– Added style mark formulae
– Assignment submission will be via svn commit to /trunk/ass4 in your repository.
– Your assignment must compile (with make) with at least the following flags: -std=gnu99 -pedantic
-Wall. The usual rules about not trying to supress warnings with pragma or compiler flags still
apply.
3356983-29492-32236089