cambridge/tetris/randomizers/bag.lua
Ishaan Bhardwaj 1fdd091456 Ruleset and randomizer refactoring (Read comments)
You can now specify an arbitrary number of pieces for a ruleset.
The randomizers will adjust accordingly.
Expect a pento ruleset in the modpack soon!
Also, gamemode skin selection has been refactored.
2021-01-06 22:53:44 -05:00

24 lines
516 B
Lua

local Randomizer = require 'tetris.randomizers.randomizer'
local BagRandomizer = Randomizer:extend()
function BagRandomizer:new(pieces)
self.bag = {}
self.pieces = pieces
for i = 1, self.pieces do
table.insert(self.bag, i)
end
end
function BagRandomizer:generatePiece()
if next(self.bag) == nil then
for i = 1, self.pieces do
table.insert(self.bag, i)
end
end
local x = math.random(table.getn(self.bag))
return table.remove(self.bag, x)
end
return BagRandomizer