Files
tromi_mobile/game/randomizer.lua
Squishy (C6H12O6+NaCl+H2O) 3343d8711b V0 version
Add ``.gitignore``

Update ``.vscode\settings.json``

Main file changed a bit

Replace every single ``io.open`` into ``fs.read()``

Add ``input.waiting2trigger`` as buffer for too quick inputs

Replace ``binser`` with ``bitser``

Add the missing buffer logical code in training mode

Add a debug connector

Not a big update

Update VirtualControl.lua

Update in vctrl system

Trimming some unnecessary empty lines in classic library

Update virtual control stuff

Replace ``table.getn`` with ``#`` and ``scene`` with ``SCENE``

Renaming and moving some modules

Removing unnecessary ``local mino = {...}``

Add loading screen

Update loading screen

Apply replay patch

Not showing virtual control on computer

Adding touch screen configuration scene (placeholder)

Fix loading screen

update virtual control texture

Do some preparation for touch config screen

Quick patch

Compress background

Not important uodates

Small changes on how virtual key call action

Add ``SCENE:onInputMove``

Apply V2.2 patch

Clean up unnecessary imports

Test

.

Remove a redudant global variable

Small change

Split up alpha number

Sorting code

Update storeInput function

Optimize replay storing, saving and reading

Add VCTRL.export (for saving feature)

Remove unnecessary imports

Redesign loading screen

Replace loading screen

Make a simple BUTTON module

Update BUTTON module

Update button module

Add new callback

Add new callback

TEST

Update simple-button module

Update simple button module

Set default draw function for button

Add scene type notation

TEST

Not important updates

Design a error screen

Small update

Remove error key

Update

TEST

TEST

Test

TEST

TEST

Update button module

TEST

TEST

TEST

TEST

TEST

TEST

TEST

TEST

test

TEST

TEST

TEST

test

TEST

test

Fix a bug in VCTRL module that affect to SCENE:onInputRelease

Moving VCTRL related calls and adding buttons for name entry screen

Add type notation

Update modules

Final update for touch configuration scene

Fix 2 buttons can be highlighted at the same time in simple-button module

Narrow the safe border

Remove id = b (it was there for test)

Update of touch configuration scene

Add touch gesture for replay and input configuration scene

Add buttons for Replay, add MENU to go out after finishing game or in 20G Training mode

TEST

Fix some bugs (TEST)

Fix lỗi giữa đêm

Fix bug again

It should work imo

TEST

Fix SCENE:onInputMove{type="touch"} is not working

Fix bug once again (DONE!)

Temproraily allowing save

Fix settings module

Fix VCTRL.exportAll()

Fix VCTRL.exportAll returns userdata

Reverse a change

Fix forgetting to import virtual control settings

Fix grid drawing

Fix bugs related to the first time launching game

Add README file

Add README file

Update README and add LICENSE files

Update README

Add TV remote code

Disable debug code

Fix Android code

Small fix

Rename LICENSE to COPYING

Moving scene.lua to modules folder

Add new libraries

Make a new FILE API and add a simple error screen in case most thing went down

Change special code, add a way to skip keys

Update icon + README file

Rename screenshot file

Update README

Updating README file

Replace loading screen

Update README

Update virtual control texture

Fix virtual button method

Update README

Add icon font

Add importing and exporting replays

Update touch control

Update conf.lua

Replacing font, to avoid license issue

convert indents to spaces

Update font related stuff

Replace font

Updating README file

Update virtual control texture
2024-06-05 18:54:11 +07:00

149 lines
4.7 KiB
Lua

local Object = require 'libs.classic'
local Randomizer = Object:extend()
local highest_count = 0
function Randomizer:new(always, seed)
self.always = always
if seed ~= nil then
self.seed = seed
else
self.seed = love.math.random(1, 9007199254740991)
end
self.drought = {
I = 0,
J = 0,
L = 0,
T = 0,
S = 0,
Z = 0,
O = 0
}
self.droughted_deals = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
self.piece_counts = {
I = 0,
J = 0,
L = 0,
T = 0,
S = 0,
Z = 0,
O = 0
}
self.piece_round = 0
self:initialize()
end
function Randomizer:nextPiece()
return self:generatePiece()
end
function Randomizer:runTest()
local i_distance = 0
local highest_distance = 0
local distance_total = 0
local i_appearances = 0
local dupe = 0
local trip = 0
local quad = 0
local quin = 0
local lastpiece = 0
local lastpiece2 = 0
local lastpiece3 = 0
local lastpiece4 = 0
local pieceseq_rep = 0
local pieceseq = {}
local last_pieceseq = {}
local highest_discrepancy = 0
local discrepancy = self.piece_counts[table.highest(self.piece_counts)] - self.piece_counts[table.lowest(self.piece_counts)]
local total_chance = 0
for i=0, 750000 do
piece = self:generatePiece()
if #pieceseq < 7 then
table.insert(pieceseq, piece)
else
--print(table.concat(pieceseq))
if table.concat(pieceseq) == table.concat(last_pieceseq) then
pieceseq_rep = pieceseq_rep + 1
end
last_pieceseq = copy(pieceseq)
pieceseq = {}
end
if piece == lastpiece then dupe = dupe + 1 end
if piece == lastpiece and piece == lastpiece2 then trip = trip + 1 end
if piece == lastpiece and piece == lastpiece2 and piece == lastpiece3 then quad = quad + 1 end
if piece == lastpiece and piece == lastpiece2 and piece == lastpiece3 and piece == lastpiece4 then quin = quin + 1 end
if piece == 'I' then
distance_total = distance_total + i_distance
i_appearances = i_appearances + 1
i_distance = 0
else i_distance = i_distance + 1 end
if highest_distance < i_distance then highest_distance = i_distance end
lastpiece4 = lastpiece3
lastpiece3 = lastpiece2
lastpiece2 = lastpiece
lastpiece = piece
--if self.piece_round <= 750 then print(discrepancy) end
local new_discrepancy = self.piece_counts[table.highest(self.piece_counts)] - self.piece_counts[table.lowest(self.piece_counts)]
if new_discrepancy > discrepancy then highest_discrepancy = new_discrepancy end
discrepancy = new_discrepancy
local chance = 0
for piece,drought in pairs(self.drought) do
local piece_chance = 0.14/( ((self.drought[table.highest(self.drought)]+1)-drought) / (self.drought[table.highest(self.drought)]) )
chance = chance + piece_chance
end
chance = chance / 7
total_chance = total_chance + chance
end
--something = something / 750000
print(string.format('dupes: %d, trips: %s, quads: %s, quins: %s, highest i distance: %d, average i distance: %f, pieceseq reps: %d, highest discrepancy:%d, average chance:%f\ndrought lengths dealt: %s', dupe, trip, quad, quin, highest_distance, distance_total/i_appearances, pieceseq_rep, highest_discrepancy, total_chance/750000, table.concat(self.droughted_deals, '-')))
for piece,count in pairs(self.piece_counts) do
print(piece..' '..count)
end
end
function Randomizer:initialize()
local start_pieces = {"I", "J", "L", "T"}
local shapes = {"I", "J", "L", "T", "S", "Z", "O"}
love.math.setRandomSeed(self.seed)
self.drought[table.remove(shapes, love.math.random(1, 4))] = 10
for i=4,9 do
self.drought[table.remove(shapes, love.math.random(1, #shapes))] = i
end
--self:runTest()
end
function Randomizer:generatePiece(always)
if self.always then
return "I"
end
local shapes = {"I", "J", "L", "T", "S", "Z", "O"}
local new_piece = shapes[love.math.random(1,7)]
local chance = love.math.random(0,self.drought[table.highest(self.drought)])
while self.drought[new_piece] < chance do
new_piece = shapes[love.math.random(1,7)]
end
for piece,drought in pairs(self.drought) do
if drought >= 10 then
new_piece = piece
end
end
generated_piece = new_piece
for piece,drought in pairs(self.drought) do
if new_piece ~= piece then self.drought[piece] = self.drought[piece] + 1
else
if drought < #self.droughted_deals then self.droughted_deals[drought+1] = self.droughted_deals[drought+1] + 1 end
self.piece_counts[piece] = self.piece_counts[piece] + 1
self.drought[piece] = 0
end
end
self.piece_round = self.piece_round + 1
return generated_piece
end
return Randomizer