Deep Dive into a MS Power Apps Wordle Game Engine
This article explores a Microsoft Power Apps canvas solution that implements a Wordle computation engine. In this application, users input a target word (the “answer”) and a guess. The engine then processes the guess and returns a string representing the match status, using the following colour-coded indicators:
- G (Green): Indicates that the character in the guess matches the character in the answer at the same position.
- Y (Yellow): Indicates that the character in the guess is present in the answer, but at a different position.
- B (Black): Indicates that the character in the guess is not present in the answer.
Enabling User-Defined Functions
This engine utilizes an experimental Power Apps feature called User-defined functions, which must be enabled as follows:
- Click the Settings (cog) icon.
- Select the Updates tab.
- Scroll down to User-defined functions and enable it.
Download the Source Package
The source package for this solution is available for download on GitHub at Power Apps-Wordle-Engine. You can run the solution, use it as a starting point for further development, or follow along with the explanation provided here to understand its implementation.
The Interface
The Wordle-engine interface comprises the following components:
- A label and text box for the answer, which is the word to be guessed.
- A label and text box for the guess, representing the guess string that is entered by the player.
- A button labelled WORDLE It, which invokes functions to populate the two remaining text boxes.
- A label and text box for gOutput, holding the output of the matching engine.
- A label and text box for nfExactMatch, containing a string indicating exact matches (discussed further below).
- Two text boxes providing worked examples of how the engine operates.
- A text box at the bottom of the screen explaining that “*” and “-” are reserved characters and cannot be used in answer and guess.
Known Limitations
This engine is a proof of concept (POC) intended to demonstrate core functions that would be part of a complete game. Input checks are non-existent; therefore, users must ensure that both the answer and guess text boxes contain exactly five characters and do not include the reserved characters.
Dry run of the solution
All actions occur within the function nfResult
, which takes answer
and guess
as parameters and returns a G-Y-B result to represent matches. This dry run focuses on this function.
For this walk-through, let’s consider answer
as B A B E S and guess
as A B B B Y.
001: |
The function calls In this case, only the third character matches, resulting in _ _ G _ _ stored in |
|
002: |
The function calls In this case, only the third character matches, resulting in _ _ G _ _ stored in |
|
003: |
The same function call to Consequently, |
|
For each character in |
||
004: |
The current character being processed is extracted into a variable called In our case, this will be A. |
|
005: |
A check is performed to see if In our example, this will be TRUE. |
|
006: |
The position of Here, |
|
007: |
If |
|
This sequence (steps 004 to 007) repeats for each character in |
Checking for Duplicates
In our example with BABES and ABBBY, there are two B’s in answer
and three B’s in guess
. The “striking out” process ensures that only two B’s from guess
find matches in answer
, leading to accurate results instead of erroneous ones.
Thoughts and comments for improvement
I want to clarify that I am not a Microsoft Power Apps developer; prior to this project, I had minimal experience with this platform. Coming from a software engineering background where I developed a Wordle game in Python, I quickly realized that Power Apps operates as a declarative language rather than a procedural one, necessitating a complete rethink of my approach.
While transitioning from one procedural language to another usually allows considerable knowledge transfer, I found that moving to Power Apps required entirely new ways of thinking about problem-solving.
Here are some suggestions for improvements that could enhance Power Apps:
Modular Variables
In Power Apps, setting or updating variables within functions requires using the With construct, limiting variable references outside its closing curly bracket. For instance, accessing exactMatch necessitated an additional With block. To update variables like answer, which needed multiple updates within one function, embedding one With within another became cumbersome.
It would be beneficial if variables could be declared within a module and manipulated freely throughout its scope.
Proper Looping Constructs
Extending the Power Apps Keywords
Introducing additional keywords such as For, While, or Repeat (these being the constructions I would have benefited from in my solution) could significantly enhance functionality within Power Apps. Drawing inspiration from Excel’s evolution over time could lead to similar advancements here.
Improving the IDE
The saying “A craftsman is only as good as his tools” rings true; thus, improvements are needed within Power Apps IDE. For example: - While keywords are case-sensitive, there’s no auto-capitalisation feature. - Searching (and replacing) all occurrences of strings across projects would streamline development processes significantly.
Debugging Enhancements
Power Apps currently offers basic debugging functionality but lacks advanced features like observing variable states during execution and supporting breakpoints. Being able to track variable changes would greatly enhance debugging capabilities.
Can you make this better?
‘Better’ is a subjective term as it can mean different things to different people. However, my definition of ‘better’ in this context would include anything that reduces or eliminates redundant code, enhances readability, and/or achieves the desired result in an innovative way.
If you create an improved version of this engine, please leave a comment so that I can link to it and share it with others
Conclusion
Microsoft Power Apps markets itself as a no-code/low-code solution; however, even newcomers will want to mature their solutions or develop more ambitious projects. A tool that facilitates such growth can empower users significantly. Moreover, developers transitioning from procedural environments will appreciate enhanced functionalities that enable them to create apps with similar ease and versatility as their existing development environments.
Before concluding this article, I visited the Microsoft Power Apps Blog and was pleased to see ongoing efforts by the team to improve their product. Many features discussed here could potentially become experimental features soon.
The Video
I also produced a video on this topic for those who prefer one medium over another. They compliment one another and tackle the topic from different perspectives.
Comments
Post a Comment