the connect-4 game you can play with netcat
Find a file
2024-10-19 16:12:05 +02:00
src reverting the hidden difficulty shift by 2 to make it consistent with the original source 2024-10-19 16:07:20 +02:00
.gitignore added logging 2024-10-19 15:22:25 +02:00
Cargo.lock added logging 2024-10-19 15:22:25 +02:00
Cargo.toml added logging 2024-10-19 15:22:25 +02:00
README.md readme and attributions 2024-10-19 16:12:05 +02:00

TCP Connect 4

type nc cqql.site 1234 to start playing connect 4 against an ai in your terminal

Game

I just really wanted to make Connect 4 playable in the terminal from anywhere in the world without any installations (assuming you have netcat installed and using a linux terminal because who else would be the target demographic for this :3).

This is what you should see when you connect:

Connect 4
Choose your difficulty [1-9]: 3
Move 0:
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 1 2 3 4 5 6 7

Choose column: 5
[AI thinking]

Move 2:
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · ○ ● · · 
 1 2 3 4 5 6 7

Choose column: 5
[AI thinking]

Move 4:
 · · · · · · · 
 · · · · · · · 
 · · · · · · · 
 · · · · ○ · · 
 · · · · ● · · 
 · · · ○ ● · · 
 1 2 3 4 5 6 7

(and so on)

have fun! 🎉

Attributions

The AI behind this was coded by balkarjun, which I translated into Rust and got their permission to use it for this project, as long as it stays open source. I couldn't stop myself from using it after I saw how neatly it checks win conditions which I posted about on fedi.

The logic is written up in great detail on balkarjun's blog in this article: Exploring Board Game AI Algorithms: Minimax. It's worth a read, especially to learn more about traditional AI.

I coded the socket interface and then added a lot of logging just for coding practice. It you'd like a leaner version of the code, take a look at this commit.