1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# Siege durak/Podkidnoy (Throw-in) durak
<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
v \
+-----------------+ \
| THROW-IN QUEUE | \
| | \
| - If defender | \
| already failed| \
| ≥1 card → | v
| put all queued| +----------------------------+
| cards on table| | DEFENSE RESULT? |
| → check again | | - SUCCESS: defender becomes |
| | | next attacker |
| - If still | | - FAIL: player after |
| defending well| | defender attacks next |
| → throw 1 card| +----------------------------+
| → DEFENSE |
+-----------------+
```
## 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
### On Linux (MacOS, FreeBSD, Android)
```
git clone https://git.scratko.xyz/durak
cd durak/linux_client
make
./client
```
Note: On Android, use a terminal like `Termux`, and install packages: `clang`, `make`, `git`.
### On Windows
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>
### 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).
---
Questions? Contact: m@scratko.xyz
|