zaidahmad16/COMP2401-Final-Project
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
COMP2401 Final Project Description: This program simulates a ghost hunting game in Willow House, a building with 13 rooms. The user creates a team of hunters with special ghost-detecting tools, and the program runs hunter and ghost threads at the same time using pthreads. Technical Overview: - Multi-threaded Design: Each hunter and the ghost run as separate threads that execute at the same time. The main thread creates all threads and waits for them to finish. - Thread Synchronization: Semaphores protect shared resources like rooms, the evidence case file, and user input. Every room has its own semaphore, and there are also global semaphores for the case file and standard input. - Deadlock Prevention: When a thread needs to lock multiple rooms, it sorts them by memory address and locks them in order. This makes sure threads always request locks in the same sequence, preventing circular wait conditions. - Data Structures: Hunters use a stack to track their path through the house (like leaving breadcrumbs). Rooms are connected using a linked list structure. Each room can hold up to 8 entities at once. - Evidence System: The ghost drops evidence based on its type (each ghost type leaves 3 specific types of evidence). Hunters collect this evidence using their assigned equipment. The program uses bitwise operations to check if 3 pieces match a ghost type. Game Logic: Hunters explore the house on their own, collecting evidence with their tools (EMF reader, thermal scanner, spirit radio, etc.). They remember their path using a breadcrumb stack so they can find their way back to the van. Hunters leave when their fear or boredom reaches 15, or when the team finds 3 or more pieces of evidence and they get back to the van. The ghost moves around randomly, dropping evidence based on what type of ghost it is. It gets more active when hunters are nearby and gets bored when alone, leaving when boredom reaches 15. How to compile and run: gcc -Wall -Wextra -pthread main.c helpers.c house.c hunters.c ghost.c -o final ./final Citations: Course assignments: - A1 (readings.c): Input validation patterns, CSV file writing with timestamps - A2 (manager.c): Bitwise operations for evidence checking, enum-to-string conversions - A3 (stack.c, tutorials): Stack data structure implementation, thread-safe random numbers, mutex ordering for deadlock prevention - A4 (building.c, room.c, ghost.c): Room initialization and connections, ghost movement and AI behavior, evidence placement, shared resource access patterns