d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Paying Fg For A Script
12Next
Add Reply New Topic New Poll
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 02:04pm
i'll pay 2k for a good script that allows me to graph the results. Your choice in the language you use as long as it is free to get online (you can use excel if you want).

Long story short I want to simulate a bunch of games of shut the box, here is the link to its wikipedia with the rules http://en.wikipedia.org/wiki/Shut_the_Box. I am going to be looking at the percent chance to win using different strategies. I need to do at least two different strategies, but three would be ideal. The first strategy would be to pick the highest number that you can use. The second strategy would be to use the most amount of numbers that you can per turn. The third would be to try to use combinations of mid value numbers. This last one being the most difficult to program I would assume and I can live without getting it to work. I am sure this is a bit confusing so please post questions. I will summarize the main programing tricks that you will need to use below. If you think you are capable of writing a code like this I will give you a more detailed explanation of the strategies.

Simulate two dice being rolled
Pick which numbers to use depending on the strategy that is being simulated
not use the numbers picked for the rest of that given game
Count the number of wins ( used all numbers 1-9) and losses (you do not have numbers that sum up to the number rolled)

Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 04:10pm
Quote (HaloGod @ May 5 2015 04:04pm)
i'll pay 2k for a good script that allows me to graph the results. Your choice in the language you use as long as it is free to get online (you can use excel if you want).

Long story short I want to simulate a bunch of games of shut the box, here is the link to its wikipedia with the rules http://en.wikipedia.org/wiki/Shut_the_Box. I am going to be looking at the percent chance to win using different strategies. I need to do at least two different strategies, but three would be ideal. The first strategy would be to pick the highest number that you can use. The second strategy would be to use the most amount of numbers that you can per turn. The third would be to try to use combinations of mid value numbers. This last one being the most difficult to program I would assume and I can live without getting it to work. I am sure this is a bit confusing so please post questions. I will summarize the main programing tricks that you will need to use below. If you think you are capable of writing a code like this I will give you a more detailed explanation of the strategies.

Simulate two dice being rolled
Pick which numbers to use depending on the strategy that is being simulated
not use the numbers picked for the rest of that given game
Count the number of wins ( used all numbers 1-9) and losses (you do not have numbers that sum up to the number rolled)


I can do this if the game is as described. In your post.
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 04:51pm
Yes this is a simulator of the game in the wikipedia link no curve balls
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 04:51pm
Created the first "strategy".

If the results of the 2 dice summed is less than or equal to 9 AND that result has not been taken before it will use that number. Else it will take the higher of the two numbers and strike that off.

Code
C:\Users\\Desktop>ruby hologod.rb
It took 28 turns
It took 53 turns
It took 31 turns
It took 33 turns
It took 27 turns
It took 25 turns
It took 11 turns
It took 17 turns
It took 26 turns
It took 64 turns
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 04:53pm
Quote (AbDuCt @ May 5 2015 05:51pm)
Created the first "strategy".

If the results of the 2 dice summed is less than or equal to 9 AND that result has not been taken before it will use that number. Else it will take the higher of the two numbers and strike that off.

Code
C:\Users\\Desktop>ruby hologod.rb
It took 28 turns
It took 53 turns
It took 31 turns
It took 33 turns
It took 27 turns
It took 25 turns
It took 11 turns
It took 17 turns
It took 26 turns
It took 64 turns


it needs to lose when you cannot sum up to the number rolled
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 05:02pm
Quote (HaloGod @ May 5 2015 06:53pm)
it needs to lose when you cannot sum up to the number rolled


Code
C:\Users\\Desktop>ruby hologod.rb
(Lost) It took 9 turns
(Lost) It took 6 turns
(Lost) It took 3 turns
(Lost) It took 9 turns
(Lost) It took 9 turns
(Lost) It took 8 turns
(Lost) It took 7 turns
It took 9 turns
(Lost) It took 8 turns
(Lost) It took 7 turns


The strategy is now

1) Attempt to use the highest number of the two dice summed
2) Attempt to use the highest number of the single dice
3) Attempt to use the number of the other dice

If none of those conditions are met the game is lost. And coincidentally, using this strategy the game only lasts a maximum of 9 turns.

This post was edited by AbDuCt on May 5 2015 05:03pm
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 05:04pm
can I see the code \ what is it in? This looks right the win % should be around 7-8 im comparing it to my calculations
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 05:06pm
Code
class Dice
attr_accessor :numberOfDice
def initialize(numberOfDice)
@numberOfDice = numberOfDice
end

def roll
results = []

@numberOfDice.times do
results.push(Random.rand(1..6))
end

results
end
end


10.times do
scoreBoard = {1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0}
turns = 0
dice = Dice.new(2)

loop do
if(scoreBoard.values.inject(:+) != 9) then
turns += 1
else
break
end

results = dice.roll

if(results.inject(:+) <= 9 && scoreBoard[results.inject(:+)] == 0) then
scoreBoard[results.inject(:+)] = 1
next
elsif(scoreBoard[results.sort.last] == 0) then
scoreBoard[results.sort.last] = 1
next
elsif(scoreBoard[results.sort.first] == 0) then
scoreBoard[results.sort.first] = 1
next
else
#p results
print "(Lost) "

break
end

end

puts "It took #{turns} turns"
#p scoreBoard
end


I can clean it up if you need to present it.

For the same of you being able to understand it, inject(:+) sums the values in an array, and sort sorts the array from lowest to highest.

This post was edited by AbDuCt on May 5 2015 05:07pm
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 05:08pm
no that works for me. What langauge is that in? Also if you can do the other strategy then i'll go ahead and pay you.

i can kind of understand it I took a little bit of matlab, but im not much of a programmer.

This post was edited by HaloGod on May 5 2015 05:09pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 05:10pm
Quote (HaloGod @ May 5 2015 07:08pm)
no that works for me. What langauge is that in? Also if you can do the other strategy then i'll go ahead and pay you


Ruby.

http://rubyinstaller.org/downloads/

I suggest Ruby 2.0.0-p645 as this is what the code was tested on in windows, although I don't have any reason to speculate it would not work using Ruby 2.2.2.

And yea I can take a look at the other strategies.

edit:: when installing, make sure you check the option "add ruby to PATH variable", or else you won't be able to run ruby from the command line unless you specify the full path to the ruby binary.

This post was edited by AbDuCt on May 5 2015 05:11pm
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll