# [Game] Psychic Tester 1.35

Do you have psychic powers? Play my game and find out.

I inverted the number wizard game to make a game that tests for psychic power. Take the test over and over again and try to achieve a score of OVER 9000!

[The algorithm for determining psychic power is quite clever, if I may say so it is the 1/(chance of incorrect/chance of correct) or 1/(chance of correct - 1) or just the range subtracted by the sum of probabilities of all wrong guesses. The lowest score achievable is a -3 rounded up from the number e. In order to get that score, you have to be super not psychic and quite unlucky. A score of -3 is I think much more improbable than guessing the right number out of a thousand on your first guess.

if you achieve a score of 37 that means a probability of roughly 1/38 of achieving that score a score of 1 means roughly 1/2 probility of guessing, a score of 0 is roughly 1/1 of guessing it meaning either you got to the last number and had nothing to choose from, or you got to two choices but the sum of all the probabilities leading -(1/6 + 1/5 + 1/4 + 1/3) up to that meant that your score approximated to 0.]

*The algorithm was not clever, an aspect of the algorithm is clever, changed it to more reflect statistics.

Ver 1.35
Psychic Tester Version 1.35

Version 1.2 Update
Cleared the Input field after each submission (has a placeholder 0)
Added text to let you know when you picked the right number and added an additional submit after the round is completed.

Version 1.25 Update
Disabled the text box on last submit
Made significant changes to the algorithm for psychic power.
Psychic Power now shows to two decimal places, it is now possible to get a score between 1 and 0 meaning your score is lessened.

Version 1.26 Update
Disabled text box on last submit (when the round is won)
Changed the text on the submit button to â€śPlayâ€ť and changed text in the round over message to indicate to click the play button.

Version 1.28 Update
Added lose conditions, and I did something else but donâ€™t remember what.

Version 1.30 Update
Modified algorithm to prevent cheating.

Version 1.31 Update
Made the Input field focused throughout play of the game.
Allows you to enter in values either through return (or Enter) key or num pad enter
Changed the end text on lose condition to inform you what the correct number was.

Version 1.32 Update
Fixed a glitch in the psychic Power algorithm. Also re-positioned crystal ball image and realigned text.

Version 1.33 Update
Improved the UI for the Input Field box, centered text, changed font. Getting close to completion.

Version 1.34 Update
Fixed a bug on the psychic power score which would cause the score to decrease after successive rounds. The algorithm is a near perfect metric for psychic ability, they most closely reflect the statistics, or your chances of guessing correctly it is actually something approximating the inverse of your chances minus one, so if you have a 1 in 2 chance of guessing correctly and you do it gives a psychic power score of 1. Of course each successive wrong guess is factored in, so each wrong probability is multiplied by itself and it can add up.

If you score over 100,000 it means you are either lucky or may have psychic potential - okay I donâ€™t believe in psychic ability so Iâ€™m going to say you are lucky - but scoring 100,000 would be highly improbable and you should screen shot it, and maybe look into the Randi educational foundation to test yourself for psychic ability.

Version 1.35
Changed the Title and text to be wider and larger.

1 Like

Hi Andrew,

What a great idea - completely turned the game upside down!

I am enjoying the subtle music and the graphics. One minor thing, I think the old +1 issue may have kicked in hereâ€¦

Thatâ€™s a tall order when you only accept `int` values

On this occasion I entered 921 and the game appeared to reset, back to picking a number between 1 and 1000, so not sure if my guess was right, or wrong.

Just letting you know in case you wish to fix.

Again, well done, really like the concept and it looks really nice.

Two other minor enhancements may be;

• default the cursor in the text field for the player at the beginning
• clear the playerâ€™s entered value and focus the text field again so the player can just enter their next number

I am returning now for another go!

1 Like

Yeah, good point, When the game resets that means you picked the correct number. I see how that is confusing, especially if you achieve a psychic power number of 1. Iâ€™ll fix it in the next version. You bring up all good points for improvements, some which I have not yet thought of. Thank you so much for your feedback.

1 Like

I think the word â€śonâ€ť is one of those words we canâ€™t help but neglect to notice, like â€śofâ€ť. The font certainly doesnâ€™t help, it looks kind of like â€śorâ€ť. I donâ€™t know what to do about that, maybe change the font? Or extend the range, I donâ€™t like the range idea, I think it ends up being more confusing. There werenâ€™t too many mystical fonts to choose from, I think I went through the whole list before I came upon this one.

1 Like

You have some good skills this helped me open my imagination.

2 Likes

I have to be honest I didnt actually read either of those wordsâ€¦ my focus was purely on the two values I had to pick between.

That could be of course because I have seen quite a few Number Wizards and of course you introduced it here as an inverted version so I just jumped in and started entering values.

1 Like

Iâ€™d be happy to see what you come up with. I had another Number Wizard concept where there are a certain number of rounds and you take turns with the computer guessing numbers and whoever has the lowest score wins, I think that would be a fun game. If you want help doing some of the stuff I did, let me know. That input field was a tad difficult to get working, it was hard for me to find resources on it. If you want to know how to do the input field please ask me within a week because Iâ€™ll forget how to do it otherwise.

1 Like

Iâ€™ve thought about defaulting the cursor after you suggested it. I have an idea of how to do it, but I anticipate two problems. My method of defaulting the cursor is to make my own cursor with a UI sprite and locking the cursor away. The first problem is that WebGL builds (correct me if Iâ€™m wrong) donâ€™t allow you to lock the cursor because it is in a web browser. The second problem is that I will have to make my own buttons as the on hover and click effects will only go into effect if the mouse, not the UI sprite, is hovering and clicking on it. I can do this, I am sure of it, but I donâ€™t have the will to. Not yet anyway.

I can probably figure out how to clear the Input field on clicking the submit button, I will try that first. Thank you Rob for your suggestions they are great suggestions and I will get to work on them.

1 Like

I updated the game with some of your suggestions. It is much better now, thank you!

1 Like

Sorry for the delay, I was AFK last night

Great to hear youâ€™ve made further updates to the game, I will go and have a play now!

The text to indicate the win state is really good, well done. I did find that I didnâ€™t have to click the button to continue playing though, I just popped another number in and submitted it, just so you know.

Just had a go, one thing Iâ€™ve noticed now is that the Enter key no longer works for submissions, which was handy before (as I wasnâ€™t clicking the submit button).

Also, regarding the focusing, the following should help with that, obviously only if you want to.

Drag input field from Hierarchy to script version

``````using UnityEngine.UI;

public class FocusExample : MonoBehaviour
{
public InputField _inputField;

private void Start()
{
_inputField.Select();
}
}
``````

or

Find the input field version

``````using UnityEngine.UI;

public class FocusExample : MonoBehaviour
{
private void Start()
{
InputField inputField = (InputField)GameObject.FindObjectOfType<InputField>()

inputField.Select();
}
}
``````

Both of the above assume that the script is attached to a game object within the scene, however, if you were to attach a script to the actual input field itself you could use the `GetComponent()` instead of having to find the actual game object.

You can obviously set the font colour, but you can also specify the carot width and colour too, which might quite nice to match your existing colour scheme. In my test I set the carot set to 3 and bright red which was nice, although an electric blue may suit your game better.

Anyway, just thought Iâ€™d share the above in case it was useful

Yeah the Enter key is no more, when I had to change the end, it meant I could no longer have two modes of entering. It began to double enter on submit which was fine in game, but post game it is not fine, you wonâ€™t see the end text otherwise.

I bet I could figure out a way to have both ways and have it work though

The script is attached to the input field itself, but I didnâ€™t attach the script (as a function that executes on the input field text change or on end edit) If that makes any sense to you - the function onButtonPress is only engaged when a person hits submit, I could do it onEndEdit for the input field, but it has a way of submitting twice in a row when the button is pressed, It actually works alright, but I thought that people would notice it bugging out.

Also, my algorithm which I thought was so clever, really was not clever, it is not a test for psychic power, there are ways to cheat it.

1 Like

Perhaps that is a more overall design issue? For example, at the end of the game when the player wins, do you really need to show the input field and submit button? Clearly, the player has won, and thus would expect to â€śrestartâ€ť in order to play again. Perhaps with either some game object disabling / enabling or, loading a â€świnâ€ť scene you could circumvent those issues entirely?

The input mechanic is one that you would probably want to consider in more detail if you were wanting to put your game on different platforms also. For example, on a PC (stand alone or web), I would imagine keyboard input would be fairly standard, obviously in partnership with the mouse.

For same a mobile or tablet, when I click inside your input field Iâ€™m going to be presented with my devices built in keyboard, which is going to overlap about a third of your game, this means that your really nice looking game is going to be under a fairly less nice looking grey keyboard (on my mobile at least) for most of its time when I play. This could be an entire design decision in itself, for example, perhaps you could have an actual number pad on the screen.

With the above example, you could potentially make the input field a text field, and just update its text value as the â€śbuttonsâ€ť on your number pad were pressed. The submit button would also be 100% useful again and there would be no need for Enter key support.

Just a thought, not suggesting for a moment you implement this one, but something that is definitely worth considering when making games for multiple platforms, in the above example, it could be that by adding the number pad it actually saves a lot of hassle trying to work out the Enter key and Submit button dual support issue - and all the while makes the game more cross platform compatible.

Regarding your algorithm, hehe, well Iâ€™ve not spotted anything obvious yet, I was simply finding the mid point each time and trying thatâ€¦ so you could say that in order to cheat youâ€™d have to have some form of psychic ability

My brother, the first time playing this game, played 8 rounds and scored 53 million! Iâ€™ve played the game over 40 times and my high score is 37. I thought it was broken so I asked him to play again, and he wasnâ€™t able to score higher than 8. I changed the algorithm before that. No more negative scores, in a way now it is harder. More ways for a playerâ€™s score to go down.

Just when I feel like I have a firm grasp on the statistics of the game, Iâ€™m befuddled.

1 Like

Thatâ€™s an impressive score!

hehe, but look at the progressive iterations you are making on your game - how awesome is that

Iâ€™m still not 100% sold on this situation though;

That to me feels like a lose condition, e.g. the player ran out of possibilities and lost but because you also accept the â€śonâ€ť a number option you have to allow it I guessâ€¦

I like the Play button, that looks better.

I have found I can not enter a value and still click the submit button though, it makes the little sound, and, as a player, I donâ€™t know whether doing this is having a negative effect against my score - e.g. if itâ€™s based at all on the number of guesses Iâ€™m makingâ€¦ on each occasion the input field has a zero in it.

May be better to have `inputField.text = string.Empty;` and then have some validation that enforces a value to be entered before the submit button can be pressed?

I am still missing my Enter key functionality *sniff*

I also just won a game, had a score of 10.06, played again straight after (on the above example as it happens) - entered 379 and submitted it. But my score reset to zero? Does that mean I lost some how on that round?

Updated Fri Jul 28 2017 22:34

Looks like Iâ€™m hitting a lose condition?

This was after two successful roundsâ€¦

I whittled it down to only this number remaining, entered it, which had to be the correct number, I got congratulated, but my score was reset to zeroâ€¦ how rudeâ€¦

Are you multiplying the score by the number of possible guesses remaining by any chance? e.g. I had no remaining guesses, thus the score was multiplied by zero?

1 Like

Yes that is right. The algorithm mulitiplies the range which is equal to the inverse of the (chances of guessing right)/(chances of guessing wrong) (or the range) and it is multiplied by the chances of guessing wrong for each wrong guess multiplied with one another.

So say the secret number is 521
your range is 1/1000 or 1/999 inverse if you guess it on the first guess a score of 999 or the range of 1-1000

say it takes you 2 guesses

first guess 500
range 501-1000
998/999 * 497/498 * 498

This algorithm doesnâ€™t change values that much until you approach the range of the number, then it kind of becomes a big deal, and you can have decimal values that when multiplied by your score can decrease it a great deal.

What I havenâ€™t figured out,

Say you start from one end 1, then guess 2 than 3 than 4

Chances are 50% that by the time you get to 500 you would have guessed the number, then the psychic power algorithm should return a value of 1 Chances of guessing right/gussing wrong I donâ€™t think that is the case

Iâ€™m liking the lose condition text, feels like it flows much better now.

Chances are 50% that by the time you get to 500 you would have guessed the number, then the psychic power algorithm should return a value of 1 Chances of guessing right/gussing wrong I donâ€™t think that is the case

That 50% chance is changing each time the player has a go though isnâ€™t it? And wouldnâ€™t that only be the case of the selected number was actually 500, and that percentage would only be true on the first turn. I think!

Any thoughts on applying that focus code? Iâ€™m finding as I play each game that Iâ€™m using the numpad on my laptop with my left hand and click on the mouse with my right hand, my coordination is not as fast as my brain determining which number to type next. With the input field being focused Iâ€™d only have to type and click the submit button

1 Like

So what will happen say the number is 500, a person guesses 1 then 2 then 3 then 4 and so on.
What my algorithim will do is when it gets to 500 it will be 1/2 * 499 (the remaining range) giving a result of 249.5 when the real result should be 1. Iâ€™m getting closer to a perfect algorithm for testing psychic ability, one that cannot be cheated. I feel like I have all the pieces of the puzzle but I donâ€™t know how it all fits together.

Yeah, that is a good point with the focus code. Iâ€™ll have to look into that.

1 Like

I think I solved it.

My plan is to create an array of subranges and have the computer determine which subrange has the greatest proportion of incorrect guesses.

for sub range where all numbers in sub range divided by guesses in subrange is lowest.

if( ((all numbers in sub range) / (guesses in sub range) - 1) < psychic power)){
psychicPower = (all numbers in sub range) / (guesses in sub range) - 1)

1 Like

Hi Andrew,

Is that all numbers in sub range as in, a total of the individual numbers available, as opposed to a sum of the total numbers available?

Have you tried it, did it work for you?

1 Like

I tried something else, much easier than what I was talking about, I think I have the best possible algorithm to test for psychic power
I have something called the psychic power detractor, which multipiies by chances of incorrect with each wrong guess.

``````psychicPowerDetractor = (range before wrong guess -1)/range before wrong guess)
PsychicPowerDetractor *= (range before wrong guess -1)/range before wrong guess)

if (psychicPowerDetractor < psychicPower)
{
psychicPower = 1/psychicPowerDetractor -1
}
``````

So basically in most cases the inverse of the psychic power detractor minus one will be the score. This new algorithm prevents cheating.