57 lines
No EOL
1.9 KiB
Markdown
57 lines
No EOL
1.9 KiB
Markdown
# 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](https://en.wikipedia.org/wiki/Connect_Four) 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](https://balkarjun.github.io), 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](https://tech.lgbt/@cqql/113330046815399664).
|
|
|
|
The logic is written up in great detail on balkarjun's blog in this article: [Exploring Board Game AI Algorithms: Minimax](https://balkarjun.github.io/blog/minimax-connect-four/). 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](https://moonlit.technology/cqql/tcp-connect4/commit/016b3aa6cfeeeb2e53b2cd4a132357b1e3ea1022). |