In this blog post you will use Python Code to complete this simulation of the game of connect 4. (Rules of the game)
You will first need to reverse-engineer the code provided. The code so far is used to:
- Display the 6×7 grid using Python Turtle.
- Randomly place tokens on the gird, taking turns (yellow and red).
- Refresh the grid on the screen using the drawGrid() function.
The code provided uses a variable called connect4, use to store a two-dimensional array (6×7) of integer values. In Python, a 2D-array is a list of lists. Within this array, a 0 represents an empty place, a 1 represents a yellow token and a 2 represents a red token.
Complete the checkIfWinner() function (from line 39) to check if after placing the token the game continues or if the player has aligned 4 tokens either in a row, column or diagonal. If so the function will return the color value of the winner (1 for Yellow, 2 for Red, 0 if no winner)