Skip to content

Q learning like Dice Game that simulates two players rolling a learned amount of dice until one player wins. The conclusion of each game updates the Wins/Losses tables so that the optimal amount of dice can be selected from a learned probability weighed dice distribution.

Notifications You must be signed in to change notification settings

nrush23/Dice_Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

***COMPILING/RUNNING THE PROJECT***

1. Unzip the project in your desired folder.
2. If you are in Linux, run the ./build.sh file.
   Otherwise:
        Open a terminal
        cd into the project folder
        Run javac dice.java
3. Run your specific test using: java dice -ND # -NS # -M # -H # -L # -G # [-v]
        ND: number of dice you'd like to roll
        NS: number of sides each dice has
        M: Parameter for exploit vs exploration
        H: High score boundary for winning
        L: Low score boundary for winning
        G: number of games to play
        v: optional verbose mode
        #: number for a given parameter

   Example runs:
        java dice -ND 3 -NS 6 -M 10 -H 31 -L 19 -G 3 -v
        java dice -ND 8 -NS 12 -M 2 -H 20 -L 15 -G 12

*** SIMULATION() INFO ***

The simulation works by executing a for loop of the game the given -G amount of times.
Inside the for loop is where the game is actually played. Until a winner is found, a while loop
switches between Player A and Player B turns. Each turn consists of the player getting a dice amount
based on their current state and then rolling them. If L <= Score <= H, the player wins and the game stops.
Otherwise, if Score > H, the player loses, so the other player wins and the game stops. If there was no win
or loss, the turns change and the game continues.

After a game ends, my Simulation uses the history of each player to update the Wins and Losses tables based on my
Entry class that stores what specific turn's dice, X (current player's score), and Y (other player's score) values were.

The simulation then proceeds to the next game using the updated Wins/Losses until there are no more remaining
games to be played and the output table is printed.

*** ROLLING THE DICE ***

The amount of dice to be rolled is determined by the getDice(X,Y) function. Given a state <X,Y>,
where X is the current score of the player rolling and Y is the score of the opponent, getDice 
calculates the Win probability for each dice of that state. Win probability is Wins[X,Y,d]/Losses[X,Y,d] or 0 if Losses if 0.
It then proceeds to pick the highest probability or randomly choosing when there are more than one equivalent maxes.
From here, a probability distribution is created weighing the maximum value the highest. From this distribution,
the number of dice gets distributed according to its probability weight. To select the amount of dice,
the generated dice distribution is then sampled and returned to the simulation.

***OUTPUT***

The final game output is generated by a L by L table. Each entry <X,Y>, where X is the current player's score
and Y their opponent, shows the optimal dice to roll followed by its Win probability. If an entry state was
never played, the table displays N/A. For detailed output, use the -v flag to see the turns played throughout the
simulation.

About

Q learning like Dice Game that simulates two players rolling a learned amount of dice until one player wins. The conclusion of each game updates the Wins/Losses tables so that the optimal amount of dice can be selected from a learned probability weighed dice distribution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages