Share your repls and programming experiences

← Back to all posts
Connect Four
Trapdoorspyder (105)

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!

Comments
hotnewtop
MyloBishop (2)

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

CodingCactus (4367)

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??

Trapdoorspyder (105)

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.

Trapdoorspyder (105)

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.

CodingCactus (4367)

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

print("blah")
choice = input()
Trapdoorspyder (105)

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?

CodingCactus (4367)

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

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

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

[deleted]

@Trapdoorspyder

COOL!

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

[deleted]

@CodingCactus
I know but how to you type it?

CodingCactus (4367)

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

Trapdoorspyder (105)

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.

MyloBishop (2)

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

Trapdoorspyder (105)

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

tyolmedo (2)

𝙘𝙤𝙤𝙡

R_Gaspar (0)

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

Trapdoorspyder (105)

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

R_Gaspar (0)

@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.

VMTU (45)

𝙘𝙤𝙤𝙡

[deleted]

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

mwilki7 (1133)

you should use emojis for the pieces
🔴🔵

Trapdoorspyder (105)

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

[deleted]

Cool Game!!

BlueComet (116)

_Nice job_

could you make a bot

Trapdoorspyder (105)

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.

BraylanBB121 (42)

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

Trapdoorspyder (105)

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.

BraylanBB121 (42)

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.

Trapdoorspyder (105)

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

BraylanBB121 (42)

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

Trapdoorspyder (105)

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

BraylanBB121 (42)

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

BraylanBB121 (42)

The new winning text looks great! @Trapdoorspyder

Trapdoorspyder (105)

Glad you appreciate it!

FidgetDaHacker2 (5)

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

Bookie0 (6297)

Very cool I like it!

ChezCoder (1605)

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

Trapdoorspyder (105)

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

HenryCommandeur (2)

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

Trapdoorspyder (105)

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