This project is a fun project with three serious goals,
NAME
snail --- the snail gate game
SYNOPSIS
snail [-v]
DESCRIPTION
As the snail moves towards a gate, the user guesses the one digit key to the
door. If the user guesses the key, the door opens (depicted by the ? in the
gate disappearing) and the snail can pass through the gate.
OPTIONS
-v verbose
ARGUMENTS
None
OUTPUT
A graphic with a snail @/, an closed gate [?] and an open gate [ ].
HISTORY
New for csc421-231.
The nag program, github://csc-courses/csc421/nag.c, is the basis for this project. The nag routine is a thread that from time to time wakes up and checks if something new has been said. If not it nags the user to say something. However if so, it insults the user for what they said.
Note in this program,
The snail gate program operates very similar to the nag program. It is on the technical level the nag program, but with a different story line.
Snail gate runs with two threads. The main thread and the draw_thread thread.
The main thread initializes the data structures and then creates the draw thread, exactly as nag created the nag thread.
The two threads communicate with two shared data structures using two different techniques,
struct Board {
int snail_loc ;
char guess ;
int gate_loc ;
int gate_key ;
int gate_state ;
} ;
struct T_arg {
int req_exit ;
pthread_mutex_t * mutex ;
pthread_cond_t * cond ;
} ;
The board information is held in a global struct of type struct Board. The snail has advanced to integer position snail_loc. The main thread update guess with what the user has guessed. The get is located at gate_loc and is opened by the character gate_key. The gate_key takes one of two values, GATE_IS_CLOSED or GATE_IS_OPEN. This field is used when creating the string tha represents the game.
The thread argument is a structure bundling up the shared lock, (pthread_mutex_t) * mutex and the shared condition variable (pthread_cond_t) * cond as well as a flag req_exit which is set to request the draw thread to exit.
Note that draw_thread formally declares the argument to be a void *. Review the meaning of a void-star. TLDR; version — you will need to cast it to its actually type struct T_arg *.
The task of the draw thread is to loop, sleeping on either a timeout or a wakeup signal from the main thread.
When the draw thread is awakened,
You have been provided with utility functions to draw the game board. In the discipline of Model-View-Controller, the main thread is the Controller and the draw thread is the Viewer. The Model is latent in the data structures, which are shared between viewer and controller.

author: burton rosenberg
created: 20 sep 2022
update: 29 sep 2024