Building a guessing game on UIPath

Hi everyone!

I am trying to build a guessing game that requires a user to enter a valid 4-digit in an attempt to guess the random number generated by the workflow. For every attempt made by each user, I want to show the “correctness” of the result.

For instance, if the randomly generated number is 1234 and a user enters 1345, I want to prompt a message box to show “2A” and “1B” respectively. “2A” signifies two correct numbers but in the wrong position (in this case numbers 3 and 4) while “1B” signifies 1 correct number in the correct position (in this case number 1).

May I know which activity(es) can be used to incorporate the aforementioned into the workflow? Any help is greatly appreciated!

1 Like

Hi @zsgg
Welcome to the UiPath Community!

This is a brilliant idea for a bot-run game!
You should be able to implement this by using mainly two String methods:

  1. String.Contains
  2. String.IndexOf

Run a loop on the digits of the number randomly generated by the workflow.
Check if user input contains that digit by using Contains method.
If yes, check if the IndexOf that digit matches the index of that digit in your number.

This in conjunction with If activity blocks should get you the desired result.

Hi @zsgg

welcome to forum!!!

check this workflow (33.6 KB)

Thanks for nice question

Nived N
Happy Automation

Hi NIVED_NAMBIAR, I tried to adapt your solution and migrate it into my current workflow but I have faced the following error:

Can I better understand the problem behind this error and how I can resolve it?

Can u show the property panel of for each activity?

Hi @NIVED_NAMBIAR, I have resolved the earlier issue, thank you so much! However, I spotted another exception when running the robot:

In this case, the randomly generated number is 6902. But when 6909 is entered, “1A 3B” is shown because the second digit ‘9’ is still found within the randomly generated number. However, the output I expected to see is “0A 3B” since the second digit ‘9’ do not belong anywhere in the randomly generated number anymore. Would like to hear your inputs on this, thank you so much!

Hi zsgg may I know if you have more updates on this project? Would like to chat and share because I’m interested on working on this too