back to scratko.xyz
aboutsummaryrefslogtreecommitdiff

Siege durak/Podkidnoy (Throw-in) durak

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)

+-----------------+
|     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: Download

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