Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most of the dice_ examples do not work #63

Open
finchco opened this issue Apr 2, 2022 · 2 comments
Open

Most of the dice_ examples do not work #63

finchco opened this issue Apr 2, 2022 · 2 comments

Comments

@finchco
Copy link
Contributor

finchco commented Apr 2, 2022

It looks like they were written before? without? the rest of the structure of rotLove. Need to refactor them into a working state.

@timothymtorres
Copy link
Contributor

True. This is the working dice example:

ROT=require 'src.rot'
local f, d_with_rng, rng
function love.load()
f=ROT.Display:new(80,24)
rng=ROT.RNG:new()
d_with_rng=ROT.Dice:new('3d6', 1):setRNG(rng)
d_without_rng=ROT.Dice:new('3d6', 1)
end
function love.draw() f:draw() end
local t=1.00000001
function love.update(dt)
if t>1 then
f:clear()
f:writeCenter("ROLL instance with rng: "..d_with_rng:roll(), 1)
f:writeCenter("ROLL instance with rng: "..d_with_rng:roll(), 2)
f:writeCenter("ROLL instance with rng: "..d_with_rng:roll(), 3)
f:writeCenter("ROLL instance with rng: "..d_with_rng:roll(), 4)
f:writeCenter("ROLL instance without rng: "..d_without_rng:roll(), 6)
f:writeCenter("ROLL instance without rng: "..d_without_rng:roll(), 7)
f:writeCenter("ROLL instance without rng: "..d_without_rng:roll(), 8)
f:writeCenter("ROLL instance without rng: "..d_without_rng:roll(), 9)
f:writeCenter("ROLL ROT.Dice with rng: "..ROT.Dice.roll('3d6', 1, lcg), 11)
f:writeCenter("ROLL ROT.Dice with rng: "..ROT.Dice.roll('3d6', 1, lcg), 12)
f:writeCenter("ROLL ROT.Dice with rng: "..ROT.Dice.roll('3d6', 1, lcg), 13)
f:writeCenter("ROLL ROT.Dice with rng: "..ROT.Dice.roll('3d6', 1, lcg), 14)
f:writeCenter("ROLL ROT.Dice without rng: "..ROT.Dice.roll('3d6', 1), 16)
f:writeCenter("ROLL ROT.Dice without rng: "..ROT.Dice.roll('3d6', 1), 17)
f:writeCenter("ROLL ROT.Dice without rng: "..ROT.Dice.roll('3d6', 1), 18)
f:writeCenter("ROLL ROT.Dice without rng: "..ROT.Dice.roll('3d6', 1), 19)
f:writeCenter("Rolling 3d6's", 23)
t=0
end
t=t+dt
end

and this is one of the more advanced examples where I didn't properly convert everything to using rot

dice = require('dice')
math.randomseed(os.time())
-- some basic dice you see in boardgames
single_die = dice:new(6) -- is the same as dice:new('1d6')
die_result = single_die:roll()
monopoly_dice = dice:new('2d6')
monopoly_turn = monopoly_dice:roll()
D&D_dice = dice:new('1d20') -- we could also use dice:new(20)
roll_to_hit = D&D_dice:roll()
risk_attackers_dice = dice:new('(1d6)x3')
risk_defenders_dice = dice:new('(1d6)x2')
attack_1, attack_2, attack_3 = risk_attackers_dice:roll()
defend_1, defend_2 = risk_defenders_dice:roll()
--alternatively we could just put the risk roll results in a table
attackers_result = { risk_attackers_dice:roll() }
defenders_result = { risk_defenders_dice:roll() }
-- Another method to roll dice is instead of using the roguelike dice notation, we can just feed the roll function a direct number
die_result = dice.roll(6)
monopoly_turn = dice.roll(6) + dice.roll(6)
roll_to_hit = dice.roll(20)
attack_1, attack_2, attack_3 = dice.roll(6), dice.roll(6), dice.roll(6)
defend_1, defend_2 = dice.roll(6), dice.roll(6)
-- Or we can roll the dice just using the notation alone without having to use dice:new()
die_result = dice.roll('1d6')
monopoly_turn = dice.roll('2d6')
roll_to_hit = dice.roll('1d20')
attack_1, attack_2, attack_3 = dice.roll('(1d6)x3')
defend_1, defend_2 = dice.roll('(1d6)x2')
-- notice we omitted the colon from the dice roll function because a dice instance is not neccessary although
-- every roll will initialize the dice table, return the result, and then discard the dice table
-- which means if you will be using dice continously it will be more efficent to use dice:new()

@finchco
Copy link
Contributor Author

finchco commented Apr 3, 2022

Ok cool. I can take point on converting / fixing these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants