Created
October 19, 2015 18:40
-
-
Save mbeltagy/7e5f45a38f30359d6205 to your computer and use it in GitHub Desktop.
Calculating the probability of getting a double dice to move peg to any particular point after where it is in game of backgammon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function backgammon_prob() | |
location_hits=zeros(Int,24) | |
for i=1:6, j=1:6 | |
if(i!=j) # to avoid double counting doubles | |
location_hits[i]+=1 | |
location_hits[j]+=1 | |
else | |
location_hits[j]+=1 | |
end | |
location_hits[i+j]+=1 | |
if i==j | |
location_hits[3*i]+=1 | |
location_hits[4*i]+=1 | |
end | |
end | |
return location_hits//36 | |
end | |
#Now for the plotting | |
using PyPlot | |
probs=backgammon_prob() | |
ax=subplot(1,1,1); | |
bar(1:24,probs,align="center") | |
tickLocations=[0.0:0.05:0.5...]; | |
tickText=["$(iround(i*100))\%" for i in tickLocations] | |
ax[:set_yticks](tickLocations) | |
ax[:set_yticklabels](tickText) | |
xticks(1:24) | |
xlabel("Location of Dice Throw") | |
ylabel("Probability") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment