First bundled release.
This commit is contained in:
34
tetris/randomizers/history_4rolls.lua
Normal file
34
tetris/randomizers/history_4rolls.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
local Randomizer = require 'tetris.randomizers.randomizer'
|
||||
|
||||
local History4RollsRandomizer = Randomizer:extend()
|
||||
|
||||
function History4RollsRandomizer:initialize()
|
||||
self.history = {"Z", "S", "Z", "S"}
|
||||
end
|
||||
|
||||
function History4RollsRandomizer:generatePiece()
|
||||
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
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user