2020-11-11 21:24:56 -06:00
|
|
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
|
|
|
|
|
|
|
local RecursiveRandomizer = Randomizer:extend()
|
|
|
|
|
|
|
|
function RecursiveRandomizer:initialize()
|
|
|
|
self.bag = {"I", "J", "L", "O", "S", "T", "Z"}
|
|
|
|
end
|
|
|
|
|
|
|
|
function RecursiveRandomizer:generatePiece()
|
|
|
|
--if next(self.bag) == nil then
|
|
|
|
-- self.bag = {"I", "J", "L", "O", "S", "T", "Z"}
|
|
|
|
--end
|
2023-06-14 00:06:16 -05:00
|
|
|
local x = love.math.random(table.getn(self.bag) + 1)
|
2020-11-11 21:24:56 -06:00
|
|
|
while x == table.getn(self.bag) + 1 do
|
|
|
|
--print("Refill piece pulled")
|
|
|
|
table.insert(self.bag, "I")
|
|
|
|
table.insert(self.bag, "J")
|
|
|
|
table.insert(self.bag, "L")
|
|
|
|
table.insert(self.bag, "O")
|
|
|
|
table.insert(self.bag, "S")
|
|
|
|
table.insert(self.bag, "T")
|
|
|
|
table.insert(self.bag, "Z")
|
2023-06-14 00:06:16 -05:00
|
|
|
x = love.math.random(table.getn(self.bag) + 1)
|
2020-11-11 21:24:56 -06:00
|
|
|
end
|
|
|
|
--print("Number of pieces in bag: "..table.getn(self.bag))
|
|
|
|
--print("Bag: "..table.concat(self.bag, ", "))
|
|
|
|
return table.remove(self.bag, x)
|
|
|
|
end
|
|
|
|
|
|
|
|
return RecursiveRandomizer
|