Replaced spaces with tabs.
Check CONTRIBUTING.md, guys!
This commit is contained in:
@@ -3,27 +3,27 @@ local Randomizer = require 'tetris.randomizers.randomizer'
|
||||
local Bag7NoSZOStartRandomizer = Randomizer:extend()
|
||||
|
||||
function Bag7NoSZOStartRandomizer:shuffleBag()
|
||||
local b = self.bag
|
||||
local ln = #b
|
||||
for i = 1, ln do
|
||||
local j = math.random(i, ln)
|
||||
b[i], b[j] = b[j], b[i]
|
||||
end
|
||||
local b = self.bag
|
||||
local ln = #b
|
||||
for i = 1, ln do
|
||||
local j = math.random(i, ln)
|
||||
b[i], b[j] = b[j], b[i]
|
||||
end
|
||||
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"}
|
||||
repeat
|
||||
self:shuffleBag()
|
||||
until isnotSZO(self.bag[7])
|
||||
repeat
|
||||
self:shuffleBag()
|
||||
until isnotSZO(self.bag[7])
|
||||
end
|
||||
|
||||
function Bag7NoSZOStartRandomizer:generatePiece()
|
||||
if #self.bag == 0 then
|
||||
self.bag = {"I", "J", "L", "O", "S", "T", "Z"}
|
||||
self:shuffleBag()
|
||||
self:shuffleBag()
|
||||
end
|
||||
return table.remove(self.bag)
|
||||
end
|
||||
|
||||
@@ -10,8 +10,8 @@ end
|
||||
|
||||
function Bag7Randomizer:generatePiece()
|
||||
if next(self.extra) == nil then
|
||||
self.extra = {"I", "J", "L", "O", "S", "T", "Z"}
|
||||
end
|
||||
self.extra = {"I", "J", "L", "O", "S", "T", "Z"}
|
||||
end
|
||||
if next(self.bag) == nil then
|
||||
self.bag = {"I", "J", "L", "O", "S", "T", "Z"}
|
||||
table.insert(self.bag, table.remove(self.extra, math.random(table.getn(self.extra))))
|
||||
|
||||
@@ -4,22 +4,22 @@ local History4RollsRandomizer = Randomizer:extend()
|
||||
|
||||
function History4RollsRandomizer:initialize()
|
||||
self.history = {"Z", "Z", "Z", "Z"}
|
||||
self.first = true
|
||||
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
|
||||
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)
|
||||
|
||||
@@ -4,22 +4,22 @@ local History6RollsRandomizer = Randomizer:extend()
|
||||
|
||||
function History6RollsRandomizer:initialize()
|
||||
self.history = {"Z", "S", "Z", "S"}
|
||||
self.first = true
|
||||
self.first = true
|
||||
end
|
||||
|
||||
function History6RollsRandomizer: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, 6 do
|
||||
local x = math.random(7)
|
||||
if not inHistory(shapes[x], self.history) or i == 6 then
|
||||
return self:updateHistory(shapes[x])
|
||||
end
|
||||
end
|
||||
end
|
||||
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, 6 do
|
||||
local x = math.random(7)
|
||||
if not inHistory(shapes[x], self.history) or i == 6 then
|
||||
return self:updateHistory(shapes[x])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function History6RollsRandomizer:updateHistory(shape)
|
||||
|
||||
@@ -3,67 +3,67 @@ local Randomizer = require 'tetris.randomizers.randomizer'
|
||||
local History6Rolls35PoolRandomizer = Randomizer:extend()
|
||||
|
||||
function History6Rolls35PoolRandomizer:initialize()
|
||||
self.first = true
|
||||
self.first = true
|
||||
self.history = {"Z", "S", "Z", "S"}
|
||||
self.pool = {
|
||||
"I", "I", "I", "I", "I",
|
||||
"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",
|
||||
"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,
|
||||
}
|
||||
self.droughts = {
|
||||
I = 0,
|
||||
T = 0,
|
||||
L = 0,
|
||||
J = 0,
|
||||
S = 0,
|
||||
Z = 0,
|
||||
O = 0,
|
||||
}
|
||||
end
|
||||
|
||||
function History6Rolls35PoolRandomizer:generatePiece()
|
||||
local index, x
|
||||
if self.first then
|
||||
local prevent = {"S", "Z", "O"}
|
||||
repeat
|
||||
index = math.random(#self.pool)
|
||||
x = self.pool[index]
|
||||
until not inHistory(x, prevent)
|
||||
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
|
||||
local index, x
|
||||
if self.first then
|
||||
local prevent = {"S", "Z", "O"}
|
||||
repeat
|
||||
index = math.random(#self.pool)
|
||||
x = self.pool[index]
|
||||
until not inHistory(x, prevent)
|
||||
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
|
||||
end
|
||||
|
||||
function History6Rolls35PoolRandomizer:updateHistory(shape)
|
||||
table.remove(self.history, 1)
|
||||
table.insert(self.history, shape)
|
||||
|
||||
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
|
||||
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
|
||||
return highdrought
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user