Jan-13-2021, 02:21 PM
Hello team,
I have this assignment to do:
1. Draw the board
2. Update the board with user input
3. Verify if there is 4 across or diagonal to end the game
So far I just manage to come up with the first step, it looks like that:
Firstly I want to make the function add an 'X' or 'O' to the bottom row , or the 8th row, of the column the user input. Then check if it is not ' ', and add to the 7th row and so on.
I have it clear in my mind but I cannot code it.
Any thoughts are most welcome.
I have this assignment to do:
Quote:I broke it down into three steps:
Have you ever played "Connect 4"? It's a popular kid's game by the Hasbro company. In this project, your task is create a Connect 4 game in Python. Before you get started, please watch this video on the rules of Connect 4:
https://youtu.be/utXzIFEVPjA
Once you've got the rules down, your assignment should be fairly straightforward. You'll want to draw the board, and allow two players to take turns placing their pieces on the board (but as you learned above, they can only do so by choosing a column, not a row). The first player to get 4 across or diagonal should win!
Normally the pieces would be red and black, but you can use X and O instead.
1. Draw the board
2. Update the board with user input
3. Verify if there is 4 across or diagonal to end the game
So far I just manage to come up with the first step, it looks like that:
''' 012345678 | | | | 0 --------- 1 | | | | 2 --------- 3 | | | | 4 --------- 5 | | | | 6 --------- 7 | | | | 8 ''' def drawField(): for row in range(9): if row % 2 == 0: for column in range(9): if column % 2 == 0: if column != 8: print(' ', end='') else: print(' ') else: print('|', end='') else: print('-'*9) drawField() player = 1 currentField = [' ', ' ', ' ', ' ', ' '] drawField() while(True): print(f'Players {player} turn') move = int(input('Column: ')) if player == 1: currentField[move] == 'X' player = 2 else: currentField[move] == 'O' drawField(currentField)What I am struggling with is to update the board with the user's input.
Firstly I want to make the function add an 'X' or 'O' to the bottom row , or the 8th row, of the column the user input. Then check if it is not ' ', and add to the 7th row and so on.
I have it clear in my mind but I cannot code it.
Any thoughts are most welcome.