VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Connect Four Python Game Tutorial with pygame

Connect Four Python Game Tutorial with pygame

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Learn how to program Connect Four in Python 3 and pygame. First, see how to store the board state, and build a simple command line interface for dropping pieces. Then see how to write a function to check for wins. Finally, learn to build graphics for your game. -Code: https://github.com/KeithGalli/Connect4-Python -How to setup Python 3 and Sublime text: https://www.youtube.com/watch?v=2nQNsrhaMpA -SublimeREPL: https://packagecontrol.io/packages/SublimeREPL Video from Keith Galli. https://www.youtube.com/channel/UCq6XkhO5SZ66N04IcPbqNcw
Date: 2022-03-14

Comments and reviews: 10


I think it's a good tutorial but I found the code to be, say, not simplified?
Range only counts to column count - 1 or row count -1.
The grid starts at [0][0]
You had to flip it
Then you had to offset it when making the graphics
You almost used paradoxical loops
In a single line you used the variable SQUARESIZED like 20 times
I understand why you did all of that, I just found it hard to keep track of the loops as you went through it because I felt it was needlessly complex. I did manage to understand what was going on in mine working though so thank you. Just difficult for a beginner to track because the code is, I dare say, a tad bit messy.

reply

Hi I'm pretty new to python, I've got until min 26 and I'm getting this error
Traceback (most recent call last):
File -connect4.py-, line 75, in
print_board(board)
File -connect4.py-, line 41, in print_board
print(np.flip(board,0))
AttributeError: 'module' object has no attribute 'flip'
---Repl Closed---
IF anyone knows and wanna help me it will be greatly appreciate it !

reply

I am a beginner programmer at 73 years of age... And, my first try at programming was your video of how to create a Connect4 game...Brilliantly explained! Only one thing did not work: the input function did not recognize integers, so I had to put the int() function in the input. I think it was because I could not install the SimplyREPL module
reply

I know this video is kinda old but i had a question. I wrote the code alongside you but i had a bug where my code wouldn't stop showing the board over and over and over. I checked as much as i could but didn't find any significant changes apart from some var names and dif names which i made sure were correct.
reply

I got as far as checking for winners, for some reason that code isnt working, there is no way in hell id be able to come up with a solution on my own =( idk if coding if for me, im not smart enough. i can only copy others code. my own code never works =(
reply

Whenever I run the code in PyCharm the entire column gets filled with pieces anytime I click on a single column. The pieces alternate in color. It's like the turn is running on its own until the column fills with pieces
reply

If you would have iterated in a reverse way in the get_next_row() function,
Like this: for r in range(ROW_COUNT-1, -1, -1)
It would have saved you a lot of time and work in flipping.

reply

Great tutorial, everything worked perfectly except for the pygame QUIT event. I don't get any errors, but the game just doesn't close when I click the close button.
reply

Finally created the game and learnt a lot from this game.
Thank u soo much for creating such a helpful video Keith Galli!!
Ahh I am 2 years late :)

reply

thanks for your video, my question is... what if the size is not 6x7 but a number chosen by the player? how do you check winners?
reply
Add a review, comment






Other channel videos