Great Approximator is a TCP-based client-server game written in C. Each client connects to the server and competes by approximating a hidden polynomial function. The goal is to minimize the error between the approximation and the actual function.
- The server provides each client with a unique polynomial function
f(x) = a0 + a1*x + ... + aN*x^N. - Clients modify their approximation
f̂(x)by sending commands that add values to integer points between0andK. - The game ends after
Mvalid PUT operations (shared among all clients). - Final scores are based on the sum of squared differences plus penalties for invalid or premature actions.
- Asynchronous handling of multiple TCP clients using IPv4 and IPv6.
- Text-based communication protocol using standard sockets (no external network libraries).
- Two modes of client operation:
- Interactive mode: reads PUT commands from stdin.
- Automatic mode: sends PUT commands based on an internal strategy (
-a).
- Custom protocol with precise error handling and diagnostics.
- Handles invalid input, client disconnects, and protocol violations.
This project uses make. Just run:
makeTo clean all generated files:
make clean./approx-server -f coefficients.txt [-p port] [-k K] [-n N] [-m M]-fis mandatory and points to the file with COEFF lines. Optional:-pserver port (default: 0 → random)-kmax point value (default: 100)-npolynomial degree (default: 4)-mnumber of total PUT operations (default: 131)
./approx-client -u playerID -s serverAddress -p port [-4 | -6] [-a]-uyour player identifier (alphanumeric)-sserver address (IP or hostname)-pport to connect to-4or-6to force IPv4 or IPv6-aenables automatic approximation strategy If-ais not specified, the client reads PUT commands from standard input like this:
0 3.5
2 1.25Each line represents a PUT: PUT $point $value.
- HELLO – client identifies itself.
- COEFF – server sends polynomial coefficients.
- PUT – client adds a value to an approximation point.
- STATE – server replies with current approximation.
- PENALTY / BAD_PUT – client mistake notifications.
- SCORING – final results with error values per player.
- Makefile → Build instructions
- README.md → Project documentation
- approx-server.c → TCP server implementation
- approx-client.c → TCP client implementation
- client.h → Server-side structure for managing connected clients
- cb.c / cb.h → Circular buffer for managing incoming TCP message streams
- queue.c / queue.h → Priority queue (event queue) used for scheduling and managing message flow per client
- err.c / err.h → Error handling utilities (prints diagnostics, handles fatal errors)
- common.c / common.h → Parsing and validating parameters, handling low-level TCP operations, address resolution, port parsing, etc.
- messages.c / messages.h → Functions for composing, validating, and parsing protocol messages
Start the server:
./approx-server -f coeffs.txt -p 12345Start a client:
./approx-client -u Alice -s localhost -p 12345 -a