Question: Complete the make_move() function that handles a single move in Connect Four. This function takes 3 parameters: The string player , representing the player making
Complete the make_move() function that handles a single move in Connect Four. This function takes 3 parameters:
- The string player, representing the player making the move. You can assume that the player will either be "X" or "O".
- The integer column, representing the column in which the player wants to place their disc. The first column is numbered 0, the second column is numbered 1 and so on.
- The list of strings board, representing the Connect Four board. The list has a length of 6. Each element of the list is a string of length 7 and represents a row on the board. The string at index 0 of the board is the top row, the string at index 1, the row below that, and so on. In the row string, the characters "0" and "X" represent player discs while the character "*" represents an empty slot.
When a player makes an invalid move, i.e. attempts to insert a disc into a column that is full, the function should print a message informing the player that the move is invalid. The board remains unchanged. When a player makes a valid move, the lowest row on the board with a vacant space in the selected column, should have its string updated so that the player character appears in this location. You can assume that only valid values for the 3 parameters will be passed to the function.
Some examples of the function being used are shown below. Please note that the draw_board() function has been provided for you. You must not change its implementation.
For example:
| Test | Result |
|---|---|
board = ["*******", "*******", "XO*****", "OX*****", "XO*****", "OX*****"] print("Before:") draw_board(board) print() make_move("X", 1, board) print("After:") draw_board(board) | Before: * * * * * * * * * * * * * * X O * * * * * O X * * * * * X O * * * * * O X * * * * * After: * * * * * * * * X * * * * * X O * * * * * O X * * * * * X O * * * * * O X * * * * * |
board = ["*OX****", "*XO****", "*OX****", "*XO****", "*OX****", "*XO****"] print("Before:") draw_board(board) print() make_move("X", 1, board) print("After:") draw_board(board) print() | Before: * O X * * * * * X O * * * * * O X * * * * * X O * * * * * O X * * * * * X O * * * * Invalid move X, column 1 is full! After: * O X * * * * * X O * * * * * O X * * * * * X O * * * * * O X * * * * * X O * * * * |
board = ["*******", "*******", "XO*****", "OX*****", "XO*****", "OX*****"] print("Before:") draw_board(board) print() make_move("X", 2, board) make_move("O", 3, board) make_move("X", 2, board) print("After:") draw_board(board) | Before: * * * * * * * * * * * * * * X O * * * * * O X * * * * * X O * * * * * O X * * * * * After: * * * * * * * * * * * * * * X O * * * * * O X * * * * * X O X * * * * O X X O * * * |
Answer:(penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %)
1
2
3
4
5
6
7
8
9
def make_move(player, column, board):
def draw_board(board):
for row in board:
for item in row:
print(" " + item + " ", end="")
print()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
