Skip to content
← Back to Community
How to make connect 4 in python
Profile icon
larsjansen1

I'm really curious how to make the game connect 4 in python. if someone can help me with it (because i get stuck at the first minute) then I would be really happy. :)

Voters
Profile icon
623Liam
Profile icon
lightningrock
Profile icon
larsjansen1
Comments
hotnewtop
Profile icon
lightningrock

I think if you don't want to use the turtle or something else then maybe you make a board out of 0s and the user could enter a number and it would change to a 1. Then the computer would randomly geanortater a number and it would be 3.
If this helped please mark it as an answer.

Profile icon
larsjansen1

@lightningrock i now made a code of it. the only problem i face now is that it only gives the win to a player when he has 4 in a row (in a 4x4 grid) or 5 in a row (in a 5x5 grid) and so on. how can i code it that it only has to be 4 in a row no matter the size of the grid.

Profile icon
lightningrock

can u invite me to the repl?
@larsjansen1

Profile icon
larsjansen1
Profile icon
lightningrock

ok i joined @larsjansen1

Profile icon
larsjansen1

@lightningrock thats nice! Can you let me know when you tried to fix it?

Profile icon
lightningrock
Profile icon
lightningrock

i'm not rly good at python im a beginner but um.. maybe this will help https://repl.it/@lightningrock/ContentIntelligentIntercept
(note:the code is not fully written by me and in your code the prompts are a little hard to understand)
@larsjansen1