Starting from:
$35

$29

Programming Assignment 4 Solution

    • Objectives

In this homework you will get familiar with Inheritance, Polymorphism and Abstract class concepts in Object Oriented programming.

Keywords: OOP, Inheritance, Abstract class, Polymorphism


    • Problem De nition

In this homework, you are going to simulate a treasure hunt game. In this game, there are players (abstract class) with di erent classes (implementations) divided in two teams. The hunt commences on a square grid of size N which is the Board class. The top left square of the grid has the coordinate (0,0) while the bottom right square has coordinates(N-1,N-1). X axis is the horizontal axis and Y axis is the vertical axis. One of the squares contains the treasure, some of them contains the characters and other squares are empty. The classes you are going to de ne are Player (and its implementations), Board, Game and Input Parser. They are explained below.
























1

    • Class De nitions

3.1    Player

Player is an abstract class. There are 5 types of players, namely, Fighter, Archer, Tank, Priest and Scout. Each player can be in the barbarian team or the knight team. Each type of player has di erent HP, attack damage, heal power and goal priority (will be explained later in the game class). The class and method de nitions of Player is written below. After that there are subsections that explains the sub-classes of Player.

c l a s s  Playerf
p r o t e c t e d :

c o n s t  uint id ;

Coordinate coordinate ;

i n t  HP ;

Team team ;

//DO NOT MODIFY THE UPPER PART

//ADD YOU OWN PROVATE METHODS/PROPERTIES BELOW

p u b l i c :

    • ∗ ∗

Main  c o n s t r u c t o r














@param
i d

i d  o f
t h e
p l a y e r .

@param
x
x
c o o r d i n a t e
o f
t h e  p l a y e r

@param
y
y
c o o r d i n a t e
o f
t h e  p l a y e r

@param
team team
o f
t h e
p l a y e r , BARBARIAN o r KNIGHT









∗/

Player(uint id , i n t
x ,  i n t  y ,
Team team) ;
v i r t u a l  ~Player ( )
= d e f a u l t ;

uint getID ( )  c o n s t ;

c o n s t  Coordinate&
getCoord ( )
c o n s t ;
i n t  getHP ( )  c o n s t ;



Team getTeam ( )  c o n s t ;

    • ∗ ∗
∗ @return t h e board ID o f t h e p l a y e r , I f t h e ID i s s i n g l e d i g i t add a p r e f i x ∗ 0 , o t h e r w i s e j u s t t u r n i t i n t o a s t r i n g . ∗

∗ Example : ∗3 >"03" ∗ 12 > "12"


∗/
std : : string getBoardID ( ) ;

v i r t u a l
i n t
getAttackDamage ( )  c o n s t
= 0 ;
v i r t u a l
i n t
getHealPower ( )  c o n s t =
0 ;
v i r t u a l
i n t
getMaxHP ( )  c o n s t = 0 ;



2

    • ∗ ∗

For
each  s u b c l a s s
o f  P l a y e r  t h e r e
a r e
d i f f e r e n t
p r i o r i t y
l i s t s  d e f i n e d

t h a t
c o n t r o l s  t h e
next  a c t i o n
t o  t a k e
f o r  t h a t
P l a y e r .  I t
i s  g i v e n  i n  t h e
∗  h e a d e r  o f  t h e  s u b c l a s s e s .

















@return  t h e  g o a l
p r i o r i t y
l i s t
f o r
t h e
P l a y e r


∗/
v i r t u a l  std : : vector<Goal> getGoalPriorityList ( ) ;
    • ∗ ∗

∗ @return t h e c l a s s a b b r e v i a t i o n o f p l a y e r , i f t h e p l a y e r i s on t h e b a r b a r i a n ∗ team , t h e a b b r e v i a t i o n w i l l c o n s i s t o f u p p e r c a s e c h a r a c t e r s , o t h e r w i s e i t ∗ w i l l c o n s i s t o f l o w e r c a s e c h a r a c t e r s . ∗

∗/

v i r t u a l    c o n s t  std : : string getClassAbbreviation ( )    c o n s t ;

    • ∗ ∗

Attack  t h e  g i v e n  p l a y e r .








Enemy HP s h o u l d
d e c r e a s e
a s
much  a s  t h e  a t t a c k
damage  o f
a t t a c k e r .
P r i n t

t h e  boardID
o f
t h e
a t t a c k e r
and  t h e
a t t a c k
and
t h e  amount
o f  damage
a s  below  -

.










∗  " P l a y e r  01  a t t a c k e d
P l a y e r  05  ( 7 5 ) "


















@param enemy  p l a y e r
t h a t
i s
a t t a c k e d .





@return  t r u e
i f
t h e
opponent
i s  dead
f a l s e
i f
a l i v e .


∗/

b o o l  attack(Player ∗enemy) ;

    • ∗ ∗
∗ Heal t h e g i v e n p l a y e r by t h e adding amount o f h e a l power o f t h i s c h a r a c t e r ∗ t o t h e HP o f a l l y . P r i n t t h e boardID o f t h e h e a l e r and h e a l e d p l a y e r s a s
∗  below .
∗  " P l a y e r  01  h e a l e d  P l a y e r  05"
∗  Healed  p l a y e r  s h o u l d  not  have  more HP than    i t s  max HP.
∗/

v o i d  heal(Player ∗ally) ;
    • ∗ ∗

@Important The  c o o r d i n a t e s
may not  be
on
t h e
board .











@return
t h e
c o o r d i n a t e s  t h a t
t h e
u n i t
i s
a b l e
t o  a t t a c k  g i v e n  t h e  p o s i t i o n

o f  t h e
u n i t .
Empty  v e c t o r
i f
t h e
u n i t
cannot
a t t a c k .
∗/

v i r t u a l  std : : vector<Coordinate> getAttackableCoordinates ( ) ;

    • ∗ ∗

@Important
The  c o o r d i n a t e s
may
not
be
on
t h e
board .










@return  t h e
c o o r d i n a t e s  t h e
u n i t  i s
a b l e
t o
move  g i v e n  t h e  p o s i t i o n  o f  t h e

u n i t .  Empty
v e c t o r  i f  t h e  u n i t
cannot
move .

∗/
v i r t u a l  std : : vector<Coordinate> getMoveableCoordinates ( ) ;




3

    • ∗ ∗

∗  @return  t h e    c o o r d i n a t e s    t h e  u n i t    i s    a b l e  t o  h e a l    a l l i e s    g i v e n  t h e    p o s i t i o n    -
o f  t h e
∗  u n i t .  Empty  v e c t o r    i f    none  a v a i l a b l e .
∗/
v i r t u a l  std : : vector<Coordinate> getHealableCoordinates ( ) ;

    • ∗ ∗

Move  p l a y e r
t o  c o o r d i n a t e .
P r i n t  t h e
boardID  o f
t h e  p l a y e r
and  t h e  o l d  and   -

new






c o o r d i n a t e s
a s  below :





" P l a y e r  01 moved from  ( 0 / 1 )  t o  ( 0 / 2 ) "




@Important
b e f o r e  c a l l i n g
t h i s  method
you  must
v e r i f y  t h a t
t h i s  c o o r d i n a t e

i s  v a l i d  t o
move




∗/
v o i d  movePlayerToCoordinate(Coordinate c) ;



    • ∗ ∗
∗  Decide  whether  t h e  p l a y e r    i s    dead .

∗  @return  t r u e    i f    t h e  p l a y e r ' s HP <= 0 ,    f a l s e    o t h e r w i s e .
∗/
b o o l  isDead ( )    c o n s t ;

    • ;

3.1.1    Archer

c l a s s  Archer  :    p u b l i c  Playerf
    • ∗ ∗
∗ Attack damage 50 ∗ Heal power 0
∗  Max HP 200

Goal  P r i o r i t i e s
> fATTACKg


C l a s s  a b b r e v i a t i o n
> " a r "
o r  "AR"

Not  a b l e  t o  move
a t
a l l .


Can  a t t a c k  t o  a
r a n g e  o f  2
s q u a r e s  d i r e c t l y  up ,  down ,  l e f t  o r  r i g h t ,  from
∗  i t s  c o o r d i n a t e .

∗/
    • ;

3.1.2    Fighter

c l a s s  Fighter  :    p u b l i c  Playerf
    • ∗ ∗
∗ Attack damage 100 ∗ Heal power 0
∗  Max HP 400

Goal
P r i o r i t i e s   > fATTACK,TO ENEMY,CHESTg i n
d e c r e a s i n g  o r d e r

C l a s s  a b b r e v i a t i o n
> " f i "  o r
"FI"



Can
move  t o
a d j a c e n t
up ,  down ,
l e f t  o r
r i g h t
s q u a r e

Can
a t t a c k
t o  a d j a c e n t  up ,  down ,  l e f t
o r  r i g h t  s q u a r e









∗/
    • ;

4

3.1.3    Priest

c l a s s  Priest  :    p u b l i c  Playerf
    • ∗ ∗
∗ Attack damage 0 ∗ Heal power 50 ∗ Max HP 150

Goal
P r i o r i t i e s
> fHEAL,TO ALLY,CHESTg
i n
d e c r e a s i n g  o r d e r

C l a s s  a b b r e v i a t i o n  > "pr"  o r  "PR"



Can
move
t o
a l l
a d j a c e n t  s q u a r e s ,  i n c l u d i n g
d i a g o n a l s .

Can
h e a l
a l l
a d j a c e n t  s q u a r e s ,  i n c l u d i n g
d i a g o n a l s .









∗/
    • ;

3.1.4    Scout

c l a s s  Scout  :    p u b l i c  Playerf
    • ∗ ∗
∗ Attack damage 25 ∗ Heal power 0

∗  Max HP 125

Goal
P r i o r i t i e s
> fCHEST,TO ALLY,ATTACKg i n  d e c r e a s i n g  o r d e r

C l a s s  a b b r e v i a t i o n  > " s c "  o r  "SC"


Can
move  t o
a l l
a d j a c e n t
s q u a r e s ,
i n c l u d i n g
d i a g o n a l s .

Can
a t t a c k
a l l
a d j a c e n t
s q u a r e s ,
i n c l u d i n g
d i a g o n a l s .









∗/
    • ;

3.1.5    Tank

c l a s s  Tank  :    p u b l i c  Playerf
    • ∗ ∗
∗ Attack damage 25 ∗ Heal power 0
∗  Max HP 1000

Goal
P r i o r i t i e s   > fTO ENEMY,ATTACK,CHESTg i n
d e c r e a s i n g  o r d e r

C l a s s  a b b r e v i a t i o n
> " t a "  o r  "TA"



Can
move  t o
a d j a c e n t
up ,  down ,  l e f t  o r
r i g h t
s q u a r e

Can
a t t a c k
t o  a d j a c e n t  up ,  down ,  l e f t
o r  r i g h t  s q u a r e








∗/
    • ;

3.2    Board

Board holds size of the board, players and position of the chest. Its methods are concerned with printing the contents of the eld and returning the properties of coordinates. The class header is given below.

c l a s s  Boardf

p r i v a t e :

uint size ;
std : : vector<Player∗>∗  players ;
Coordinate chest ;

//DO NOT MODIFY THE UPPER PART

//ADD YOU OWN PROVATE METHODS/PROPERTIES BELOW

p u b l i c :


5

Board(uint _size , std : : vector<Player∗>∗ _players , Coordinate chest) ; ~Board ( ) ;

    • ∗ ∗
∗  @return  t r u e    i f    t h e  c o o r d i n a t e    i s    i n  t h e  board  l i m i t s ,    f a l s e    o t h e r w i s e .
∗/
b o o l  isCoordinateInBoard( c o n s t  Coordinate& c) ;
    • ∗ ∗
∗  @return  t r u e    i f    t h e r e    i s  a  p l a y e r  on  t h e  g i v e n  c o o r d i n a t e ,    f a l s e    o t h e r w i s e .
∗/
b o o l  isPlayerOnCoordinate( c o n s t  Coordinate& c) ;
    • ∗ ∗

∗ @return p o i n t e r t o t h e p l a y e r a t t h e g i v e n c o o r d i n a t e . Return NULL i f no ∗ p l a y e r i s t h e r e .
∗/
Player ∗ o p e r a t o r    [ ] ( c o n s t  Coordinate& c) ;

    • ∗ ∗
∗  @return  t h e  c h e s t    c o o r d i n a t e
∗/
Coordinate getChestCoordinates ( ) ;
    • ∗ ∗

P r i n t  t h e  board
with
c h a r a c t e r
ID ' s .








For
each  empty
s q u a r e
p r i n t  two
u n d e r s c o r e
c h a r a c t e r s .



For
t h e
s q u a r e s
with
a  p l a y e r  on  i t ,
p r i n t
t h e
board
i d  o f
t h e
p l a y e r .

For
t h e
s q u a r e
with  t h e
c h e s t ,
p r i n t
t h e
s t r i n g
"Ch" .




I f
a  c h a r a c t e r
i s  on
t h e
s q u a r e
with
t h e
c h e s t ,
o n l y
p r i n t
t h e
ID  o f  t h e
∗  c h a r a c t e r .
∗  For  each  row  p r i n t  a new  l i n e ,    f o r    each  column  p r i n t  a  s p a c e    c h a r a c t e r .
∗  Example :
∗01


02
05

Ch
03




∗/
v o i d  printBoardwithID ( ) ;
    • ∗ ∗
∗  For  each  empty  s q u a r e    p r i n t  two  u n d e r s c o r e    c h a r a c t e r s .
∗  For  t h e  s q u a r e s  with  a  p l a y e r  on  i t ,    p r i n t    t h e    c l a s s    a b b r e v i a t i o n    o f  t h e
∗  p l a y e r .

For
t h e  s q u a r e
with
t h e
c h e s t ,  p r i n t
t h e
s t r i n g
"Ch" .


I f
a  c h a r a c t e r
i s
on
t h e
s q u a r e
with
t h e
c h e s t ,
o n l y  p r i n t  t h e
a b b r e v i a t i o n
∗  o f  t h e  c h a r a c t e r .









To
s e p a r a t e  each
row
p r i n t  a new
l i n e ,  t o
s e p a r a t e  each  column
p r i n t  a
∗ s p a c e c h a r a c t e r . ∗ Example :
∗PR

     a r    TA

∗  Ch    f i



∗/
v o i d  printBoardwithClass ( ) ;

    • ;

3.3    Game

Game class is responsible for running the game and managing the memory. The most important method here is the playTurnForPlayer method which computes the moves for the players given their di erent goal


6

priorities.

c l a s s  Gamef

p r i v a t e :

Board board ;

uint turnNumber ;

uint maxTurnNumber ;
std : : vector<Player∗> players ;

//DO NOT MODIFY THE UPPER PART

//ADD YOU OWN PROVATE METHODS/PROPERTIES BELOW

p u b l i c :
    • ∗ ∗
∗  C o s t r u c t o r    f o r  Game  c l a s s .
∗  Game manages  t h e  memory  a l l o c a t e d    f o r    f u t u r e    c o n t e n t s  t h e  v e c t o r  ( added    -
p l a y e r s ) .

Pass  a
p o i n t e r  t o  t h e
p l a y e r s  v e c t o r
t o
board  c o n s t r u c t o r  s o  t h a t  t h e  board   -

w i l l






not  miss  t h e  a d d i t i o n
o f
p l a y e r s  t o
t h e
game .

@param maxTurnNumber  t u r n  number  t o  end  t h e  game

@param
b o a r d S i z e  s i z e
o f
t h e  board



@param
c h e s t  c o o r d i n a t e
o f  t h e  c h e s t


∗/

Game(uint maxTurnNumber , uint boardSize , Coordinate chest) ; ~Game ( ) ;


    • ∗ ∗

Add a
new
p l a y e r  t o
t h e
game .  Add
a  p o i n t e r  t o
t h e  new  p l a y e r
t o
t h e  t h i s  >  -

p l a y e r s  v e c t o r .









Do not
f o r g e t  t h a t
Game
w i l l
manage  t h e  memory
a l l o c a t e d  f o r
t h e
p l a y e r s .

@param  i d  ID  o f  t h e  new
p l a y e r .





@param
x
x
c o o r d i n a t e
o f
t h e
new
p l a y e r .




@param
y
y
c o o r d i n a t e
o f
t h e
new
p l a y e r .




@param
team
team  o f
t h e
new
p l a y e r .
















∗/
v o i d  addPlayer( i n t  id ,    i n t  x ,    i n t  y ,  Team team ) ;

    • ∗ ∗

The game  ends
when
e i t h e r
o f
t h e s e  happens :



A l l  b a r b a r i a n s  d i e  ( k n i g h t  v i c t o r y )




A l l  k n i g h t s
d i e  ( b a r b a r i a n  v i c t o r y )




A b a r b a r i a n
g e t s  t o  t h e  s q u a r e  c o n t a i n i n g  t h e  c h e s t  ( b a r b a r i a n  v i c t o r y )

maxTurnNumber
o f
t u r n s  p l a y e d
( k n i g h t
v i c t o r y )
















I f  t h e  game  ends
announce
i t
py
p r i n t i n g
t h e
r e a s o n ,
t u r n  number and  t h e   -

v i c t o r












a s  i n
t h e
f o l l o w i n g
examples :



















Game
ended
a t
t u r n
1 3 .
A l l
b a r b a r i a n s  dead .
Knight  v i c t o r y .

Game
ended
a t
t u r n
121.
A l l
k n i g h t s  dead .  B a r b a r i a n
v i c t o r y .

Game
ended
a t
t u r n
5 2 .
Chest
c a p t u r e d .  B a r b a r i a n  v i c t o r y .

Game
ended
a t
t u r n
215.
Maximum
t u r n  number
r e a c h e d .
Knight  v i c t o r y .

∗  @return  t r u e    i f    any  o f  t h e  above    i s    s a t i s f i e d ,    f a l s e    o t h e r w i s e



7

∗/
b o o l  isGameEnded ( ) ;

    • ∗ ∗

Play  a  t u r n
f o r
each
p l a y e r .






A c t i o n s  a r e
taken  i n
t h e
o r d e r
o f  ID
numbers  o f
p l a y e r s
( p l a y e r
with
∗  s m a l l e r  ID  a c t s  f i r s t ) .







At  t h e  s t a r t
o f
t h e  t u r n
i t  announces
t h a t  t h e
t u r n  has
s t a r t e d
by  p r i n t i n g

t o  s t d o u t .  Turn
numbers
s t a r t s
with  1 .




Ex :
"Turn  13
has
s t a r t e d . "






C a l l
playTurnForPlayer  f o r  e v e r y  p l a y e r .















∗/
v o i d  playTurn ( ) ;
    • ∗ ∗

Play  a
t u r n  f o r
t h e  p l a y e r  with
t h e
g i v e n  ID .



I f
t h e
p l a y e r
i s
dead  announce
i t s
death  by
p r i n t i n g
t h e  boardID  o f  t h e
-

p l a y e r








a s
i n
" P l a y e r
07
d i e d . " .  Remove
t h a t  p l a y e r
from  t h e
board  and  r e l e a s e
i t s   -
r e s o u r c e s .



















Each
p l a y e r
has  a  g o a l
l i s t
s o r t e d
by
i t s
p r i o r i t y
f o r
t h a t
p l a y e r .


When
a  p l a y e r
p l a y s  a
t u r n
i t
i t e r a t e s
o v e r  i t s
g o a l  l i s t  and
t r i e s
t o  t a k e

an  a c t i o n .
V a l i d  a c t i o n s
a r e
a t t a c k ,  move
and  h e a l . A
p l a y e r
can  t a k e  o n l y

one
a c t i o n
i n
a  turn ,
and
i f
t h e r e
i s
no
a c t i o n
i t
can
t a k e
i t
s t o p s
and   -
d o e s  n o t h i n g .

B e f o r e  moving
a
p l a y e r  you
must
check
i f
t h e  c o o r d i n a t e
t o
move
i s  v a l i d .


Meaning  that ,
t h e  c o o r d i n a t e
i s
i n
t h e
bounds  o f
t h e  board
and
t h e r e  a r e
no

∗  p l a y e r s  t h e r e .



































∗  IMPORTANT NOTE:
e v e r y  us a g e
o f
t h e
word
n e a r e s t
i s  r e f e r e n c i n g
s m a l l e s t
t h e
-

Manhattan

















d i s t a n c e ,
which
i s  f o r m u l a t e d
a s  ( abs ( x
1  x
2 )
+
abs ( y 1
y
2)).
o p e r a t o r



o v e r l o a d e d
i n
C o o r d i n a t e . h
computes
e x a c t l y
that ,
s o  you
can  u s e  t h a t  method
-

t o


















c a l c u l a t e
t h e
d i s t a n c e  between
two
c o o r d i n a t e s .



























Below  a r e
t h e
e x p l a n a t i o n s
f o r
g o a l s :






























∗  ATTACK:

I f
t h e r e
a r e
any  e ne m ie s
i n  t h e
a t t a c k
r a n g e
o f
t h e
p l a y e r
a t t a c k  t o  i t .

I f
t h e r e
a r e
more  than
1
enemy  i n  t h e  r a n g e
a t t a c k
t o
t h e
one  with

l o w e s t  ID .  I f
t h e r e  i s
no
one  t o
a t t a c k
t r y
t h e
next
g o a l .















∗  CHEST:

Move
t o
t h e
d i r e c t i o n
o f
t h e
c h e s t ,  i f
both
v e r t i c a l
and
h o r i z o n t a l
-

moves














a r e
a v a i l a b l e ,  p i c k  t h e
h o r i z o n t a l
one .
I f
t h e
h o r i z o n t a l
move  i s
-

b l o c k e d














but
t h e
v e r t i c a l  move
i s
not ,
move
v e r t i c a l l y .
I f  a l l
d i r e c t i o n s  towards

t h e
c h e s t  i s
b l o c k e d
t r y
t h e
next
g o a l .





















∗  TO ENEMY:

     Move towards  t h e  n e a r e s t  enemy .    I f    t h e r e    a r e  more  than  one  e n e mi e s  with    -

t h e  same  d i s t a n c e
     move  towards  t h e  one  with  t h e    s m a l l e s t  ID .    I f    both    v e r t i c a l  and    -

h o r i z o n t a l  moves


8


a r e
a v a i l a b l e ,
p i c k
t h e  h o r i z o n t a l
one .
I f
an enemy
i s
i n  t h e
s q u a r e s

t h a t
t h e  p l a y e r
can
move  o r  e v e r y
move
t h a t
b r i n g s
t h e
p l a y e r
c l o s e r  t o

t h e
s e l e c t e d  enemy
i s  blocked ,  t r y
t h e
next
g o a l .














∗  TO ALLY:


Move
towards
t h e
n e a r e s t
a l l y .
I f
t h e r e
a r e
more  than
one
a l l i e s
with
-

t h e  same  d i s t a n c e
















move
towards  t h e  one
with
t h e
s m a l l e s t
ID .
I f
both
v e r t i c a l
and
-


h o r i z o n t a l  moves
















a r e
a v a i l a b l e ,
p i c k
t h e  h o r i z o n t a l
one .
I f
an
a l l y
i s
i n
t h e
s q u a r e s


t h a t
t h e  p l a y e r
can
move  o r  e v e r y
move  t h a t
b r i n g s
t h e  p l a y e r
c l o s e r
t o

t h e
s e l e c t e d
a l l y
i s
blocked ,
t r y
t h e  next
g o a l .

























∗  HEAL:

I f
t h e r e
a r e
any
a l l i e s  i n
t h e
h e a l i n g
r a n g e  h e a l  a l l
o f
them .  i f
t h e r e

i s
no  one  t o
h e a l
t r y
t h e
next
g o a l .































@return
t h e
g o a l
t h a t
t h e
a c t i o n  was  taken
upon . NO GOAL
i f
no  a c t i o n
was   -

taken .
∗/
Goal playTurnForPlayer(Player∗  player) ;
    • ;

3.4    InputParser

Reads the standard input and creates a Game object. Details are explained in the header.

c l a s s  InputParserf

p u b l i c :

    • ∗ ∗

Parse
t h e
i n i t i a l
p a r a m e t e r s
o f
t h e
game  from  s t d i n .


The  i n p u t
w i l l  be
a s  f o l l o w s .









F i r s t
l i n e  c o n t a i n s
t h e
s i z e
o f
t h e  board .





Second  l i n e
c o n t a i n s
t h e
c o o r d i n a t e s
o f  t h e
c h e s t .



Third
l i n e  c o n t a i n s
t h e
number
o f  p l a y e r s ,
P .




Each
o f  t h e
next P
l i n e s
c o n t a i n s  a
d e s c r i p t i o n
f o r
a  p l a y e r
a s  f o l l o w s .

ID  o f
t h e  p l a y e r ,
c l a s s
o f
t h e
p l a y e r ,
team
o f
t h e
p l a y e r ,  x
c o o r d i n a t e ,  y   -

c o o r d i n a t e ,  .













C a l l
t h e
addPlayer
method
o f
t h e Game
c l a s s
t o
add
t h e  p l a y e r s .
∗  Example  i n p u t :
∗  6
∗  3  3
∗  2
∗ 12 ARCHER BARBARIAN 3 5 ∗ 11 FIGHTER KNIGHT 1 1

∗  @returns  P o i n t e r  t o  t h e  Dynamically    a l l o c a t e d  Game  o b j e c t
∗/
s t a t i c  Game∗  parseGame ( ) ;
    • ;


    • Extras

The enumerations you need are de ned in the Constants.h header. You can use them from there.


9

The Game class owns every player and vector of players in terms of memory management and is responsible for the destruction of these.

In order to get full grade from each part your code should not have any memory leak. This will be checked with valgrind. While grading your classes will be used with the correct implementations, therefore they are expected to work as commented in the code.


    • Regulations

        ◦ Programming Language: You must code your program in C++ (11). Your submission will be compiled with g++ with -std=c++11 ag on department lab machines.

        ◦ Allowed Libraries: You may include and use C++ Standard Library. Use of any other library (especially the external libraries found on the internet) is forbidden.

        ◦ Memory Management: When an instance of a class is destructed, the instance must free all of its owned/used heap memory. Any heap block, which is not freed at the end of the program will result in grade deduction. Please check your codes using valgrind {leak-check=full for memory-leaks.

        ◦ Late Submission: You have a total of 10 days for late submission. You can spend this credit for any of the assignments or distribute it for all. For each assignment, you can use at most 3 days-late.

        ◦ Cheating: In case of cheating, the university regulations will be applied.

        ◦ Newsgroup: It’s your responsibility to follow the cengclass forums for discussions and possible updates on a daily basis.


    • Submission

Submission will be done via CengClass. Create a zip    le named hw4.zip that contains:

    • Archer.h

    • Archer.cpp

    • Board.h

    • Board.cpp

    • Fighter.h

    • Fighter.cpp

    • Game.h

    • Game.cpp

    • InputParser.h

    • InputParser.cpp

    • Player.h

    • Player.cpp

    • Priest.h



10

    • Priest.cpp

    • Scout.h

    • Scout.cpp

    • Tank.h

    • Tank.cpp

Do not submit a le that contains a main function. Such a le will be provided and your code will be compiled with it. Also, do not submit a Make le.

Note: The submitted zip le should not contain any directories! The following command sequence is expected to run your program on a Linux system:

    • unzip hw4.zip

    • make clean

    • make all

    • make run

    • -optional- make valgrind













































11

More products