Question: 10. (total 25 points) Consider the Connect Four web service that you wrote for your PHP assignment. A Connect Four board consists of mx n

 10. (total 25 points) Consider the Connect Four web service that

you wrote for your PHP assignment. A Connect Four board consists of

mx n places and each place of a board is uniquely identified

10. (total 25 points) Consider the Connect Four web service that you wrote for your PHP assignment. A Connect Four board consists of mx n places and each place of a board is uniquely identified by a pair of 0-based column and row indices. Below you are to write partial code for two classes: Place and Board. 6.0 Board Place 0.6 6,6 empty Occupied (a) (5 points) As shown above, each place of a board is represented by an instance of the Place class. Write the missing constructor and the isEmpty() function of the Place class shown below. The constructor takes a pair of 0-based column/row indices, say $x and $y, and creates an empty place. The isEmpty function tests if a place is unoccupied. class Place { private $x; // 0-based column, or slot, index of this place private Sy; // 0-based row inder of this place private Splayer; // occupant of this place function isEmpty() { ... } function set Player (player) {...} function getX() { ... } function getYO { ... } } (b) (5 points) Write the missing constructor of the Board class that takes two parameters, $width and $height. It should create an appropriate number of places and store them in an one-dimensional array $places; see the next two questions for the use of the array. class Board { private Swidth; // number of columns private Sheight; // number of rous private Splaces; // 1-d array containing all the places of this board function getPlace(8x, $y) {...} // to be written in (c) below function dropln($x, Splayer) { ... } // to be written in (d) below } (c) (7 points) Write the getPlace() function of the Board class shown in Question 10b above. The getPlace() function returns the specified place; if the given column or row index is invalid, it returns null. Hint: use the foreach statement to iterate over all places of a board and find the specified place. (d) 8 points) Write the dropIn() function of the Board class shown in Question 10b above. The function takes a column index ($x) and a player ($player) and lets the player occupy the lowest available place within the column. If the given index is invalid or the column is full, it has no effect. 10. (total 25 points) Consider the Connect Four web service that you wrote for your PHP assignment. A Connect Four board consists of mx n places and each place of a board is uniquely identified by a pair of 0-based column and row indices. Below you are to write partial code for two classes: Place and Board. 6.0 Board Place 0.6 6,6 empty Occupied (a) (5 points) As shown above, each place of a board is represented by an instance of the Place class. Write the missing constructor and the isEmpty() function of the Place class shown below. The constructor takes a pair of 0-based column/row indices, say $x and $y, and creates an empty place. The isEmpty function tests if a place is unoccupied. class Place { private $x; // 0-based column, or slot, index of this place private Sy; // 0-based row inder of this place private Splayer; // occupant of this place function isEmpty() { ... } function set Player (player) {...} function getX() { ... } function getYO { ... } } (b) (5 points) Write the missing constructor of the Board class that takes two parameters, $width and $height. It should create an appropriate number of places and store them in an one-dimensional array $places; see the next two questions for the use of the array. class Board { private Swidth; // number of columns private Sheight; // number of rous private Splaces; // 1-d array containing all the places of this board function getPlace(8x, $y) {...} // to be written in (c) below function dropln($x, Splayer) { ... } // to be written in (d) below } (c) (7 points) Write the getPlace() function of the Board class shown in Question 10b above. The getPlace() function returns the specified place; if the given column or row index is invalid, it returns null. Hint: use the foreach statement to iterate over all places of a board and find the specified place. (d) 8 points) Write the dropIn() function of the Board class shown in Question 10b above. The function takes a column index ($x) and a player ($player) and lets the player occupy the lowest available place within the column. If the given index is invalid or the column is full, it has no effect

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!