The CFG Derivation Game is an interactive web-based game designed to help users understand and practice Context-Free Grammar (CFG) derivations. The game challenges players to generate a target string using CFG production rules within a limited depth and time. It combines learning with fun, offering a visually engaging experience with derivation trees and dynamic gameplay.
The goal of the game is to:
- Generate the target string using the provided CFG production rules.
- Complete the derivation within the specified tree depth and time limit.
- Enhance understanding of CFGs and derivation processes in a fun and interactive way.
- Dynamic Derivation Tree: Visualize the derivation process as a vertical tree structure.
- Customizable Rules: Input your own CFG production rules and target string.
- Time and Depth Constraints: Test your skills under pressure with a timer and depth limit.
- Interactive Gameplay: Select non-terminals, positions, and rules to progress through the derivation.
- Win/Lose Screens: Get feedback on your performance with visually appealing win/lose screens.
- Responsive Design: Play the game seamlessly on any device.
-
Setup the Game:
- Input CFG production rules in the format
A → a | b | c
. - Specify the target string you want to derive.
- Set the maximum tree depth for the derivation process.
- Input CFG production rules in the format
-
Start the Game:
- The game begins with the start symbol (
S
) as the initial string. - Use the provided rules to replace non-terminals and derive the target string.
- The game begins with the start symbol (
-
Make Your Moves:
- Select a non-terminal from the current string.
- Choose its position and apply a production rule to replace it.
-
Win or Lose:
- Win by deriving the target string within the time and depth limits.
- Lose if you exceed the maximum depth or run out of time.
- Frontend: React, TypeScript
- Styling: Tailwind CSS
- Build Tool: Vite
- Routing: React Router
Feel free to contribute or suggest improvements to the project!
- Add support for saving and loading custom CFGs.
- Implement a leaderboard to track high scores.
- Add hints and tutorials for beginners.
- Enhance the derivation tree with animations.
PS: UI might not be very good, considering it was made solely for 5 weightage =].