-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign.txt
12 lines (6 loc) · 2.23 KB
/
design.txt
1
2
3
4
5
6
7
8
9
10
11
12
(What additional properties did you add to your models and why?)
There were two additional properties that I added to my model: a JsonProperty and a ComputedProperty. Given that I was implementing a hangman game, I couldn't just store the answer itself as a string nor could I store a list of characters. In fact, each character had to be accompanied by a boolean value indicating whether the user had guessed it correctly or not. So what I needed was a nested list to store the ultimate answer for every game, and the user’s progress in guessing each individual character- this was where the JsonProperty came in handy.
In order to create an endpoint returning a ranking of users ordered by their performance metrics, I needed to add extra fields to the User model so that I could store how many games they won and played, and how many guesses they made. But using such simple numbers alone could not produce the metric I needed to properly rank users. One programatically elegant solution to this was to add to the User model, computed properties which automatically calculated the win ratio and average guesses per game whenever I made queries.
(What were some of the trade-offs or struggles you faced when implementing the new game logic?)
Hangman is a more complex game than 'guess a number'. Given the more complicated logic, I needed whole new set of helper functions which I defined in a separate file. The more complex logic required a lot more 'if conditions', loops, counters, and boolean values. Fortunately I practised beforehand by writing a command line version of Hangman before producing the Endpoints API. The game is complicated further by the fact that the user can not only guess using single letters, but also attempt to win the game by guessing the whole word, so additional logic needed to be added, but that was more routine. Rather fortuitously, the use of helper functions became useful when I was required to extend the endpoints API because it allowed me to modify the code base with in an organised way without breaking any existing function.
Choosing to program for hangman made some things easier as well: for example, I did not need to ask the user to specify a limit to the number of guesses allowed- such a game has a fixed number of guesses.