2019-05-22 22:57:34 -05:00
|
|
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
|
|
|
|
2020-10-08 22:34:11 -05:00
|
|
|
local History6Rolls35PoolRandomizer = Randomizer:extend()
|
2019-05-22 22:57:34 -05:00
|
|
|
|
2020-10-08 22:34:11 -05:00
|
|
|
function History6Rolls35PoolRandomizer:initialize()
|
2020-11-06 19:49:44 -06:00
|
|
|
self.first = true
|
2019-05-22 22:57:34 -05:00
|
|
|
self.history = {"Z", "S", "Z", "S"}
|
2020-10-08 22:34:11 -05:00
|
|
|
self.pool = {
|
|
|
|
"I", "I", "I", "I", "I",
|
2020-11-06 19:49:44 -06:00
|
|
|
"T", "T", "T", "T", "T",
|
|
|
|
"L", "L", "L", "L", "L",
|
|
|
|
"J", "J", "J", "J", "J",
|
|
|
|
"S", "S", "S", "S", "S",
|
|
|
|
"Z", "Z", "Z", "Z", "Z",
|
|
|
|
"O", "O", "O", "O", "O",
|
|
|
|
}
|
|
|
|
self.droughts = {
|
|
|
|
I = 0,
|
|
|
|
T = 0,
|
|
|
|
L = 0,
|
|
|
|
J = 0,
|
|
|
|
S = 0,
|
|
|
|
Z = 0,
|
|
|
|
O = 0,
|
2019-05-22 22:57:34 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-10-08 22:34:11 -05:00
|
|
|
function History6Rolls35PoolRandomizer:generatePiece()
|
2020-11-06 19:49:44 -06:00
|
|
|
local index, x
|
|
|
|
if self.first then
|
2021-03-02 19:31:56 -06:00
|
|
|
index = math.random(20)
|
|
|
|
x = self.pool[index]
|
2020-11-06 19:49:44 -06:00
|
|
|
self.first = false
|
|
|
|
else
|
|
|
|
for i = 1, 6 do
|
|
|
|
index = math.random(#self.pool)
|
|
|
|
x = self.pool[index]
|
|
|
|
if not inHistory(x, self.history) or i == 6 then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.pool[index] = self:updateHistory(x)
|
|
|
|
return x
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2020-10-08 22:34:11 -05:00
|
|
|
function History6Rolls35PoolRandomizer:updateHistory(shape)
|
|
|
|
table.remove(self.history, 1)
|
2019-05-22 22:57:34 -05:00
|
|
|
table.insert(self.history, shape)
|
2020-10-08 22:34:11 -05:00
|
|
|
|
2020-11-06 19:49:44 -06:00
|
|
|
local highdrought
|
|
|
|
local highdroughtcount = 0
|
|
|
|
for k, v in pairs(self.droughts) do
|
|
|
|
if k == shape then
|
|
|
|
self.droughts[k] = 0
|
|
|
|
else
|
|
|
|
self.droughts[k] = v + 1
|
|
|
|
if v >= highdroughtcount then
|
|
|
|
highdrought = k
|
|
|
|
highdroughtcount = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-10-08 22:34:11 -05:00
|
|
|
return highdrought
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function inHistory(piece, history)
|
|
|
|
for idx, entry in pairs(history) do
|
|
|
|
if entry == piece then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2020-10-08 22:34:11 -05:00
|
|
|
return History6Rolls35PoolRandomizer
|