Question: Connect 4 win function and Tostring(grid) Edit View Go Tools Window Help BE Fri Mar 12 8:02 PM 1005-W21-Assignment3-UPDATED.pdf Page 3 of 6 Q Search

Connect 4 win function and Tostring(grid)Connect 4 win function and Tostring(grid) Edit View Go Tools Window Help

Edit View Go Tools Window Help BE Fri Mar 12 8:02 PM 1005-W21-Assignment3-UPDATED.pdf Page 3 of 6 Q Search Next, make a function called win(grid, column) that retums a string. The function checks if a player has won the game (four checkers of the same colour in a row, column or diagonal) or not. The specified column is the last column in which the piece was played in the game (this should make it easier to check if that last play was a winning play). If a player has won the game then the function returns the checker name ('red' or 'black') that won. Otherwise, it returns empty'. To make the function more robust, it should also return 'empty' if the input column is out of the valid range of columns or if there is no piece played in the specified column. Next, make a function called toString(grid) that returns a string representation of the game. The checker 'red' will be represented by an 'X', the checker 'black' will be represented by an 'o' and empty locations will be represented by a single space (" "). The string must contain newline characters, border characters (I' pipes, 'dashes and '+'pluses) and labels (numbering) of the rows and columns. The format of the output string should follow this example: 2] 2] >>> grid = makeGrid(4,5) >>> play(grid, 1, 'red') True >>> play (grid, 1, 'black') True >>> play(grid, 3, 'red') True >>> print( toString(grid)) I 10 1 11 10 12 | XX13 +-----+ 01234 Put all FOUR functions in a file called connect4.py

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!