Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Are auditors responsible for catching material fraud?

Answered: 1 week ago

Question

To find integral of sin(logx) .

Answered: 1 week ago