Skip to content
Sign upLog in
← Back to Community

Connect Four

Profile icon
Trapdoorspyder

Nice Connect Four game I made in python. I've added a lot of little quality of life features that not everybody might notice, but make the game a much more enjoyable experience to play and win. Feel free to give feedback!

To play:
Red and Blue will alternate turns automatically. The loser of the previous game will go always go first in the next.
To make a play, all you have to do is type in the number of the row you want to play in and press enter.

Enjoy!

Note: If you encounter any errors, please put down in the comments the board state from when it happened and what the most recent play was. Thanks!

Voters
Profile icon
ElvisColon
Profile icon
Reecemcmorrin
Profile icon
TristenAengus
Profile icon
firedragondnd
Profile icon
JarishaanThirus
Profile icon
Jakman
Profile icon
BobTheTomatoPie
Profile icon
ohyea
Profile icon
asdjfhjasdhfelh
Profile icon
PizzaMan21
Comments
hotnewtop
Profile icon
MyloBishop

Cool! It would be cool if you could add an AI for the game!

Profile icon
Trapdoorspyder

Working on it...

Profile icon
CodingCactus

i don't know if this is a problem with repl.it or your code, but when i type a number, then press backspace, it deletes the prompt??

Profile icon
Trapdoorspyder

I've noticed that happening, but I'm not sure if there is really anything wrong with the code. It's just a basic input command.

Profile icon
CodingCactus

@Trapdoorspyder
ok, maybe report it (https://repl.it/bugs)

Profile icon
Trapdoorspyder

I might do that. I did manage to fix it though, instead of printing text and sticking the input on the end of it, which is how it was before, I'm just doing the whole thing as an input. It does result in a bit more code, but that's fine.

Profile icon
CodingCactus

@Trapdoorspyder
surely a one line input (choice = input("blah")) would be less code than

print("blah") choice = input()
Profile icon
Trapdoorspyder

I was doing it that way because unlike your example, I actually had an if statement before, so it looked more like this:

if(this):
print("blah")
else:
print("meh")
choice = input()

Also, how did you get the text to go in a box like that?

Profile icon
CodingCactus

@Trapdoorspyder
put three backticks above it

Profile icon
CodingCactus

@Trapdoorspyder
even in there, a one line input would be better:

if (this): choice = input("blah") else: choice = input("meh")
Profile icon
CodingGoose

I used to play this Game so much when I was little. This game is So Cool. I love the winning screen too

Profile icon
[deleted]

@Trapdoorspyder

COOL!

but how did you do the board, like the double vertical line thing?

Profile icon
CodingCactus

@blackjkl
it's an ascii character

Profile icon
[deleted]

@CodingCactus

I know but how to you type it?

Profile icon
CodingCactus

@blackjkl
either:
alt + [some 3 digit number on kepad]
or
copy paste

Profile icon
Trapdoorspyder

I copy/pasted from this website:
https://fsymbols.com/keyboard/windows/alt-codes/list/
You can also find them at the bottom of the code for the connect four game.

Profile icon
MyloBishop

Did you program in every possible win? Thats a very inefficient way of doing it.

Profile icon
Trapdoorspyder

Kind of. I have a for loop for each direction checking all the ones in that direction. Not great, but not horrible.

Profile icon
tyolmedo

𝙘𝙤𝙤𝙡

Profile icon
PizzaMan21

Nice game dude

Profile icon
Hihi21

nice

Profile icon
R_Gaspar

Nice Game. Now I want to replicate it in Java. Try this game out. I would like to see your Python version for this, if you're looking for a small challenge. Your choice to do either, but to whatever you choose to do, enjoy it!
https://repl.it/@R_Gaspar/Tic-Tac-Toe

Profile icon
Trapdoorspyder

@R_Gaspar I just might do that once I'm done with the bot for this game that I'm working on.

Profile icon
R_Gaspar

@Trapdoorspyder
A bot? That's interesting... Let me know how it turns out. Never tried AI or "AI" on a game before. I think the Tic-Tac-Toe could use a bot.

Profile icon
VMTU

𝙘𝙤𝙤𝙡

Profile icon
TheFatBananaMan

𝙘𝙤𝙤𝙡

Profile icon
[deleted]

I lUV iTTT 💕 I wish I can make a code like u did T^T

Profile icon
mwilki7

you should use emojis for the pieces
🔴🔵

Profile icon
Trapdoorspyder

Unfortunately, the emojis end up off center, so they won't work. It was a good idea though!

Profile icon
[deleted]

Cool Game!!

Profile icon
thenullified

:)

Profile icon
BlueComet

_Nice job_

could you make a bot

Profile icon
Trapdoorspyder

I've been thinking about adding an AI for solo play in the future, but it will take a bit of time. I do intend to do it though, at least at some point.

Profile icon
BraylanBB121

I got an error message, it says line 96 if(b6[].....)
IndexError: List index out of range.

Profile icon
Trapdoorspyder

Yup. Just fixed that one. I knew it existed, but couldn't figure out what was causing it. I figured out what was wrong and now it's all good! (hopefully)
Essentially, it was trying to detect wins and tried to look off of the board.

Profile icon
BraylanBB121

Ok. Thank you.

@Trapdoorspyder

Profile icon
BraylanBB121

I love it! The ONLY thing I would suggest (very small suggestion) is that make the background color of whoever wins, make it that color.

Profile icon
Trapdoorspyder

I'm not sure if that's possible with Python, but if it is, I will most certainly do it.

Profile icon
BraylanBB121

You can do it very easily with the module 'colorama'

@Trapdoorspyder

Profile icon
Trapdoorspyder

Thanks! In the meantime until I implement that, I have spruced up the 'You win' message a little bit.

Profile icon
BraylanBB121

The most recent play was Blue: 1st row, 4th column.

Profile icon
BraylanBB121

The new winning text looks great!

@Trapdoorspyder

Profile icon
Trapdoorspyder

Glad you appreciate it!

Profile icon
python9160

@BraylanBB121
or you could use ansi escape codes like
'\u001b[31m' for red and '\u001b[31m' for blue

Profile icon
Bookie0

Very cool I like it!

Profile icon
ChezCoder

nice! Would be awesome if you made it multiplayer. I can only play it with myself :(

Profile icon
Trapdoorspyder

Unfortunately, I don't know how to do that currently, but I will attempt to implement that sometime. Thanks for the feedback!

Profile icon
ChezCoder

@Trapdoorspyder
I will be willing to help

Profile icon
Trapdoorspyder

Thanks!

Profile icon
HenryCommandeur

I can't use it for some reason. Too bad I bet it was great. :v(

Profile icon
Trapdoorspyder

@HenryCommandeur
That's unfortunate. What kind of device are you on?

Profile icon
CodingCactus

very nice!!