Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CS 115: Assignment 5 Assignment 5 Due March 31, 2021 Overview In this assignment, you will restructure your program to use dynamically allocated memory for the tiles. The Board and AvailableTiles...

1 answer below »
CS 115: Assignment 5
Assignment 5
Due March 31, 2021
Overview
In this assignment, you will restructure your program to use dynamically allocated memory for the tiles.
The Board and AvailableTiles classes will be put in canonical form and the constructors,
destructors, and assignment operators will be written to allocate and deallocate the memory as needed.
Internally, the game board will be a statically allocated 2D a
ay of pointers (which will be set to point to
dynamically allocated tiles) and the list of available tiles will be represented as a linked list. Each linked
list element will store the tile cost and a pointer to a dynamically-allocated tile.
Note that the dynamically allocated tiles are always “owned” by the class that creates and deletes them.
When a tile is needed elsewhere, it is passed by reference and, if necessary, the client creates a copy for
its own use. No tile is ever created by one class and destroyed by another one. This reduces the chance
of memory e
ors, such as memory leaks (caused by forgetting to call delete) and dangling pointers
(caused by trying to use something after it was deleted).
The purpose of this assignment is to give you practice with dynamically allocated memory, including
linked lists, and with how classes can be used to avoid memory leaks. For Part A, you will change your
Board class to use dynamically allocated tiles. For Part B, you will create an encapsulated type to store
a linked list element. For Part C, you will refactor your AvailableTiles class to store the tiles and
costs in a linked list.
Dynamic Memory Management
Each piece of dynamically allocated memory in the program will be managed by a single class. That
class will be the only part of the program that ever has access to the pointer to that memory. It will
allocate and deallocate the dynamic memory. The constructors, destructor, and assignment operator
will be used to ensure that the memory is always allocated before it is used and deallocated when it is
no longer needed. Class invariants will be used to check that everything is working co
ectly.
The Board Class
The Board class will manage the Tiles by using a 2D a
ay of pointers; each pointer in the a
ay is a
pointer to a Tile (see diagram). None of these pointers will ever be nullptr. Suppose your a
ay is
named pb. Then:
pb[i][j] XXXXXXXXXXis one of the pointers that points to a Tile
*(pb[i][j] XXXXXXXXXXis the Tile being pointed to by pb[i][j]
pb[i][j] -> genus XXXXXXXXXXis the genus field of the Tile being pointed to by pb[i][j]
The AvailableTilesElement Class
The AvailableTilesElement class will manage a single Tile, which will never be nullptr. The
AvailableTilesElement class will also contain a next pointer that it will not manage. The data
structure for an AvailableTilesElement is as follows:
The AvailableTiles Class
The AvailableTiles class will manage a linked list of AvailableTilesElements, which will
contain 5 elements at the end of each public member function (except the destructor). As a result,
the head pointer will never be nullptr. As part of managing the linked list, the AvailableTiles
new Tile new Tile
new Tile new Tile
new Tile
new Tile
new Tile
new Tile
new Tile
new Tile
new Tile
new Tile
new Tile
new Tile
Board
Tile
owner genus species
int int int
AvailableTilesElement
ptile cost pnext
int
Memory managed by
AvailableTilesElement
class will manage the next pointers for the elements. The data structure for an AvailableTiles is
as follows:
Allocation Counting
Even when ADTs are used, linked lists are a common cause of memory leaks. In this assignment, we will
use a technique named allocation counting to detect (and then fix) memory leaks in the linked list. In
short, we will create a global variable refe
ed to here as the allocation counter and start it at zero.
Whenever we allocate a linked list element, we will increment the allocation counter. Whenever we
deallocate an element, we will decrement allocation counter. To ensure that we do not miss any
allocations, we will update the allocation counter in the constructors and destructor.
Ideally, we would like to print the value of the allocation counter once at the end of the program. If it
were positive, a memory leak would exist and if it were zero, one would not. (If it is ever negative, there
is a bug in the counting code.) However, making something happen "only at the end of the program" is
difficult. Instead, we will print the allocation counter whenever it is decreased to zero. Then we will see
if it is printed when the program ends.
If you want to find out more about when the linked list elements were allocated and deallocated, you
can print the allocation counter every time it is changed. However, this will produce a lot of extra
messages, so you should disable or remove such printing before turning in your assignment.
Requirements
Start by creating a new project (or new folder, etc.) for Assignment 5. Do not just modify Assignment 4.
If you are using Visual Studio, create a new project and copy in the code files (.h and .cpp) from
Assignment 4. Do not ever copy a Visual Studio project. If you do, it will get all mixed up between the
two of them and Bad Things will happen.
Tile
Available-
Tiles-
Element
Tile Tile
AvailableTiles
phead
Memory managed
y AvailableTiles
Memory managed by
AvailableTilesElement
Available-
Tiles-
Element
Available-
Tiles-
Element
Part Zero [Optional but recommended]: Add a Copy Constructor to the Tile Class [0%]
It will be helpful in Part A if you have a copy constructor for the Tile class. You will add one line to the
Tile.h file and one function to the Tile.cpp file.
Add the prototype for the copy constructor to Tile.h; place it with the public member functions:
Tile (const Tile& original);
Add the following function to Tile.cpp:
Tile::Tile(const Tile& original)
{
genus = original.genus;
species = original.species;
owner = original.owner;
}
Adjust the names of the three member fields to match the names of your member variables in the Tile
class.
Part A: Change the Board Class [40% = 30% test program + 10% code]
In Part A, you will change the implementation of the Board class to use dynamically allocated memory
for the tiles. You will also add a class invariant requiring that none of the pointers are nullptr (or
NULL). Apart from explicitly listing the copy constructor, destructor, and assignment operator, the
interface for the class will not change.
Warning: Your Board class must use dynamically allocated memory for the tile. If it does not, you will
eceive 0/40% for Part A.
By the end of Part A, your Board class will have the following public member functions:
 Board ();
 Board (const Board& original);
 ~Board ();
 Board& operator= (const Board& original);
 void print () const;
 const Tile& getAt (const CellId& cell_id) const;
 void setAt (const CellId& cell_id,
XXXXXXXXXXconst Tile& value,
XXXXXXXXXXunsigned int owner);

You will also have the following private member functions:
 void printColumnNameRow () const;
 void printBorderRow () const;
 void printEmptyRow () const;
 void printDataRow (int row) const;
 void deleteAllTiles ();
 void copyAllTiles (const Board& original);
 bool isInvariantTrue () const;

Perform the following steps:
1. Change the declaration of your Board class so it contains a 2D a
ay of tile pointers instead of a
2D a
ay of tiles. Update the function implementations to call tile functions using a
ow
notation.
 Example: Everywhere that you use dot notation to call a function, e.g.,
tile.function(); change it so that you have tile->function(); This idea
also applies if the function has parameters.
 Note: You may want to name your pointer variables differently so you don't get them
mixed up with the normal kind of variable. For example, if your a
ay used to be named
data, it could be renamed to p_data or ptr_data.
2. Update the default constructor to allocate the tiles dynamically using the new command.
 Reminder: The new command yields a pointer to the new memory space.
3. Update the setAt function. It should start (after the precondition) by deallocating the tile at
the specified cell. Then it should dynamically allocate a new tile for the specified cell.
 Hint: Use the new command in association with the Tile copy constructor to create a
copy of the tile that is passed as a parameter. (If you do not provide the Tile copy
constructor, it will be provided automatically by C++). The syntax to initialize a pointer
named pb to point to a new Box (not a real type) that is a copy of an existing Box
named b1 is:
Box *pb = new Box(b1);
 Hint: You should save the pointer returned by the new command. You should save it at
the specified cell in your 2D a
ay of pointers. This can be done with a simple
assignment statement; you do not need to put & or * in front of the pointer.
 Comment: It is also permissible to use the Tile initializing constructor instead of the
Tile copy constructor. If you do it this way, you will need to set the owner field.
 Reminder: Deallocation is performed with the delete command. The delete
command must be given a pointer to the memory space that is being deallocated.
4. Add an implementation for the
Answered Same Day Mar 30, 2021

Solution

Kamal answered on Mar 30 2021
149 Votes
Dice.h
Dice.h
A module to handle dice rolling.
#pragma once
const int DICE_SIDE_COUNT = 4;
void diceInit ();
int diceRoll ();
void dicePrint2and2 (int r1, int r2, int c1, int c2);
void dicePrint2and2and1 (int r1, int r2, int c1, int c2, int e1);
Game.cpp
Game.cpp
  Game.cpp
#include #include #include #include "Player.h"
#include "BoardSize.h"
#include "CellId.h"
#include "Tile.h"
#include "Board.h"
#include "AvailableTiles.h"
#include "Dice.h"
#include "CellChooser.h"
#include "Game.h"
using namespace std;
Game :: Game ()
    : board(),
      available()
{
}
void Game :: printState (unsigned int whose_turn) const
{
    assert(whose_turn < playerGetCount());
    board.print();
    cout 
 endl;
    available.print();
    cout 
 endl;
    cout 
 playerGetName(whose_turn) 
 "'s turn:" 
 endl;
    cout 
 endl;
}
void Game :: handleDiceRoll (unsigned int whose_turn)
{
    assert(whose_turn < playerGetCount());
    bool is_extra_die = false;
    if(playerHasDice(whose_turn, 1))
    {
        is_extra_die = true;
        playerDecreaseDice(whose_turn, 1);
    }
    int row1    = diceRoll();
    int row2    = diceRoll();
    int column1 = diceRoll();
    int column2 = diceRoll();
    int extra   = diceRoll();
    if(is_extra_die)
        dicePrint2and2and1(row1, row2, column1, column2, extra);
    else
        dicePrint2and2(row1, row2, column1, column2);
    cout 
 endl;  
 blank line
    
 ask player to choose a cell if needed
    CellChooser cell_chooser(row1, row2, column1, column2, extra, is_extra_die);
    if(!cell_chooser.isChosen())
    {
        cell_chooser.printAvailable();
        while(!cell_chooser.isChosen())
        {
            cout 
 "Choose a cell to roll: ";
            string input;
            getline(cin, input);
            if(isOnBoard(input))
            {
                CellId chosen = toCellId(input);
                if(cell_chooser.isAvailable(chosen))
                    cell_chooser.chooseAvailable(chosen);
                else
                    cout 
 "  Cell " 
 chosen 
 " is not available" 
 endl;
            }
            else
                cout 
 "  Invalid cell" 
 endl;
        }
    }
    else
        cout 
 "Rolled cell: " 
 cell_chooser.getChosen() 
 endl;
    CellId chosen_cell = cell_chooser.getChosen();
    assert(isOnBoard(chosen_cell));
    Tile tile = board.getAt(chosen_cell);
    tile.activate(whose_turn);
}
ool Game :: puchaseTile (unsigned int whose_turn)
{
    assert(whose_turn < playerGetCount());
    playerPrint(whose_turn);
    string input;
    cout 
 "Choose a cell to place a tile: ";
    getline(cin, input);
    if(input == "q")
        return true;  
 player wants to quit
    bool is_discard_tile = true;
    if(isOnBoard(input))
    {
        CellId chosen_cell = toCellId(input);
        assert(isOnBoard(chosen_cell));
        if(!board.getAt(chosen_cell).isOwner())
        {
            int tile_index;
            cout 
 "Choose a tile to buy (by index): ";
            cin 
 tile_index;
            cin.clear();  
 clean up bad input
            getline(cin, input);  
 read to end of line
                
            if(tile_index >= 0 && tile_index < AVAILABLE_TILE_COUNT)
            {
                int cost = available.getCost(tile_index);
                if(playerHasMoney(whose_turn, cost))
                {
                    board.setAt(chosen_cell, available.getTile(tile_index), whose_turn);
                    playerDecreaseMoney(whose_turn, cost);
                    available.replaceAt(tile_index);
                    is_discard_tile = false;
                    cout 
 "Success: Tile added" 
 endl;
                }
                else
                    cout 
 "Failure: Not enough money" 
 endl;
            }
            else
                cout 
 "Failure: Invalid tile" 
 endl;
        }
        else
            cout 
 "Failure: Cell already has an owner" 
 endl;
    }
    else
        cout 
 "Failure: Invalid cell" 
 endl;
    if(is_discard_tile)
        available.replaceAt(0);
    return false;  
 player does not want to quit
}
Game.h
Game.h
A module to represent the complete state of the game.
#pragma once
#include #include "BoardSize.h"
#include "CellId.h"
#include "Tile.h"
#include "Board.h"
#include "AvailableTiles.h"
Game
A class to represent the complete state of the game.
class Game
{
public:
    Game ();
    void printState (unsigned int whose_turn) const;
    void handleDiceRoll (unsigned int whose_turn);
    bool puchaseTile (unsigned int whose_turn);
private:
    Board board;
    AvailableTiles available;
};
Main.cpp
Main.cpp
  Main.cpp
  The main program for Assignment 4.
  For Dr. Hamilton's CS 115 class, 202110 (Winter) term.
  Name: ___________________
  Student number: _________
#include #include #include #include "Dice.h"
#include "Player.h"
#include "Game.h"
using namespace std;
const int POINTS_TO_WIN = 5;
int main ()
{
    
 setup
    diceInit();
    string player_names[2] = { "Alice", "Bob" };
    playerInit(2, player_names);
    Game game;
    cout 
 "Welcome to the game." 
 endl;
    
 run main loop
    unsigned int cu
ent_player = 0;
    bool is_quit = false;
    
    do
    {
        cout 
 endl;
        cout 
 endl;
        assert(cu
ent_player < playerGetCount());
        game.printState(cu
ent_player);
        game.handleDiceRoll(cu
ent_player);
        cout 
 endl;
        is_quit = game.puchaseTile(cu
ent_player);
        cu
ent_player++;
        if(cu
ent_player >= playerGetCount())
            cu
ent_player = 0;
    }
    while (!is_quit && !playerHasPointsAnyone(POINTS_TO_WIN));
    
 print end messages
    cout 
 endl;
    cout 
 endl;
    for(unsigned int p = 0; p < playerGetCount(); p++)
    {
        playerPrint(p);
    }
    cout 
 endl;
    cout 
 "Thank you for playing!" 
 endl;
    return 0;  
 program exited without crashing
}
Player.cpp
Player.cpp
  Player.cpp
#include #include #include #include #include "Player.h"
using namespace std;
const unsigned int START_MONEY  = 0;
const unsigned int START_DICE   = 1;
const unsigned int START_POINTS = 0;
struct Playe
{
    string name;
    int money;
    int dice;
    int points;
};
static Player players[PLAYER_COUNT_MAX];
static unsigned int player_count = 0;
static bool isInvariantTrue ()
{
    if(player_count > PLAYER_COUNT_MAX)
        return false;
    for(unsigned int i = 0; i < player_count; i++)
        if(players[i].name == "")
            return false;
    return true;
}
void playerInit (unsigned int player_count1,
                 const string names[])
{
    assert(isInvariantTrue());
    assert(player_count1 >= PLAYER_COUNT_MIN);
    assert(player_count1 <= PLAYER_COUNT_MAX);
    for(unsigned int i = 0; i < player_count1; i++)
        assert(names[i] != "");
    player_count = player_count1;
    for(unsigned int i = 0; i < player_count; i++)
    {
        players[i].name = names[i];
        players[i].money  = START_MONEY;
        players[i].dice   = START_DICE;
        players[i].points = START_POINTS;
    }
    assert(isInvariantTrue());
}
unsigned int isInitialized ()
{
    assert(isInvariantTrue());
    if(player_count >= PLAYER_COUNT_MIN &&
       player_count <= PLAYER_COUNT_MAX)
    {
        return true;
    }
    else
        return false;
}
unsigned int playerGetCount ()
{
    assert(isInvariantTrue());
    assert(isInitialized());
    return player_count;
}
unsigned int playerGetIndex (const string& name)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(name != "");
    for(unsigned int i = 0; i < player_count; i++)
    {
        if(players[i].name == name)
            return i;
    }
    
 if we get here, there was no player with name name
    return NO_SUCH_PLAYER;
}
void playerPrint (unsigned int player_index)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    cout        
 setw(8) 
 left 
 players[player_index].name
         
 "$" 
 setw(4) 
 left 
 players[player_index].money
         
 "#" 
 setw(4) 
 left 
 players[player_index].dice
         
 "*" 
 setw(4) 
 left 
 players[player_index].points 
 endl;
}
const string& playerGetName (unsigned int player_index)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    return players[player_index].name;
}
char playerGetTileChar (unsigned int player_index)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(players[player_index].name.size() > 0);
    return players[player_index].name[0];
}
ool playerHasMoney (unsigned int player_index,
                     int money)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(money >= 0);
    if(players[player_index].money >= money)
        return true;
    else
        return false;
}
ool playerHasDice (unsigned int player_index,
                    int dice)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(dice >= 0);
    if(players[player_index].dice >= dice)
        return true;
    else
        return false;
}
ool playerHasPointsAnyone (int points)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(points >= 0);
    for(unsigned int i = 0; i < player_count; i++)
    {
        if(players[i].points >= points)
            return true;
    }
    return false;
}
void playerIncreaseMoneyAndPrint (unsigned int player_index,
                                  int increase)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(increase >= 0);
    int old_money = players[player_index].money;
    players[player_index].money += increase;
    int new_money = players[player_index].money;
    cout 
 players[player_index].name 
 "'s money:"
         
   " $" 
 old_money
         
 " + $" 
 increase
         
 " = $" 
 new_money 
 endl;
    assert(isInvariantTrue());
}
void playerIncreaseDiceAndPrint (unsigned int player_index,
                                 int increase)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(increase >= 0);
    int old_dice = players[player_index].dice;
    players[player_index].dice += increase;
    int new_dice = players[player_index].dice;
    cout 
 players[player_index].name 
 "'s dice:"
         
   " #" 
 old_dice
         
 " + #" 
 increase
         
 " = #" 
 new_dice 
 endl;
    assert(isInvariantTrue());
}
void playerIncreasePointsAndPrint (unsigned int player_index,
                                   int increase)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(increase >= 0);
    int old_points = players[player_index].points;
    players[player_index].points += increase;
    int new_points = players[player_index].points;
    cout 
 players[player_index].name 
 "'s points:"
         
   " *" 
 old_points
         
 " + *" 
 increase
         
 " = *" 
 new_points 
 endl;
    assert(isInvariantTrue());
}
void playerDecreaseMoney (unsigned int player_index,
                          int decrease)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(decrease >= 0);
    assert(playerHasMoney(player_index, decrease));
    assert(players[player_index].money >= decrease);
    players[player_index].money -= decrease;
    assert(isInvariantTrue());
}
void playerDecreaseDice (unsigned int player_index,
                         int decrease)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(decrease >= 0);
    assert(playerHasDice(player_index, decrease));
    assert(players[player_index].dice >= decrease);
    players[player_index].dice -= decrease;
    assert(isInvariantTrue());
}
Player.h
Player.h
A module to keep track of the information for the players.
Each player has a name and an amount of money, dice, and
points. The amount of money and the number of dice can be
increased and decreased, while the number of points can
only be increased.
This is an encapsulated global service.
#pragma once
#include PLAYER_COUNT_MIN
The minimum number of players in the game.
const unsigned int PLAYER_COUNT_MIN = 1;
PLAYER_COUNT_MAX
The maximum number of players in the game.
const unsigned int PLAYER_COUNT_MAX = 4;
NO_SUCH_PLAYER
A special value indicating that there was not a player with
the requested name.
const unsigned int NO_SUCH_PLAYER = 999999;
playerInit
Purpose: To initialize the Player module for the specified
players. Each player starts with $0 money, #1 die,
and *0 points.
Parameter(s):
<1> count: The number of players in the game
<2> names: The player names
Precondition(s):
<1> count >= PLAYER_COUNT_MIN
<2> count < PLAYER_COUNT_MAX
<3> names[i] != "" WHERE 0 <= i < count
Returns: N/A
Side Effect: The players module is initialized to contain
count players with the first count names in
names. If the module was already initialized,
all infromation about the previous players is
lost.
void playerInit (unsigned int count,
const std::string names[]);
isInitialized
Purpose: To determine whether the player module has been
initialized.
Parameter(s): N/A
Precondition(s): N/A
Returns: Whether the player module is initialized.
Side Effect: N/A
unsigned int isInitialized ();
playerGetCount
Purpose: To determine the number of players in the game.
Parameter(s): N/A
Precondition(s):
<1> isInitialized()
Returns: How many players in the game.
Side Effect: N/A
unsigned int playerGetCount ();
playerGetIndex
Purpose: To determine the index of the player with the
specified name.
Parameter(s):
<1> name: The player name
Precondition(s):
<1> isInitialized()
<2> name != ""
Returns: The index of the player with name name. If there
isn't a player with that name, NO_SUCH_PLAYER is
returned.
Side Effect: N/A
unsigned int playerGetIndex (const std::string& name);
playerPrint
Purpose: To print the information for the specified player.
Parameter(s):
<1> player_index: Which playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
Returns: N/A
Side Effect: The name, money, dice, and points for playe
player_index is printed to standard output
(cout).
void playerPrint (unsigned int player_index);
playerGetName
Purpose: To determine the specified player's name.
Parameter(s):
<1> player_index: Which playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
Returns: The name of player player_index.
Side Effect: N/A
const std::string& playerGetName (unsigned int who);
playerGetTileCha
Purpose: To determine the character that the specified
player uses to mark tile ownership.
Parameter(s):
<1> player_index: Which playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
Returns: The char used to show that player player_index owns
a tile.
Side Effect: N/A
char playerGetTileChar (unsigned int player_index);
playerHasMoney
Purpose: To determine if the specified player has at least
the specified amount of money.
Parameter(s):
<1> player_index: Which playe
<2> money: How much money to check fo
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> money >= 0
Returns: Whether player player_index has at least money
money.
Side Effect: N/A
ool playerHasMoney (unsigned int player_index,
int money);
playerHasDice
Purpose: To determine if the specified player has at least
the specified number of dice.
Parameter(s):
<1> player_index: Which playe
<2> dice: How many dice to check fo
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> dice >= 0
Returns: Whether player player_index has at least dice dice.
Side Effect: N/A
ool playerHasDice (unsigned int player_index,
int dice);
playerHasPointsAny
Purpose: To determine if any player has at least the
specified number of points.
Parameter(s):
<1> points: How many points to check fo
Precondition(s):
<1> isInitialized()
<2> points >= 0
Returns: Whether any player has at least points points.
Side Effect: N/A
ool playerHasPointsAnyone (int points);
playerIncreaseMoneyAndPrint
Purpose: To give the specified player the specified amount
of additional money.
Parameter(s):
<1> player_index: Which playe
<2> increase: How much money to give the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> increase >= 0
Returns: N/A
Side Effect: Player player_index gains increase money. The
change to the player's money is printed,
including the player name.
void playerIncreaseMoneyAndPrint (unsigned int player_index,
int increase);
playerIncreaseDiceAndPrint
Purpose: To give the specified player the specified numbe
of additional dice.
Parameter(s):
<1> player_index: Which playe
<2> increase: How many dice to give the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> increase >= 0
Returns: N/A
Side Effect: Player player_index gains increase dice. The
change to the player's number of dice is
printed, including the player name.
void playerIncreaseDiceAndPrint (unsigned int player_index,
int increase);
playerIncreasePointsAndPrint
Purpose: To give the specified player the specified numbe
of additional points.
Parameter(s):
<1> player_index: Which playe
<2> increase: How many points to give the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> increase >= 0
Returns: N/A
Side Effect: Player player_index gains increase points. The
change to the player's points is printed,
including the player name.
void playerIncreasePointsAndPrint (unsigned int player_index,
int increase);
playerDecreaseMoney
Purpose: To reduce the specified player's money by the
specified amount.
Parameter(s):
<1> player_index: Which playe
<2> decrease: How much money to take from the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> decrease >= 0
<4> playerHasdDice(player_index, decrease)
Returns: N/A
Side Effect: Player player_index loses decrease money.
void playerDecreaseMoney (unsigned int player_index,
int decrease);
playerDecreaseDice
Purpose: To reduce the specified player's number of dice by
the specified amount.
Parameter(s):
<1> player_index: Which playe
<2> decrease: How many dice to take from the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> decrease >= 0
<4> playerHasdDice(player_index, decrease)
Returns: N/A
Side Effect: Player player_index loses decrease dice.
void playerDecreaseDice (unsigned int player_index,
int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here