d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Paying Fg For A Script
Prev12
Add Reply New Topic New Poll
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 05:22pm
so if i type this into the cmd box run it?
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 05:29pm
Quote (HaloGod @ May 5 2015 07:22pm)
so if i type this into the cmd box run it?


Save the code into a file with the extension ".rb", then via the command line (start -> type in "cmd") navigate to where you saved the file via "cd". Example if you saved it to your desktop type in "cd Desktop".

From there you can type in "ruby myfilename.rb" and it will run.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 05:34pm
Code
C:\Users\\Desktop>ruby hologod.rb
(Lost) It took 4 turns
(Lost) It took 4 turns
(Lost) It took 4 turns
It took 7 turns
(Lost) It took 4 turns
(Lost) It took 3 turns
(Lost) It took 4 turns
It took 6 turns
(Lost) It took 3 turns
(Lost) It took 4 turns


Strategy is

1) Check to see if the sum of 2 dice is taken, if not use it
2) Check to see if higher dice is used, if not use it
3) Check to see if lower dice is used, if not use it

This gives you a chance of using 1-3 numbers per turn. If you cannot use any numbers in that turn, you have lost.

This post was edited by AbDuCt on May 5 2015 05:38pm
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 05:40pm
ok ty i'll try this when i get home
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 5 2015 05:42pm
Quote (HaloGod @ May 5 2015 07:40pm)
ok ty i'll try this when i get home



Strategy2:

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
lost = true
dice = Dice.new(2)

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

results = dice.roll
#p results
if(results.inject(:+) <= 9 && scoreBoard[results.inject(:+)] == 0) then
scoreBoard[results.inject(:+)] = 1
lost = false
end

if(scoreBoard[results.sort.last] == 0) then
scoreBoard[results.sort.last] = 1
lost = false
end

if(scoreBoard[results.sort.first] == 0) then
scoreBoard[results.sort.first] = 1
lost = false
end

if(lost == true)
#p results
print "(Lost) "
break
end

lost = true
end

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


If you need a larger sample space change the line "10.times do" to a larger number. This is how many times the game is played. If you need counting of wins/losses per game as program output I can also do that.

Quote
The third would be to try to use combinations of mid value numbers.


If you could explain this a bit more I might be able to do your third strategy.

With my calculations and changing the games played to 100, the first strat wins 3% of the time (didn't average), and strat 2 wins 5% of the time. This is sampling each strat 100 times once, you would probably get more accurate results sampling each strat 100 times multiple times and averaging the results.

This post was edited by AbDuCt on May 5 2015 05:46pm
Member
Posts: 27,290
Joined: Apr 7 2007
Gold: 22,908.00
May 5 2015 05:45pm
if you can use a 7 8 or 9 only then you would use that( 7 8 or 9 is rolled and is available to be used), otherwise you would use the strategy from 2 (that is you will use the most amount you possibly can)

This post was edited by HaloGod on May 5 2015 05:46pm
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll