2

I want to make simple guessing game. Players guessing letters from secretary. If player choice is in secretary then player get some point. Now I have 4 lists of letters sorted by points value:

//List of letters:
private string[] fivePointsLetters = { "q", "w", "ď", "x", "ň", "ú", "g", "ä", "ô", "ó" };
private List<string> fourPointsLetters = new List<string> { "f", "ů", "š", "č", "ž", "ý", "ch", "í", "ú", "é", "á", "ý" };
private List<string> threePointsLetters = new List<string> { "ř", "h", "é", "b", "c", "ě", "j", "z", "á", "k", "f", "v", "r", "y" };
private List<string> twoPointsLetters = new List<string> { "a", "e", "i", "o", "u", "d", "n", "t", "v", "s", "l", "k", "r", "p", "í", "m" };

GameManager pick random 4 twoPointLetters, random 3 threePointLetters, random 2 fourPointLetters and only 1 fivePointLetters. Now happens, that in this 10 picked letters there are not correct letters from secretary. So I devise that I should create new List with only correct letters(split answer string). And then GameManager should pick from this List not all values, but for example 30% correct letters. So player can pick one of 10 letters, but only 3 letters will be correct in secretary.

Problem is that I do not know how to pick for example only 30% values from List. Is there any solution or have you any idea how to do this please?

EDIT:

Picking random letters example:

for (int i = 0; i < button2b_value.Count; i++)
{
    List<string> filteredStrings = twoPointsLetters.Except(usedLetters).Except(button2b_value).ToList();
    if (filteredStrings.Count == 0)
    {
        Debug.LogWarning("No possible 2 point letters in list");
    }
    else
    {
        int index = UnityEngine.Random.Range(0, filteredStrings.Count);
        view.RPC("Set2ButtonsValuesRPC", RpcTarget.All, filteredStrings[index], i);
    }
}
orhtej2
  • 2,133
  • 3
  • 16
  • 26
V1lko
  • 53
  • 8
  • Can you please provide [mcve] showing how are you picking the letters currently? – orhtej2 Mar 20 '23 at 10:24
  • 1
    @orhtej2 Sorry, my bad. I edited main post already – V1lko Mar 20 '23 at 10:28
  • If I understand the question correctly picking n% random values from a list can be done like explained here: https://stackoverflow.com/questions/48087/select-n-random-elements-from-a-listt-in-c-sharp – orhtej2 Mar 20 '23 at 10:32
  • 1
    I'm unclear on what "Now happens, that in this 10 picked letters there are not correct letters from secretary." means. I'm also not sure where the contents of `usedLetters` collection are sourced from. Can you provide more context? – orhtej2 Mar 20 '23 at 10:36
  • In secretary is answer for example "hi" but gameManager pick random letters where there are not "h" or "i". So player dont have chance to guess correct. I need to do that everytime in values what GameManager pick, will be at least one correct letter. In this example correct letter is "h" or "i" – V1lko Mar 20 '23 at 10:40
  • 1
    Can you walk me through how this game is meant to be played? It's something like Wordle? The hidden thing the player is supposed to guess - is it a word? In the example you gave - "hi" - what is expected player input and why should you get any points if your guess does not contain letters h nor i? – orhtej2 Mar 20 '23 at 10:44
  • 1
    It is turn based game. So when turn start player will see 10 letters which GameManager pick from lists of letters, empty squares(answer) and question. When player click on one of this letters, GameManager check if letter that player choose is in the answer. If it is true player get points for this round, this one letter is added to usedLetters List and letter that player choose shows in secretary(in empty squares), if not then this 10 letters change. – V1lko Mar 20 '23 at 10:51
  • 1
    it is somthing like hangman game, but players dont lose points when choose not correct letter and answer its not random word but answer on question. Example of hangman game: https://www.gamestolearnenglish.com/hangman/ – V1lko Mar 20 '23 at 10:53
  • 1
    Another example: question is "who discovered America?", Answer is "Columbus". Player every round see 10letters from which he can pick one – V1lko Mar 20 '23 at 10:57
  • 1
    ^ that should be a part of problem statement in the question itself, it's super useful. – orhtej2 Mar 20 '23 at 10:57
  • questions are mostly harder then this and intention of this game is to improve knowledge, not only fun :D But now I this problem that in this 10 letter from which player can choosing there are sometimes not correct letter, so players must picking wrong letters until good letter is picked but GameManager. This is why I need to always have min 1 good letter in this 10 letters :D – V1lko Mar 20 '23 at 11:08
  • 1
    Regarding that Columbus example - would clicking 'u' button reveal 2 tiles? – orhtej2 Mar 20 '23 at 11:12
  • Yes, and "u" is in 2pointLetters List so player get 2 point * 2 because in answer there are 2 "u" – V1lko Mar 20 '23 at 11:14
  • 1
    Consider [the following code](https://gist.github.com/orhtej2/975f3746be225068d5f629e4605f0cf0) to get you started, it DOES NOT consider 'ch' a valid letter like your example. What it reveals however is the fact that there are intersections between your letter-to-points arrays. Are these intentional? – orhtej2 Mar 20 '23 at 11:41
  • this is perfect :) Thank you very much code is clear and your answer is understandably. Thank you :) – V1lko Mar 20 '23 at 11:58
  • Don't describe your problem in endless comments, instead add all info to the question. – Palle Due Mar 20 '23 at 13:00

0 Answers0