back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md161
1 files changed, 122 insertions, 39 deletions
diff --git a/README.md b/README.md
index da73c73..7675145 100644
--- a/README.md
+++ b/README.md
@@ -3,32 +3,112 @@
<img src="durak.png" />
## Description
+This is a network-based console version of the classic Russian card game
+"Podkidnoy Durak" (Throw-in Fool). Both the client and server are written in
+pure C.
+
+TCP/IP sockets are used for network communication, enabling reliable data
+transfer via `read` and `write` system calls. The client and server follow an
+event-driven programming model using `select()` for I/O multiplexing.
+
+## Gameplay
+- Card suits: `%`, `#`, `v`, `^`
+- Card ranks: `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `J`, `Q`, `K`, `A`
+- Game phases: attack, defense, and throw-in
+
+The game supports dynamic throw-ins based on real-time player reactions —
+whoever throws first, their card is accepted.
+
+## Hint system
+
+Players receive visual hints based on their role:
+
+- Attacker: all cards of matching rank
+- Defender: cards that beat the attacking one (higher of same suit or trump)
+- Thrower: cards of the same rank as those already on the table
+
+Players may press `Enter` to either surrender the defense or skip the throw-in phase.
+
+The server analyzes each phase:
+
+- Determines whether the defender can beat the attack
+- If defense fails, transitions to the throw-in phase
+- If no throw-in is possible, moves to the next attack phase
+
+During defense, the defender sees only one attacking card at a time (others see all cards).
+
+## Game State Machine (ASCII Diagram)
+
+```text
++-----------------+
+| ATTACK |
+| (attacker plays)|
++--------+--------+
+ |
+ v
++-----------------+
+| DEFENSE |
+| (defender tries |
+| to beat cards)|
++--------+--------+
+ |
+ v
++----------------------------+
+| CAN OTHERS THROW-IN? |
+| (same rank as on table) |
++------+---------------------+
+ |YES (NO -- DEFENSE RESULT?)
+ v
++----------------------------+
+| THROW-IN QUEUE |
+| - If defender already |
+| failed 1+ cards → put all |
+| queued cards on table |
+| - If still defending well → |
+| throw 1 queued card |
++------+---------------------+
+ |
+ v
+ (recheck throw-in)
+ |
+ v
++----------------------------+
+| END OF THROW-IN |
++------+---------------------+
+ |
+ v
++----------------------------+
+| DEFENSE RESULT? |
+| - SUCCESS: defender becomes |
+| next attacker |
+| - FAIL: player after |
+| defender attacks next |
++----------------------------+
+```
-Network game. Client and server are written in pure C.
-For network communication the socket system with TCP/IP protocol is used. Due to this it is possible to use streaming through read
-and write system calls, and there is a guarantee that the data will arrive in strict order.
-The client and server are written in an event-driven programming model. Events are selected using the select system call, thus
-multiplexing I/O.
-
-GUI: console version.
-Card suits are labeled as %, #, v, ^.
-Card ranks: 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, J, Q, K, A.
-There are several stages: attacking, defending, and tossing cards. Unlike classic Fool's game, here you can toss cards depending on
-the reaction of the players --- whoever has time to toss a card, that card goes on the table.
-
-There are hints to help players.
-
- * When attacking: those cards that have the same ranks (or all of them).
- * When defending: those cards that can be used to beat back the attacking card on the table (higher rank, or with a trump suit).
- * When tossing: those cards that have the same rank.
-
-It is possible to give up defense and accept attacking cards -- then press enter. It is also possible to discard the toss -- also
-press enter.
-The server analyzes whether the defender can fight back. If so, the server analyzes whether the defender can fight back.
-The defender is shown one card at a time (the others see all cards), which he must defeat. If the server decides that the defender
-does not have any cards that can be used to fight off the attacking cards, then the tossing phase is analyzed.
-If the other players (except the defender, of course) have cards with the same rank as on the table, then the player moves to
-the tossing phase, otherwise the player moves to a new attack phase.
+## Features & Technologies
+
+### Technologies
+
+- C programming language — for both client and server
+- POSIX sockets — TCP/IP networking
+- `select()` system call — event-driven I/O
+- Cross-platform — Linux, Windows, Android (via Termux)
+- Finite State Machine (FSM) for game phase control**
+- Session tracking for each connected client
+- Separate adapted Windows client derived from the Linux version
+
+### Gameplay Features
+- Full support for "Podkidnoy Durak" rules: attack, defense, throw-in
+- Real-time interaction: whoever throws a card first wins the throw-in
+- Turn-based logic, respecting the rules of defending, beating, or taking cards
+- Hint system based on player role:
+ - Attacker — cards of matching rank
+ - Defender — suitable beating cards
+ - Thrower — cards matching any on the table
+- Game logic transparency — only defender sees current attack card; others see all
+- Supports multiple clients connected to the same server in real time
+- Automatic phase switching based on server logic without client-side decision delays
## Building
@@ -41,25 +121,28 @@ make
./client
```
-Note: for Android, you need to use a terminal like Termux. After installing it, you should to install packages:
-clang, make, git. Then follow the steps above.
+Note: On Android, use a terminal like `Termux`, and install packages: `clang`, `make`, `git`.
### On Windows
-You can download the built version for the Windows platform (it already contains the IP address for connecting to this server).
+You can download a prebuilt Windows version with the server IP preset:
Windows version: <a href="https://scratko.xyz/games/durak.exe" target="_blank">Download</a>
-### Use for your server
-
- * Build the server executable file.
-Run the file on the command line, specify a free port to be used by the server (from 1024 to 65535) as the second argument.
-Example: `./server 1025`
- * Open the linux_client/client.c (or windows_client/client.c) file with any text editor.
- * On line 14, change the ip from `109.107.161.30` to `%server ip-address%` (either `127.0.0.1` if you want to test on a local
-computer).
- * On line 15 in the same file, correct the port to the one specified above.
- * Build the client file and run it without arguments.
+### Hosting Your Own Server
+
+1. Build and run the server:
+ ```
+ ./server 1025
+ ```
+ Choose a free port (≥1024).
+
+2. Configure the client:
+ Open `linux_client/client.c` or `windows_client/client.c`:
+ - Line 14: set your server IP address (e.g., 127.0.0.1 for local)
+ - Line 15: set the same port used above
+
+3. Build and run the client (no arguments required).
---
-If you have any questions, please contact me: m@scratko.xyz \ No newline at end of file
+Questions? Contact: m@scratko.xyz