cambridge/tetris/randomizers/history_4rolls.lua
Oshisaure 1366451a3d Fixed randomisers in A1-A4 modes:
- History 4-rolls, history 6-rolls and history 6-rolls 35-bag no longer deal S, Z or O as their first piece
- Added a 7-bag randomiser with the same behaviour (bag7noSZOstart)
- Tweaked the "35-bag" part of the history 6-rolls 35-bag randomiser to work closer to what it's supposed to be
- Switched Marathon AX4's randomiser from history 6-rolls to 7-bag no SZO start
2020-10-09 04:34:11 +01:00

41 lines
1000 B
Lua

local Randomizer = require 'tetris.randomizers.randomizer'
local History4RollsRandomizer = Randomizer:extend()
function History4RollsRandomizer:initialize()
self.history = {"Z", "Z", "Z", "Z"}
self.first = true
end
function History4RollsRandomizer:generatePiece()
if self.first then
self.first = false
return self:updateHistory(({"L", "J", "I", "T"})[math.random(4)])
else
local shapes = {"I", "J", "L", "O", "S", "T", "Z"}
for i = 1, 4 do
local x = math.random(7)
if not inHistory(shapes[x], self.history) or i == 4 then
return self:updateHistory(shapes[x])
end
end
end
end
function History4RollsRandomizer:updateHistory(shape)
table.remove(self.history, 1)
table.insert(self.history, shape)
return shape
end
function inHistory(piece, history)
for idx, entry in pairs(history) do
if entry == piece then
return true
end
end
return false
end
return History4RollsRandomizer