Connect 4 Terminal game

Here’s a link to the github repo for the game, simply run Connect4.py and off you go. It’d be awesome to get some feedback on what I can do differently, or better, or even things I managed to do well.

Cheers,

codeNewb

2 Likes

My version is here

2 Likes

@digitalsolver96493 Your code is years beyond of mine, can’t say nothing bad. You managed all this too well, as for me. Congrats!

1 Like

Both of you guys beat me. Here’s my repo lmao

I have 627 lines of code… think I got to learn some stuff over the next few weeks about being concise :v

1 Like

I was pretty disgusted at how unnecessarily long my original code was, so I did it again taking inspiration from how I remembered OP’s repository looking - specifically how it used class and a two-dimensional list instead of uh… my original idea… (anyway see the new repo).

I got stuck on the inputter function because I forgot “break” was a thing for a bit. I had to directly look at your code for that, OP.

However, I managed to do the rest by myself (with a lot of googling - and through trying to remember how OP used class and the 2dlist, honestly). I reviewed both of our code afterwards, and it’s kind of interesting that we both did the thing where it checks diagonals going from left to right and then right to left afterwards. I was trying to come up with a more concise way of doing it, but I honestly couldn’t come up with anything… maybe it’s not that interesting given I literally looked through your whole code a few days ago. My memory’s terrible, but still.

Anyway I feel more comfortable with OOP now… so this was a good exercise…

But really, is there a more concise way to check diagonal lines? The vertical and horizontal checkers are quite good, but yeah, think the diagonal one could be condensed somehow.

1 Like

I was thinking about a better/quicker way of checking, but I think anything faster would be pretty complex. I also have the same problem of looking at code then immediately forgetting syntax. But it seems to be improving the more I force myself to remember.

1 Like

That’s some nice looking code! :laughing: I like the use of a class to hold everything together and that it makes referencing stuff easy and clean.

What I would do different is I would add a bit of validation to the user input. Asking them to use a single character when choosing a team is nice, but it is better to set it as a rule and be sure they’re starting a match that’s playable.
Another thing I noticed is that your code doesn’t check for a tie so it keeps going even after all the columns are full.

Anyhow, here’s my version of the game on GitHub

1 Like

Thanks!

Yeah I realized I hadn’t checked for a tie after looking at lolwhatyesme’s code. I’ll likely put out an update in the next week or so when I have time. As well as the user input bug. Thanks for the recommendations!

1 Like