2020-10-08 22:34:11 -05:00
|
|
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
|
|
|
|
|
|
|
local Bag7NoSZOStartRandomizer = Randomizer:extend()
|
|
|
|
|
|
|
|
function Bag7NoSZOStartRandomizer:shuffleBag()
|
2020-11-06 19:49:44 -06:00
|
|
|
local b = self.bag
|
|
|
|
local ln = #b
|
|
|
|
for i = 1, ln do
|
2021-12-08 20:23:00 -06:00
|
|
|
local j = love.math.random(i, ln)
|
2020-11-06 19:49:44 -06:00
|
|
|
b[i], b[j] = b[j], b[i]
|
|
|
|
end
|
2020-10-08 22:34:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local function isnotSZO(x) return not(x == "S" or x == "Z" or x == "O") end
|
|
|
|
|
|
|
|
function Bag7NoSZOStartRandomizer:initialize()
|
|
|
|
self.bag = {"I", "J", "L", "O", "S", "T", "Z"}
|
2020-11-06 19:49:44 -06:00
|
|
|
repeat
|
|
|
|
self:shuffleBag()
|
|
|
|
until isnotSZO(self.bag[7])
|
2020-10-08 22:34:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function Bag7NoSZOStartRandomizer:generatePiece()
|
|
|
|
if #self.bag == 0 then
|
|
|
|
self.bag = {"I", "J", "L", "O", "S", "T", "Z"}
|
2020-11-06 19:49:44 -06:00
|
|
|
self:shuffleBag()
|
2020-10-08 22:34:11 -05:00
|
|
|
end
|
|
|
|
return table.remove(self.bag)
|
|
|
|
end
|
|
|
|
|
|
|
|
return Bag7NoSZOStartRandomizer
|