About tripleX

Hi Everyone, I am Davide and I have just completed the tripleX section.
First I wanted to thank you for this course opportunity because it is very helpful.
I just wanted to talk about TripleX game, in particular about the “code matching”.
In the if statement we just check whether the sum and product match but that’s not enough;
First we should assume that all the 3 numbers are positive integers (0 excluded) otherwise would be very simple to find 2 different triples which give same product and sum.
Moreover even deciding to bind our 3 numbers to positive integers it is still possible to find this bug.

In example: SecretCode {6, 6, 10}: Sum=32; Product=360;
PlayerGuess {5, 8, 9}: Sum= 32; Product=360;

The solution would be a Set comparing between the SecretCode and PlayerGuess; however this may collapse in a exhaustive comparing unless we apply a previous sorting which would allow us to match the codes easily.

Secondly, I took the challenge to try and invent a level-based random numbers generator for the SecretCode and I had this as first (failed) idea:
in each Level L extract the random value r in the Interval [1; 2L]; However before we call the rand() function I do extract another random value unfairness in the Interval [0; L].
In this way I extract r using the module operator to get a random value in [1; 2L+unfairness], if r is greater than 2L I subtract the unfairness.

This metod allow a random amount of the second half of the interval of the possible random number [1; 2L] to have more chance to get picked (in this sense unfair); and this allows greater numbers to get picked more often.

However happened that in a Level 5 the secret code was 1 1 1; such a sad conclusion to this idea; so I thought to remember the maximum value picked in the previous code generation and to sum it to the new generation; having this way never twice the same code just shifting to greater numbers every time. The only problem is now that the greatest number possible would be (2+(2+4)+(2+4+6)+(2+4+6+8)+(2+4+6+8+10))=(2+6+12+20+30)=70. In an extreme rare event.

Before i did find out this bug I modified a little bit the structure of the game introducing an HealthPoints parameter (initialized at 1) and every time the player would guess the exact sequence (in the exact order) would gain an extra life, and everytime he mistakes loses one.
I considered the option to add a timeout after which the player loses automatically the round but I think i’ll add it up in future.

Thank you for reading this, and let me know if you liked these ideas and consideration and what do you think about 'em.

Bye,
Falie