Sorting code

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-05-15 18:18:55 +07:00
parent b789354299
commit 8c895221bd

View File

@@ -62,23 +62,23 @@ function GameMode:new(player_name, input_file, replay_grade)
self.total_lines = 0
self.lineClearPoints = {[0]=0, 0, 1667, 3750, 6668, 8335}
self.gradeNames = {
"19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k", "10k",
"19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k", "10k",
"9k", "8k", "7k", "6k", "5k", "4k", "3k", "2k", "1k",
"1D", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D"
}
self.promo_table = {
26666, 53333, 79999, 106666, 133333, 159999, 186666, 213333, 239999, 266666,
293333, 319999, 346666, 373333, 399999, 426666, 453333, 479999, 506666,
26666, 53333, 79999, 106666, 133333, 159999, 186666, 213333, 239999, 266666,
293333, 319999, 346666, 373333, 399999, 426666, 453333, 479999, 506666,
533333, 559999, 586666, 613333, 639999, 666666, 693333, 719999, 719999
}
self.autopromo_table = {
79999, 106666, 133333, 159999, 186666, 213333, 239999, 266666, 293333, 319999,
346666, 373333, 399999, 426666, 453333, 479999, 506666, 533333, 559999,
79999, 106666, 133333, 159999, 186666, 213333, 239999, 266666, 293333, 319999,
346666, 373333, 399999, 426666, 453333, 479999, 506666, 533333, 559999,
586666, 613333, 639999, 666666, 693333, 719999, 746666, 773333, 1000000
}
self.demo_table = {
-1, 13332, 25000, 40000, 50000, 60000, 60000, 120000, 120000, 120000,
180000, 180000, 240000, 240000, 300000, 300000, 360000, 360000, 360000,
-1, 13332, 25000, 40000, 50000, 60000, 60000, 120000, 120000, 120000,
180000, 180000, 240000, 240000, 300000, 300000, 360000, 360000, 360000,
420000, 420000, 480000, 480000, 480000, 480000, 540000, 540000, 540000
}
self.speed_divisor = 10000
@@ -135,7 +135,7 @@ function GameMode:new(player_name, input_file, replay_grade)
{20, 14, 20, 8},{20, 13, 20, 8},{20, 13, 20, 8},{20, 13, 19, 8},{20, 13, 19, 8},{20, 13, 19, 8},
{20, 12, 18, 8}
}
if not self.input_playback and not self.training and not PENTO_MODE then
if not self.input_playback and not self.training and not PENTO_MODE then
self:readGradeHistory()
end
end
@@ -143,14 +143,13 @@ end
function GameMode:readGradeHistory()
if love.filesystem.getInfo(SAVE_DIR..self.player_name.."_grade_history.sav") then
self.grade_history = bitser.loadLoveFile(SAVE_DIR..self.player_name.."_grade_history.sav")
else
else
self.grade_history = {1,2,0,0}
end
self.grade = self.grade_history[1]
self.starting_grade = self.grade
if self.grade > 1 then
temp_grade = copy(self.grade_history)
temp_grade[2] = 0
local temp_grade = copy(self.grade_history); temp_grade[2] = 0
bitser.dumpLoveFile(SAVE_DIR..self.player_name.."_grade_history.sav", temp_grade)
end
end
@@ -158,7 +157,7 @@ end
function GameMode:readHiScores()
if love.filesystem.getInfo(HIscoreFILE) then
self.hi_scores = bitser.loadLoveFile(HIscoreFILE)
else
else
self.hi_scores = {"TRO",0,"MIT",0,"ROM",0,"ITR",0,"OMI",0}
end
end
@@ -237,7 +236,7 @@ end
function GameMode:getLineARE() return self:getARE() end
function GameMode:getLockDelay()
function GameMode:getLockDelay()
if self.training then return 99999999999 end
if self.speed_level <= #self.delay_table then return self.delay_table[self.speed_level][3]
else return self.delay_table[#self.delay_table][3] end
@@ -279,7 +278,7 @@ function GameMode:initialize(ruleset)
end
function GameMode:saveInputs()
input_string = 'NEW'..string.format("%16d", self.randomizer.seed)..';'
local input_string = 'NEW'..string.format("%16d", self.randomizer.seed)..';'
for frame, input_set in pairs(self.recorded_inputs) do
input_string = input_string..string.format('%03d', tostring(input_set))
end
@@ -288,75 +287,46 @@ function GameMode:saveInputs()
inputfile:close()
end
function GameMode:storeInput(input_set)
input_right = 1
input_rotright2 = 2
input_up = 4
input_rotleft = 8
input_left = 16
input_down = 32
input_rotright = 64
input_rotleft2 = 128
if not input_set['right'] then input_right = 0 end
if not input_set['rotate_right2'] then input_rotright2 = 0 end
if not input_set['up'] then input_up = 0 end
if not input_set['rotate_left'] then input_rotleft = 0 end
if not input_set['left'] then input_left = 0 end
if not input_set['down'] then input_down = 0 end
if not input_set['rotate_right'] then input_rotright = 0 end
if not input_set['rotate_left2'] then input_rotleft2 = 0 end
self.recorded_inputs[self.frames] = bit.bor(input_right, input_rotright2, input_up, input_rotleft, input_left, input_down, input_rotright, input_rotleft2)
self.recorded_inputs[self.frames] = bit.bor(
input_set['right'] and 1 or 0,
input_set['rotate_right2'] and 2 or 0,
input_set['up'] and 4 or 0,
input_set['rotate_left'] and 8 or 0,
input_set['left'] and 16 or 0,
input_set['down'] and 32 or 0,
input_set['rotate_right'] and 64 or 0,
input_set['rotate_left2'] and 128 or 0
)
end
function GameMode:getInputPieceSeq(input_file)
local seed = ''
if string.sub(input_file, 1, 3) == 'NEW' then
string_start = 4
self.old_replay = false
else
string_start = 1
self.old_replay = true
end
for i = string_start, #input_file do
c = string.sub(input_file, i, i)
if c == ';' then break
else seed = seed..c
end
end
return seed
end
function GameMode:getReplayInputs(input_file)
input_right = 1
input_rotright2 = 2
input_up = 4
input_rotleft = 8
input_left = 16
input_down = 32
input_rotright = 64
input_rotleft2 = 128
replay_inputs = {}
reached_inputs = false
i = 1
while not reached_inputs do
c = string.sub(input_file,i,i)
local i = 1
local replay_inputs = {}
local reached_inputs = false
for _=1,1e99 do
local c = string.sub(input_file,_,_)
if c == ';' then
reached_inputs = true
i = _ + 1
end
i = i+1
if reached_inputs then break end
end
if reached_inputs then
while i <= #input_file - 3 do
input_list = {right = false, rotate_right2 = false, up = false, rotate_left = false, left = false, down = false, rotate_right = false, rotate_left2 = false}
coded_input = tonumber(string.sub(input_file, i, i+2))
if bit.band(coded_input, input_right) == 1 then input_list["right"] = true end
if bit.band(coded_input, input_rotright2) == 2 then input_list["rotate_right2"] = true end
if bit.band(coded_input, input_up) == 4 then input_list["up"] = true end
if bit.band(coded_input, input_rotleft) == 8 then input_list["rotate_left"] = true end
if bit.band(coded_input, input_left) == 16 then input_list["left"] = true end
if bit.band(coded_input, input_down) == 32 then input_list["down"] = true end
if bit.band(coded_input, input_rotright) == 64 then input_list["rotate_right"] = true end
if bit.band(coded_input, input_rotleft2) == 128 then input_list["rotate_left2"] = true end
local input_list = {right = false, rotate_right2 = false, up = false, rotate_left = false, left = false, down = false, rotate_right = false, rotate_left2 = false}
local coded_input = tonumber(string.sub(input_file, i, i+2))
if bit.band(coded_input, 1 ) == 1 then input_list["right"] = true end
if bit.band(coded_input, 2 ) == 2 then input_list["rotate_right2"] = true end
if bit.band(coded_input, 4 ) == 4 then input_list["up"] = true end
if bit.band(coded_input, 8 ) == 8 then input_list["rotate_left"] = true end
if bit.band(coded_input, 16 ) == 16 then input_list["left"] = true end
if bit.band(coded_input, 32 ) == 32 then input_list["down"] = true end
if bit.band(coded_input, 64 ) == 64 then input_list["rotate_right"] = true end
if bit.band(coded_input, 128) == 128 then input_list["rotate_left2"] = true end
table.insert(replay_inputs, input_list)
i = i + 3
end
@@ -364,6 +334,25 @@ function GameMode:getReplayInputs(input_file)
return replay_inputs
end
function GameMode:getInputPieceSeq(input_file)
local seed = ''
local string_start
if string.sub(input_file, 1, 3) == 'NEW' then
string_start = 4
self.old_replay = false
else
string_start = 1
self.old_replay = true
end
for i = string_start, #input_file do
local c = string.sub(input_file, i, i)
if c == ';' then break
else seed = seed..c
end
end
return seed
end
function GameMode:update(inputs, ruleset)
if self.input_playback and self.replay_inputs[self.frames] ~= nil then
inputs = self.replay_inputs[self.frames]
@@ -376,7 +365,7 @@ function GameMode:update(inputs, ruleset)
if self.game_over or self.completed then
self.game_over_frames = self.game_over_frames + 1
if self.game_over_frames == 1 then self:storeInput(inputs) end
if self.lcd > 0 then
if self.lcd > 0 then
self.lcd = self.lcd - 1
elseif self.game_over_frames == 30 then
local cleared_row_count = self.grid:getClearedRowCount()
@@ -388,7 +377,7 @@ function GameMode:update(inputs, ruleset)
end
return
end
if inputs["up"] and self.training and not self.up_lock then
if inputs["up"] and self.training and not self.up_lock then
table.remove(self.next_queue, 1)
table.insert(self.next_queue, self:getNextPiece(ruleset))
self.up_lock = true
@@ -396,7 +385,7 @@ function GameMode:update(inputs, ruleset)
if not inputs["up"] then self.up_lock = false end
local dir_list = {"down", "left", "right"}
for i = 1, #dir_list do
if inputs[dir_list[i]] and not table.contains(self.directions_pressed, dir_list[i]) then
if inputs[dir_list[i]] and not table.contains(self.directions_pressed, dir_list[i]) then
table.insert(self.directions_pressed, dir_list[i])
elseif not inputs[dir_list[i]] then
for j=1, #self.directions_pressed do
@@ -414,9 +403,9 @@ function GameMode:update(inputs, ruleset)
end
-- advance one frame
if self:advanceOneFrame(inputs, ruleset) == false then return end
self:chargeDAS(inputs, self:getDasLimit(), self:getARR())
-- set attempt flags
@@ -427,7 +416,7 @@ function GameMode:update(inputs, ruleset)
) then
self:onAttemptPieceRotate(self.piece, self.grid)
end
if self.piece == nil then
self:processDelays(inputs, ruleset)
else
@@ -448,7 +437,7 @@ function GameMode:update(inputs, ruleset)
local piece_dy = self.piece.position.y - piece_y
local piece_dx = self.piece.position.x - piece_x
local piece_drot = self.piece.rotation - piece_rot
-- das cut
if (
(piece_dy ~= 0 and (inputs.up or inputs.down)) or
@@ -513,7 +502,7 @@ function GameMode:update(inputs, ruleset)
else
self.are = self:getARE()
end
end
end
self.moved = false
@@ -524,7 +513,7 @@ end
function GameMode:detectHoles(x, y)
if y < 1 then return true end -- reached the top, no hole
local cell = self.grid:getCell(x, y)
if table.contains(self.visited, x..'.'..y) then
if table.contains(self.visited, x..'.'..y) then
return false
else
table.insert(self.visited, x..'.'..y)
@@ -556,7 +545,7 @@ end
function GameMode:doStackQuality()
local contiguous_holes = self:stackQualityCheck()
local total_speed = 0
if contiguous_holes > self.last_holes then
if contiguous_holes > self.last_holes then
self.speed_table[1] = 0
self.last_percent = 0
end
@@ -634,15 +623,15 @@ function GameMode:advanceOneFrame()
SOUNDS['bgm_secondhalf']:stop()
end
end
if self.clear then
self.completed = true
if self.clear then
self.completed = true
end
self.frames = self.frames + 1
if self.input_playback == true and self.old_replay == true and self.ready_frames ~= 0 then
self.frames = 0
end
if self.line_clear_flash > 0 then self.line_clear_flash = self.line_clear_flash - 1 end
if self.line_clear_flash == 0 then
if self.line_clear_flash == 0 then
self.lines_cleared = 0
self.score_to_add = 0
self.last_meter = 0
@@ -679,7 +668,7 @@ function GameMode:onPieceDrop(piece, grid, dy)
self.moved = true
end
end
function GameMode:onPieceLock(piece, cleared_row_count)
function GameMode:onPieceLock(piece, cleared_row_count)
if not self.moved then
self.move_count = self.move_count + 1
self.moved = true
@@ -726,7 +715,7 @@ function GameMode:drawEndScoringInfo()
drawBigText(string.format("%s", self.grade_score), 247, 150, 100, "center")
if not PENTO_MODE then
drawText("Best scores:", 247, 220, 1000, "left")
local i = 2
while i <= 10 do
if i == hiscore_pos[1] or i == hiscore_pos[2] then
@@ -1020,7 +1009,7 @@ function GameMode:drawScoringInfo()
drawBigText(string.format("%s", self.grade), 100, 143, 1000, "left")
self:drawInputDisplay(103,185)
elseif not PENTO_MODE then
if math.mod(self.grade_change_flash, 5) ~= 0 then
if math.mod(self.grade_change_flash, 5) ~= 0 then
drawBigText(string.format("%s", self.gradeNames[self.grade]), 100, 143, 1000, "left", self.grade_change_color)
else
drawBigText(string.format("%s", self.gradeNames[self.grade]), 100, 143, 1000, "left")
@@ -1068,7 +1057,7 @@ function GameMode:drawScoringInfo()
love.graphics.rectangle("fill", 385, 348, 190, 50, 10, 10)
drawText(string.format("Added: %d\nScore: %d",self.score_to_add, self.grade_score), 392, 356, 1000, "left")
end
if self.clear or self.game_over then
SOUNDS['bgm_firsthalf']:stop()