Question: Overview I keep getting wrong code!! Make sure the output is the same. Please make sure that I can copy and paste the code. This
Overview
I keep getting wrong code!! Make sure the output is the same. Please make sure that I can copy and paste the code.
This lab is designed to introduce you to D lists by recreating one of everyones favorite childhood games: ConnectFour. You will loop through lists and manipulate them. Your end product should be robust enough to not have a single outofbounds exception.
Submission Instructions
After completing all programs, please submit your py files labeled with the lab number.
For example: Labpy
Specification
You will first start by asking the user for what they wish the height and length of the board to be:
What would you like the height of the board to be
What would you like the length of the board to be
Then you will print the empty board:
And tell the players what their tokens are:
Player : x
Player : o
The players will take turns placing their tokens by choosing columns...
Player : Which column would you like to choose?
x
Player : Which column would you like to choose?
x o
until one of them wins!
Player : Which column would you like to choose?
x
x
x o
x o x o o
Player won the game!
Or until there is a tie!
Player : Which column would you like to choose?
o x o x o
x o o x x
x o o o x
x o x o x
Draw. Nobody wins.
Elements in the Dlist should be accessible via rowmajor indexing boardrowcolumn In addition, you should follow the structure by storing the chips eg inserting x in column and then inserting o in column in a D list starting from row :
Row x o
Row
Row
Row
When printing the board, you should print the board upside down by printing from the last row which is row in our example So that your output on the console after calling printboardboard would be:
x o
Assumptions and Notes
Students can assume that:
the user will choose for the board dimensions to be x or greater.
the user will input a valid column number from to length
the column that the user chooses to place their token into has space it is not filled already by other tokens
players can only win vertically or horizontally, but not diagonally.
Program Methods
def initializeboardnumrows, numcols
This will take in the numrow and numcols from user input and this will set each spot in the list to A D character list with each spot set to be will be returned.
def printboardboard
This will take in the D character list for the board and print the board.
def insertchipboard col, chiptype
This will take in the D character list for the board. This function places the token x or o denoted as chiptype in the column that the user has chosen. Will find the next available spot in that column if there are already tokens there. The index of the row that the token is placed in is returned.
def checkifwinnerboard col, row, chiptype
This will take in the D character list for the board. After a token is added, checks whether the token in this location, of the specified chip type, creates four in a row. Will return True if someone won, and False otherwise.
Hint: Implement the methods in this order.
Sample Submission Output
What would you like the height of the board to be
What would you like the length of the board to be
Player : x
Player : o
Player : Which column would you like to choose?
x
Player : Which column would you like to choose?
x o
Player : Which column would you like to choose?
x
x o
Player : Which column would you like to choose?
x
x o o
Player : Which column would you like to choose?
x
x
x o o
Player : Which column would you like to choose?
x
x
x o o o
Player : Which column would you like to choose?
x
x
x o x o o
Player : Which column would you like to choose?
x
x o
x o x o o
Player : Which column would you like to choose?
x
x
x o
x o x o o
Player won the game!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
