Skip to content

C Program that lets the user play Hangman with a evil twist where the game is designed to try to actively cheat you out of winning.

Notifications You must be signed in to change notification settings

Meeps-Underflow/Evil_Hangman

Repository files navigation

Evil Hangman - C Implementation

Overview

This project is a C implementation of the "Evil Hangman" game, where the computer cheats by dynamically changing the word it's "thinking of" to make the game as difficult as possible for the player. The game uses advanced data structures including generic vectors and binary search trees to efficiently manage word families during gameplay.

Features

  • Generic Vector Implementation: A reusable generic vector data structure that can store any type of data (void pointers)
  • String Library: Custom string implementation with dynamic resizing and common string operations
  • Word Family Management: Uses binary search trees to organize words into families based on letter patterns
  • Interactive Gameplay:
    • Configurable word length
    • Adjustable number of guesses
    • Visual feedback of guessed letters and current word state
    • Input validation

Data Structures

  • Generic Vector:
    • Dynamic array implementation
    • Handles any data type through void pointers
    • Includes assignment and destruction callbacks for proper memory management
  • Binary Search Tree:
    • Used to organize word families during gameplay
    • Nodes contain word patterns and vectors of matching words
  • String Implementation:
    • Dynamic character array
    • Automatic resizing
    • Common string operations (concatenation, comparison, etc.)

How It Works

Initialization:

- Reads dictionary file and organizes words by length
-Creates initial word family based on user-selected word length

Gameplay Loop:

-  For each guess:
  1. Divides current word family into sub-families based on letter positions
  2. Selects the largest family (making the game as hard as possible)
  3. Updates display based on whether the guess was "correct"
- Continues until player wins or loses

Cheating Mechanism:

- The computer doesn't actually pick a word initially
- Instead, it maintains the largest possible set of words that match all previous guesses
- Only "chooses" a specific word when the player wins or loses

Building and Running

  • Clone the repository
  • Run make to compile
  • Execute the program with
./string_driver
  • The program expects a dictionary.txt file in the same directory.

Requirements

  • C compiler (tested with gcc)
  • Make utility
  • Dictionary file (included in repository)

File Structure

  • generic_vector.c/h: Generic vector implementation
  • my_string.c/h: Custom string implementation
  • main.c: Game logic and user interface
  • status.h: Status codes and boolean type
  • generic.h: Generic type definitions
  • Makefile: Build configuration
  • dictionary.txt: Word list

Example Gameplay

image

Known Issues

  • Limited error handling for file operations
  • No difficulty settings (always uses hardest possible strategy)

Future Improvements

  • Add graphical interface
  • Implement difficulty levels
  • Add word definition display at game end
  • Support for multiple dictionary formats

Author

Meeps-Underflow

About

C Program that lets the user play Hangman with a evil twist where the game is designed to try to actively cheat you out of winning.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published