The Mendeleev's Dream: an Educational Game in Awk Language
by DaniloR29 in Teachers > University+
185 Views, 1 Favorites, 0 Comments
The Mendeleev's Dream: an Educational Game in Awk Language
2019 marked the 150th anniversary of the periodic table of elements, which now includes 118 entries. The most recent addition, Tennessine, was announced in April 2010 [1]. On March 6, 1869, Russian chemist Dmitri Ivanovich Mendeleev presented a groundbreaking communication to the Russian Chemistry Society titled "The Dependence of the Properties of the Chemical Elements on Atomic Weight." This historic communication introduced a new way to organize known chemical elements in a table that highlighted their periodic properties. Mendeleev's work established the foundation for the modern periodic table of elements, a cornerstone of chemistry (for books on the periodic table look the references in this article [2]).
In honor of this milestone, I made it available in a program created long ago, which I named ‘Mendeleev’s Dream.’ Written in the AWK language, this program is a valuable tool for learning about the elements in the periodic table and their properties while having fun.
Program Overview
Mendeleev’s Dream is designed to offer both an educational tool and a set of interactive games to help users memorize and understand the periodic table. The program provides a textual representation of the periodic table, detailed information sheets on the elements, and a collection of simple, educational games.
Why AWK?
AWK is a powerful Unix tool named after its creators: Alfred Aho, Peter Weinberger, and Brian Kernighan, who originally designed it at Bell Labs in 1977. It processes files of text, treating each file as a sequence of records, typically with each line being a record. The key features of this language include:
- Pattern Scanning and Processing: AWK reads input files line by line, splitting each line into fields, processing them against a set of patterns, and executing corresponding actions.
- Text Processing: Ideal for scripting and automating text-processing tasks.
- Portability: Runs on numerous operating systems, including Unix, Linux, Windows, and macOS.
- Extensibility: Supports user-defined functions and extensions, allowing sophisticated text processing and data manipulation.
Gawk, or GNU Awk, is the GNU project's implementation of the AWK language. It is known for its speed and efficiency in processing text, making it perfect for handling large datasets and performing complex text manipulations quickly [3]. For more details and tutorials on the awk language, please visit my blog pages [4], where you can find resources to help you get started and explore its many features.
REFERENCES
[1] https://daniloroccatano.blog/2019/09/01/4377/
[2] [ORNL Tennessine Program](https://www.ornl.gov/sites/default/files/Ts_Program%20Final%20sm.pdf)
Supplies
A computer with a Unix OS (e.g., Linux) and the tool gawk installed is required. The program has been tested on macOS and Raspbian using a Raspberry Pi Zero 2 W.
Gawk Installation
Gawk scripts are highly portable across different Unix-like systems and are usually pre-installed on these systems. This portability ensures the program can run seamlessly on various platforms without requiring modifications. Users can run “The Mendeleev’s Dream” on their preferred operating system, whether it’s a desktop environment or a minimal setup like a Raspberry Pi.
If gawk is unavailable, it can be easily installed using package managers like apt for Debian-based systems, and "brew" for macOS, or downloaded directly from the GNU website.
These changes ensure consistency in naming (macOS instead of macOSX), clarity in instructions, and a more structured presentation.
Usage
Download the attached file and using the terminal window change the name using the command:
mv MendeleevDreamNN.awk.txt MendeleevDreamNN.awk
You can now run the program by typing:
gawk -f MendeleevDreamNN.awk
Disclaimers
The author has made every effort to ensure the accuracy and functionality of the program and its data. However, errors may still be present, and data on the properties of elements, especially artificial ones, may be updated. Therefore, the author declines any responsibility for potential inaccuracies and bugs in the code.
Downloads
Program Structure
This AWK script serves as both an educational tool and a game to help memorize the Periodic Table of Elements, including names, symbols, and various properties.
The program operates in two modes:
- Periodic Table Info Mode:
Displays the periodic table and prompts the user to enter the symbol of an element. It then provides a detailed
information about the selected element.
- Guessing Game Mode:
A guessing game involving 118 elements, where players guess the element names or symbols based on
position, symbol, and properties.
The game supports three languages (English, Italian, German) and various difficulty levels. Each turn allows 5 attempts, with the score decreasing by 0.2 for each incorrect attempt. The game includes four sub-modes:
- Guess the element symbol
- Guess the element name
- Guess the element based on the table position
- Guess the element based on properties
Game levels:
0: Guessing Element Name and Position
1: +Mass number (number of nucleons)
2: +Electronic Configuration
3: +Atomic Weight
4: +Year of Discovery
5: +Density
6: +Melting Point
7: +Boiling Point
8: +Atomic Radius
9: +Covalent Radius
10: User Selected Property (Game0+Select. Prop.)
Description of the Awk program:
The program is organized as follows:
- Initialization: Sets up the properties of the elements and initializes the periodic table.
- Main Menu: Offers two main modes: Periodic Table Info and Guessing Game.
- Periodic Table Info Mode: Displays the periodic table and allows users to select an element to get detailed information.
- Guessing Game Mode: Features various games to help users learn the elements based on their properties.
The program includes four engaging games:
- Game 1: Guess the Element Symbol
- Game 2: Guess the Element Position
- Game 3: Complete the Element Name
- Game 4: Property-Based Guessing
The BEGIN block initializes variables, and properties, and sets up the main menu loop that allows users to select between "Periodic Table Info" and the "Game".
List of the Awk functions used in the program:
GameMenu():
Handles game menu and game selection.
LanguageSelection():
Allows the user to select the language for element names.
DifficultyLevelSelection():
Allows the user to select the difficulty level for the game.
UserLevelSelection():
Allows the user to select a specific property for the game if the difficulty level is set to "User Selected Property".
GameLogic():
Implements the game logic based on the selected language and difficulty level.
game1():
Implements the logic for game type 1, where the user selects the name of the atom in the indicated position.
game2():
Implements the logic for game type 2, where the user selects the number corresponding to the position of an element.
game3():
Implements the logic for game type 3, where the user enters the full name of the element.
game4():
Implements the logic for game type 4, where the user selects a property of the element in the indicated position.
SaveGame():
Saves the current game state to a file.
LoadGame():
Loads a previously saved game state from a file.
checkword():
Checks the guessed word and updates the display for partially guessed words.
rSpaces():
Removes trailing spaces from a string.
CheckAnswer():
Checks the user's answer and updates the score.
ChoiceElement():
Selects a random element from the list.
PrepareList():
Prepares a list of elements for guessing.
Setup():
Prepares the periodic table setup for display.
green(s):
Highlights the input string in green.
PrintPerTable():
Displays the periodic table and handles user interaction for element selection.
PrintInfo(sel):
Displays the properties of the selected element.
Properties():
Initializes arrays containing the properties of elements, such as atomic number, atomic radius, melting point, boiling point.
Periodic Table Info Mode
Displays the periodic table and allows users to select an element to get detailed information.
You can display the information by typing the symbol of the element. Type zero to exit.
Game Mode
The program checks if there is a backup file named "MendDream.dat" that stores the current game. If it exists then you can continue the game or you can start a new one.
If you start a new one the program asks in which language you want to guess the name of the element in the game 3. You can choose between English, German and Italian.
Finally, the program asks you to choose the level. For each level, the new property in the list will be used in the game 4.
For option 1), it is possible to specify the property that you want to train together with the default training for the games 1-3 on the element positions in Table.
You start with 50 points. You have 5 attempts for each of the questions in the game. Each mistake reduces by 0.1 point your score.
Game 1
- Objective: Guess the element's name at the indicated position.
In this game, you need to guess the name of the element in the position indicated by the red cross. 5 possible symbols or element names are suggested. 5 attempts are allowed, and each negative answer is penalized by 0.1 points after 5 attempts the answer is given with a total penalty equal to -0.5.
Game 2
- Objective: Identify the position of a randomly chosen element based on its symbol or name.
The second game aims to guess the position of a randomly chosen element, given its symbol or its name. 5 possible locations are suggested in the periodic table numbered from 1 to 5. 5 attempts are allowed, each negative answer is penalized by 0.1 points after 5 attempts the answer is given with a total penalty equal to -0.5.
Game 3
- Objective: Guess the element's name with missing letters represented by dashes.
In this game, you need to guess the name of the element indicated with an X in the periodic table. The program suggests the letters contained in the name with dashes. 5 attempts are available if the proposed name is not correct, the characters that coincide with those of the exact name are reported in the suggestion. After 5 attempts, the correct answer is given, but with a total penalty of -0.5.
Game 4
- Objective: Guess the element based on properties like atomic number, atomic weight, or melting point.
- Mechanism: Users have multiple attempts, with penalties for incorrect guesses.
Conclusions
Mendeleev’s Dream is a simple yet powerful educational tool that makes learning about the periodic table engaging and fun. Whether you're a student or a chemistry enthusiast, this program offers an enjoyable way to deepen your knowledge of the periodic table.