Pull from upstream before solving this task.
The goal of this assignment is to learn and understand the mechanisms of multithreading and concurrency programming. You will use the functionality of the POSIX standard for that.
We decided to show you the aspects of multithreading via a simple ASCII game. You can see if you have done something right by observing that the game is getting more playable. In the beginning, you will only see a plain game map without any content.
In the game, your protagonist is an archaeologist who collects artifacts in Egyptian ruins. But these ruins are full of venomous snakes and mummies. Help your protagonist to collect as many artifacts as possible and avoid the enemies.
The game consists of 3 different entities:
Enemy Snakes: Snakes are three fields long. The enemy snakes are spawning at a random position and will kill your archaeologist if you hit them. (represented by an ‘S’ on red background)
Enemy Mummies: Mummies move way slower than snakes. The enemy mummies are also spawning at a random position and will kill your archaeologist immediately if you hit them. (represented by an ‘M’ on black background)
User Protagonist: To collect chests and avoid enemies, the user protagonist (represented by an ‘A’ on blue background) gets moved via the WASD keys. The game shall quit when ‘q’ is pressed, when it hits an enemy or when it hits the border. (Lifepoints get set to 0)
Artifacts: To get points, you may collect some artifacts (represented by ‘#’). Once one artifact is collected, the next artifact shall spawn immediately at a random position.
You’ll have to install
ncurses on your system. In
Debian/Ubuntu the following line will do the job:
sudo apt-get install libncurses6-dev libncursesw6-dev
ncursesw6 is not working or not available for your system, you may also use
ncursesw5. If that’s the case, you may replace the line
NCURSES = $(shell ncursesw6-config --cflags --libs)
Makefile with the line:
NCURSES = $(shell ncursesw5-config --cflags --libs)
Do NOT make any other changes to the
When you open the folder of this task, you will notice four files:
Makefile: Use this file to compile and run the program or clean up the folder with it.
archaeologist.h: This file contains relevant includes, typedefs, predefined values. You can change them as you wish but be careful: you must not push this file. Therefore all changes are irrelevant for us.
helpers.c: This file contains functions, which make your implementation run. As with your header file, you can change everything in there, but as the header file, you must not submit this file as well, so your changes are irrelevant to the testing system.
archaeologist.c: This is the only file that will be checked and used by the test system. Please follow the TODOs and ONLY change and add code between TODO BEGIN and TODO END!
You must not create ANY global variables, delete existing code (comments can be changed and added, of course), or rearrange existing code! Be careful, do not delete any needed functions declared in the header file.
What to do before you start?
Pull from upstream!
Carefully look at the TODOs in the
Look at the Manpage and what those parameters of the needed functions are for and how they are used. (
pthread_create( ... ),
pthread_cancel( ... ),
pthread_join( ... ), etc [https://man7.org/linux/man-pages/man7/pthreads.7.html])
Only begin if you understand the basic concept, what a thread is, and what it does. Bruteforcing will lead to a severe amount of wasted time.
Try to understand the different functions in the
archaeologist.cfile and their connections.
I would recommend starting with the user_protagonist spawning task in the
Hint: Make sure that you reuse as many variables as possible.
You find all the needed information on the manual pages. You can access them by either typing
man into the terminal or by reading them on various websites. For example, the manual for
pthread_create( ... ) may be accessed by the command
man pthread_create . For this exercise, you might find the following links helpful.
In case you prefer a german source:
- Linux-UNIX-Programmierung von Jürgen Wolf (chapter 10)
archaeologist.c in your git repository. You can find this file in directory
A1. Tag the submission with
A1 and push it to the server. Do not add any additional files to the folder!