src | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
README.md |
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.