CS 330: Three Letter Word Match

Due: Tuesday, Nov 12, 2026 by 11:59 PM


Overview

In this assignment, you will extend the basic client/server socket programs to implement a networked word game called Three Letter Match. The server manages the active substring, validates submitted words against a dictionary, tracks client scores, and responds to commands that allow a player to participate in the game.

The goal is to help you practice the core skills introduced in the networking units: socket programming, server/client communication, input validation, concurrency, and structured documentation.


Objective

The objective of this assignment is to modify or build a TCP-based client/server application so that:

  1. The client can choose a three-letter substring.
  2. The server validates that substring and dictionary entries.
  3. The client can submit words and receive score updates.
  4. The server can list matching words for the current substring.
  5. The server can handle multiple clients and maintain correct per-client score state.

By completing the assignment, you will gain practical experience in networked application design, concurrency, protocol handling, and robust error checking.


Game Rules and Functionality

1. Selecting the Substring

2. Dictionary Validation

3. Submitting Words

4. Scoring

5. Listing Words

6. Ending the Game

7. Available Commands

  1. SET — choose a new three-letter substring.
  2. SUBMIT — submit a word to check for validity and substring match.
  3. LIST — request all words containing the current substring.
  4. QUIT — exit the game and display the final score.

8. Client Input and Output

9. Server Behavior

10. Buffer Limits


Example Client–Server Interaction

Client> SET ate
Server> Substring set to "ate"

Client> SUBMIT late
Server> "late" is valid! +1 point. Score: 1

Client> SUBMIT cat
Server> "cat" does not contain "ate". -1 point. Score: 0

Client> LIST
Server> Words containing "ate": ate, late, rate, fate, create, update, ...

Client> QUIT
Server> Final score: 0
Connection closed.

Implementation Requirements

1. Connection Setup

2. Server Requirements

3. Client Requirements

4. Error Handling

5. Concurrency and Data Structures


Design Decisions

When completing the assignment, you must make and document several design choices. Include your reasoning for each decision in the source code comments and in your README.

  1. Handling Multiple Clients
    • How will the server handle multiple simultaneous clients?
    • Consider whether to use multithreading, multiprocessing (fork()), or synchronous I/O multiplexing (select()).
    • Explain why your chosen approach is suitable for this application.
  2. Tracking Client Scores
    • How will you store each client’s score?
    • For example, you might use a dictionary or list that maps each connected client to its score.
    • Justify your chosen data structure.
  3. Behavior After LIST
    • After a client uses LIST, no more points may be awarded.
    • The round ends immediately after LIST, and the client must choose a new substring with SET before submitting more guesses.
    • Explain how your implementation enforces this rule and why it makes the game state predictable.
  4. Handling Invalid Substrings
    • How should the server respond if a client submits a substring that is not exactly three letters long?
    • Define clear error handling, such as rejecting the input and prompting the user to try again.
  5. General Input Validation
    • How will you handle invalid input, such as empty strings or non-alphabetic characters?
    • Decide whether to reject the input, penalize the client, or display an error message.

Documentation Requirements

1. Code Comments

Include clear and meaningful comments throughout your code that explain:

Lack of proper documentation will result in point deductions.

2. README File

Include a README file with your submission that contains:

3. Pair Work and Submission


References


Grading Criteria

Category Requirements
README File Clear instructions, rules, and design discussion
Compile & Run Programs compile and run without errors
Command Flow Supports SET → SUBMIT → LIST → QUIT sequence, with LIST ending the round so no more points can be awarded
Consecutive Rounds Supports multiple rounds and repeated substring changes after a new SET
Score Tracking Accurate scoring behavior
Multiple Clients Server supports concurrent clients
Static Buffer Limit All buffers are at or under 512 bytes
Error Handling Gracefully handles invalid substring length, invalid characters, duplicate submissions, and invalid commands
Test Substring Uses and tests the substring ate
Client Restrictions Client does not read or access words.txt directly

Helpful Testing Notes

Example test for substring frequency:

cat words.txt | perl -nlE '$_=lc; $l=length; next if $l < 3; m/(.{3,$l})(?{ $freq{$1}++ })^/; END { say "$freq{$_} $_" for keys %freq }' | sort -rg | head -10

This is a useful way to examine how often particular substrings appear in the dictionary and to validate the expected behavior of your game logic.