Search Unity

2D Dice Game.

Discussion in '2D' started by MurcsRoyce, Oct 10, 2017.

  1. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    I need help with rolling the six dice and having 6 new random dice pictures appear.
    the game needs to know which dice are on the board then calculate which hand you have upon hitting bank score.
    also holding dice and not rolling any held dice. to increase your possible high hand. maybe 3 rolls total.

    That is pretty much the game. everything else is whistles and bells and networking.

    i have created the script and it works awesome in c# with windows forms inside visual studio. i simply need to recreate this in unity. once i do this with these dice. i will have a much better understanding how unity works and uses objects.

    this is all high hands. 2 pair, 3 pair, 3 of kind, 4 of kind, 5 of kind, 6 of kind, straight, two sets of 3, full house = 2222 33.
    9 high hands possible.

    i’m willing to invest the time. i just need help. The photo i posted is built with unity and is my current layout/scene
     
  2. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
  3. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    I put together something. Hope if it helps you. Although I am not quite sure that I understand your problem perfectly.
    Tell me if it is what you want.
     

    Attached Files:

    MurcsRoyce likes this.
  4. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    thank you . thats exactly what i was looking for.. i would appreciate it if you could help me until this dice rolling is complete within unity. There were some bugs within your code and some stuff is not commented and i dont understand some of the code. Fullhouse is not working when it hits 4 and 2. And i had to run an arron so i didnt get to fully test . Ill be back home in 1 hour.

    Things to complete dice roll.

    I have a star dice for wild card or equal to any dice.

    Holding dice and re rolling other dice

    And no high hand bugs
     
  5. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    I've attempted to fix the Full House bug/ Two Sets of Three, and I cannot. no matter what i do it renders four of a kind.
     
  6. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    Ac
    Actually I had no idea what is your high hands. I just went with my guesses. If you explain them, I can make it work.

    Yes, Sure. That's why I am here.

    Ask me anything that looks confusing or wrong to you.

    I thought full house is only made with 4 twos and 2 threes.

    Does star replaces any specific numbers? Or we just have 7 possibilities for each dice?
     
    Last edited: Oct 12, 2017
    MurcsRoyce likes this.
  7. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    I made a few changes. Fixed a few bugs and added hold buttons.
    Let me know if anything looks wrong.
     

    Attached Files:

    MurcsRoyce likes this.
  8. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    so two sets of three and full house can be any numbers. two sets can be = 111,222 or 555,333. and same for full house 1111,22 or 6666,33. its anytime 4 of any dice is the same and 2 of any dice is the same.

    the star is a 7th dice and very complicated . when the star hits the board it can be 1 or 2 or 3 or 4 or 5 or 6 like a wild dice.

    holding the dice will consist of clicking the actual dice. and have its color changed from white to blue.or red or anything.

    i'm going do 3 chances to gain the best hand you can. or 3 rolls to gain the best hand you can.

    i hope i'm explaining this good enough. and i want to say thanks your helping me get this dice iteration done and i just need these dice to work with no bugs so i can move on with my project.

    leaving the star wild for last is way ok with me. the main iteration is much more important and trust me the star wild gets really hairy and conflicts with the rest of the script layout. after the dice are very nicely scripted with no bugs then id like to attempt to add the star wild. it will actually be very important at some point later in the game creation.

    for instance like acquiring 25 stars in a single game would award bonus points.
    it also changes the luck factor and allows people to get really good rolls. six of kind pays allot of points and with stars you can achieve some of the high pointed hands.
     
  9. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    Well, I guess this is what you need, minus the star dice.
     

    Attached Files:

    MurcsRoyce likes this.
  10. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    I just got to work. Ill check it out when i get home. Thanks for helping and for your time . Its much appreciated.
     
  11. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    Code works good. no bugs as of yet. thank you very much. When im done with demo version, i will post it on my website for download. and ill post that back here on this page in case you want to see or play my version of this game.
     
  12. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    I look forward to see your game.

    Now please explain a little more about that star dice. We can add that to the game now.
     
    MurcsRoyce likes this.
  13. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    Ok, i'm excited about the star dice. the star simply can = a 1 or 2 or 3 or 4 or 5 or 6. if you roll 1234,star,star. that would = a straight. i think its going to be hard to do and not conflict with the other code. I'm Hoping there is a simple method that can achieve this.

    another example 666,star,star,star = six of a kind

    Star = wild dice , 1 or 2 or 3 or 4 or 5 or 6

    i hope i explained it well enough
     
    Last edited: Oct 15, 2017
  14. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    I've managed to modify it and it seems to work. I tested it with your examples. Only one difference. I simulated a 666,star,star,star and it gave me a full house. Because it thought that it can be 666611 instead of 666666, and a full house is more valuable than a six of a kind. Is it correct behavior?
     
    MurcsRoyce likes this.
  15. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    666,666 is highest score possible. post your star code because ive simulated true and false statements for scoring purposes.
     
  16. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    It has a bug, I am working on it. Probably take like half an hour. In the meantime can you tell me the high hands in order of best to worst?
     
    MurcsRoyce likes this.
  17. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    until i further test probability scoring is just set to random numbers right now. here's what i have.

    Code (csharp):
    1.    
    2.  
    3.     int onepair = 100;
    4.     int threekind = 150;
    5.     int twopair = 250;
    6.     int fourKind = 400;
    7.     int threepair = 1000;
    8.     int fullhouse = 1000;
    9.     int twosets = 1500;
    10.     int fivekind = 1500;
    11.     int straight = 2500;
    12.     int sixkind = 5000;
    13.  
    14.  
     
  18. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    here's my script with scoring , everything works perfect

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class SceneController : MonoBehaviour
    5. {
    6.     public Dice[] dices;
    7.     public Text handText;
    8.     public Text[] buttonTexts;
    9.  
    10.     int onepair = 100;
    11.     int threekind = 150;
    12.     int twopair = 250;
    13.     int fourKind = 400;
    14.     int threepair = 1000;
    15.     int fullhouse = 1000;
    16.     int twosets = 1500;
    17.     int fivekind = 1500;
    18.     int straight = 2500;
    19.     int sixkind = 5000;
    20.  
    21.     public bool HasOnePair = false;
    22.     public bool HasTwoPair = false;
    23.     public bool HasThreePair = false;
    24.     public bool HasTwoSets = false;
    25.     public bool HasFullhouse = false;
    26.     public bool HasThreeKind = false;
    27.     public bool HasFourKind = false;
    28.     public bool HasFiveKind = false;
    29.     public bool HasSixKind = false;
    30.     public bool HasStraight = false;
    31.  
    32.     bool[] holds;
    33.  
    34.     void Start()
    35.     {
    36.        // holds = new bool[dices.Length];
    37.     }
    38.  
    39.     public void RollDice_Click()
    40.     {
    41.         for (int i = 0; i < dices.Length; i++)
    42.         {
    43.             if (dices[i].hold == false)
    44.                 dices[i].ShowRandomFace();
    45.         }
    46.  
    47.         HighHands hand = DetectHighHands(dices);
    48.         handText.text = hand.ToString();
    49.     }
    50.  
    51.     int[] repeats;
    52.     public HighHands DetectHighHands(Dice[] dices)
    53.     {
    54.         repeats = new int[6];
    55.  
    56.         // find out how many times each number is repeated
    57.         for (int i = 0; i < dices.Length; i++)
    58.         {
    59.             repeats[dices[i].faceIndex]++;
    60.         }
    61.  
    62.         bool four = false;
    63.         bool two = false;
    64.         int threes = 0;
    65.         for (int i = 0; i < repeats.Length; i++)
    66.         {
    67.             // is there a number with 4 repeats?
    68.             if (repeats[i] == 4)
    69.                 four = true;
    70.  
    71.             // is there a number with 2 repeats?
    72.             if (repeats[i] == 2)
    73.                 two = true;
    74.  
    75.             // how many sets of threes do we have?
    76.             if (repeats[i] == 3)
    77.                 threes++;  
    78.         }
    79.  
    80.         if (four && two) // 4 twos and 2 threes
    81.         {
    82.             HasFullhouse = true;
    83.             HasThreeKind = false;
    84.             HasThreePair = false;
    85.             HasTwoSets = false;
    86.             HasTwoPair = false;
    87.             return HighHands.FullHouse;
    88.         }
    89.         else
    90.         {
    91.             HasFullhouse = false;
    92.         }
    93.         if (threes == 2) // 2 sets of three
    94.         {
    95.             HasTwoSets = true;
    96.             HasThreeKind = false;
    97.             return HighHands.TwoSetsOfThree;
    98.         }
    99.         else
    100.         {
    101.             HasTwoSets = false;
    102.          
    103.         }
    104.  
    105.         // detect if there is one of each number - straight
    106.         bool isAllOneSoFar = true;
    107.         for (int i = 0; i < repeats.Length; i++)
    108.         {
    109.             if (repeats[i] != 1)
    110.             {
    111.                 isAllOneSoFar = false;
    112.                 break;
    113.             }
    114.         }
    115.  
    116.         if (isAllOneSoFar)
    117.         {
    118.             HasStraight = true;
    119.             return HighHands.Straight;
    120.         }
    121.         else
    122.         {
    123.             HasStraight = false;
    124.         }
    125.        
    126.         // detect if it is a straight hand
    127.         for (int i = 0; i < repeats.Length; i++)
    128.  
    129.         {
    130.  
    131.             if (repeats[i] == 6)
    132.             {
    133.                 HasSixKind = true;
    134.                 return HighHands.SixOfAKind;
    135.             }
    136.             else
    137.             {
    138.                 HasSixKind = false;
    139.             }
    140.             if (repeats[i] == 5)
    141.             {
    142.                 HasFiveKind = true;
    143.                 return HighHands.FiveOfAKind;
    144.             }
    145.             else
    146.             {
    147.                 HasFiveKind = false;
    148.             }
    149.             if (repeats[i] == 4)
    150.             {
    151.                 HasFourKind = true;
    152.                 return HighHands.FourOfAKind;
    153.             }
    154.             else
    155.             {
    156.                 HasFourKind = false;
    157.             }
    158.             if (repeats[i] == 3)
    159.             {
    160.                 HasThreeKind = true;
    161.                 return HighHands.ThreeOfAKind;
    162.             }
    163.             else
    164.             {
    165.                 HasThreeKind = false;
    166.             }
    167.         }
    168.  
    169.  
    170.         // find the number of pairs
    171.         int pairs = 0;
    172.         for (int i = 0; i < repeats.Length; i++)
    173.         {
    174.             if (repeats[i] == 2)
    175.                 pairs++;
    176.         }
    177.  
    178.         if (pairs == 3)
    179.         {
    180.             HasThreePair = true;
    181.             return HighHands.ThreePair;
    182.         }
    183.         else
    184.         {
    185.             HasThreePair = false;
    186.         }
    187.  
    188.         if (pairs == 2)
    189.         {
    190.             HasTwoPair = true;
    191.             return HighHands.TwoPair;
    192.         }
    193.         else
    194.         {
    195.             HasTwoPair = false;
    196.         }
    197.  
    198.         if (pairs == 1)
    199.         {
    200.             HasOnePair = true;
    201.             return HighHands.OnePair;
    202.         }
    203.         else
    204.         {
    205.             HasOnePair = false;
    206.         }
    207.  
    208.             return HighHands.None;
    209.     }
    210.     public void BankScore()
    211.     {
    212.         if (HasFullhouse)
    213.         {
    214.             Debug.Log("Has Full House");
    215.             AddScore.score += fullhouse;
    216.         }
    217.    
    218.         if (HasStraight)
    219.         {
    220.             Debug.Log("Has Straight");
    221.             AddScore.score += straight;
    222.         }
    223.        if (HasTwoSets)
    224.         {
    225.             Debug.Log("Has Two Sets of three");
    226.             AddScore.score += twosets;
    227.         }
    228.         if (HasTwoPair)
    229.         {
    230.             Debug.Log("Has Two pair");
    231.             AddScore.score += twopair;
    232.         }
    233.          if (HasThreePair)
    234.         {
    235.             Debug.Log("Has Three Pair");
    236.             AddScore.score += threepair;
    237.         }
    238.         if (HasSixKind)
    239.         {
    240.             Debug.Log("Has Six of A Kind");
    241.             AddScore.score += sixkind;
    242.         }
    243.          if (HasFiveKind)
    244.         {
    245.             Debug.Log("Has Five of A Kind");
    246.             AddScore.score += fivekind;
    247.         }
    248.          if (HasFourKind)
    249.         {
    250.             Debug.Log("Has Four of A Kind");
    251.             AddScore.score += fourKind;
    252.         }
    253.          if (HasThreeKind)
    254.         {
    255.             Debug.Log("Has Three of A Kind");
    256.             AddScore.score += threekind;
    257.         }
    258.     }
    259. }
    260.  
    261. public enum HighHands
    262. {
    263.     None,
    264.     OnePair,
    265.     TwoPair,
    266.     ThreePair,
    267.     ThreeOfAKind,
    268.     FourOfAKind,
    269.     FiveOfAKind,
    270.     SixOfAKind,
    271.     Straight,
    272.     TwoSetsOfThree,
    273.     FullHouse,
    274. }
     
  19. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    َAnd finally it is done. Star dice works like a peach (and I think it is a very exciting feature in your game)
    I used a recursive function to check all the possible combinations. The recursion level is as many as stars appearing in the hand and it works beautifully.
    Check it and let me know the result.
     

    Attached Files:

    • Dice.rar
      File size:
      58.5 KB
      Views:
      398
    MurcsRoyce likes this.
  20. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    works great. good job man. thank you.
     
  21. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
  22. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    I checked it. It's cool :cool:
    Do you want to make it a mobile game or pc?
     
    MurcsRoyce likes this.
  23. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    Its going to be a pc install. With plans to be global multiplayer. With big jackpots for real money. If it becomes popular well make a mobile version. Hey btw did the particle systems work for you ?. My buddy downloaded it and said theres no particle systems
     
  24. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    No. No Particles. Maybe it is a Z-fight problem.

    I hope it'll be a huge success my friend :)
     
    MurcsRoyce likes this.
  25. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    Need your help again. ok so there is some issues with how the dice work compared to how the game is suppose to work.

    the way you have it coded its checking for highest hand possible. when in fact that's eliminating the users choice and users attempt to achieve a higher hand. i have a solution but since there's 270 lines of code now its becoming confusing.

    so here's my thought and plan. I hope i can explain this so you understand. We need to lock the held dice and change its color to red. upon locking lets say 3 dice , we need to run a check for highest hand possible for the held dice not the entire six dice.

    the key to this game is achieve a six dice roll. allowing the player to roll the six dice AGAIN rather then banking.

    any 1 or 5 or six dice score allows the player to roll again. if a player has EXAMPLE: 333155 this would consist of six dice locked and a valid six dice hand allowing the player to re roll all six dice.

    EXAMPLE 2 : player rolls 333,466 player then holds and locks 333 and re rolls the other dice and hits 666 this would enable to player to re roll all six dice because he has 2 sets of three. To build is score higher and higher.

    EXAMPLE 3: player rolls 444,662 Player holds and locks 444 then rolls the other 3 dice. hitting 562 because the player has a 5 he can lock the 5 and re Roll the other 2 dice. he now has 4445.

    If the player fails to achieve a situation not allowing him to gain any points then he would loose all his points.
    EXAMPLE 4: player rolls 444,662, player holds and locks 444 but then roll 336. turn would be over he failed to achieve more points. Only if pulling a six dice hand or hitting a 1 or 5 would allow the continuation of another roll..

    1 will declare 150 points.
    5 will declare 250 points.
    Lets say three of a kind declares 350 points

    EXAMPLE 5: player rolls 666, 513 Player then locks 66651 and is able to re roll the 3. Here is where the fun comes from and this is what were currently bypassing. 66651 = 750 points. player can choose to bank score or attempt to roll his sixth dice to achieve a 1 or 5 or 6 because 6 would = 4 of a kind . If player achieves this he can re roll all six dice. if player fails and lets say rolls a 2 or 4 then he would loose his 750 points and turn would be over.

    i know i typed allot and its allot to take in but i tried explaining this the best i could . its really simple when you play and understand the concept. The main key points are locking the held dice until round is over or until a six dice re roll is available. and the 1 and 5 being involved to allow a re-roll. Ill be working on it or here to answer any questions you have for me thank you.
     
  26. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    I have this feeling i have to much in one script. Should we break all this code down into small scripts . Like one script per function. Would that make it easier to manage ?
     
  27. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    I've read your post 2 times and still not have a clue about what you want :p
    first things first.

    How we are eliminating user's choice? What choice is that?

    It's usally a good thing to keep your script files short and simple. But the breaking down process also have to make sense. It's one action, one job. Therefore I think it's better to remain as one file. But it's your project, you should decide which way is more convenient for you.
     
    Last edited: Oct 17, 2017
    MurcsRoyce likes this.
  28. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    once a player holds a dice it cannot be un-held, until his turn is over. We need to check if he has a 1 or 5 or minimum 3 of a kind / Lowest high hand possible.

    the dice need to lock after holding them.

    here's the process

    Step One: Player rolls the dice
    Step Two: Player decides which dice to hold. Minimum of 3 of a kind (OR) having a single 1 or 5.
    Step Three: Check the players choice to make sure hes holding a valid roll then lock those dice
    Step Four: Re- Roll the UNHELD dice. If a player rolls NO new points round is over.
     
  29. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    So player can't just hold any dice? He/She has to follow rules. And what happens if they don't?

    New points means a better high hand than the last one?
     
    MurcsRoyce likes this.
  30. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    I think ive somewhat confused you with the 1 and the 5, And we can add that part after we fix this main problem.

    NEW EXAMPLE: Player rolls 444, 323 . Player then holds the 444 and re rolls the other 3 dice. Now the 444 are locked and cannot be unheld. Upon the re-roll the player now has (444)423 Player holds the new 4 and now has 4 of a kind and can re-roll the other 2 dice. Upon the re roll the player now has (4444)43 Player holds the new 4 and now has 5 of a kind and can re-roll the last dice. If the player gets lucky and hits sixofakind he can reroll ALL SIX DICE. if the player does not his turn is over banking no points.

    A player can bank at anytime to bank points instead of loosing his whole hand
     
  31. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    Ok ive found a online game thats quick and simple and its exactly what im trying to achieve please play it. At the bottom choose to play with computer and you will see what im trying to do. no account creation required

    http://www.playonlinedicegames.com/farkle

    I appreciate you being patient with me helping again.
     
    MiladZarrin1 likes this.
  32. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    Thank you for the example. I think I got it. Let me think a little about it. I'll come back to you soon.
     
    MurcsRoyce likes this.
  33. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    OK. In the example you gave me, there is no signs of high hands. Instead we have this scoring table:

    Category Score
    Each 1 100
    Each 5 50
    Three 1s 1000
    Four 1s 2000
    Five 1s 3000
    Six 1s 4000
    Three 2s 200
    Four 2s 400
    Five 2s 600
    Six 2s 800
    Three 3s 300
    Four 3s 600
    Five 3s 900
    Six 3s 1200
    Three 4s 400
    Four 4s 800
    Five 4s 1200
    Six 4s 1600
    Three 5s 500
    Four 5s 1000
    Five 5s 1500
    Six 5s 2000
    Three 6s 600
    Four 6s 1200
    Five 6s 1800
    Six 6s 2400
    Straight (1-2-3-4-5-6) 1500
    Three pairs 750

    Do you have this scoring system in your game too? And the game only allows me to re-roll if I have some score with my held dice. Is that correct?
     
    MurcsRoyce likes this.
  34. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    OK. It's done (again minus star dice). Check it out and let me know the result.
     

    Attached Files:

    • Dice.rar
      File size:
      59.9 KB
      Views:
      442
    MurcsRoyce likes this.
  35. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38
    Ok thanks man ill check it out when i get home from work. Thank you

    And your scoring table is correct

    I wanted to add six dice scores. Like
    Two sets of three , fullhouse, three pair. And the star wild , to not completely copy that game. And my game will score more points and go past 10,000 for final score