Fix the UI some more. Correct the outputs

This commit is contained in:
Empathic Qubit 2021-03-05 11:33:11 -05:00
parent 34b4528953
commit e410f14b5d
3 changed files with 53 additions and 56 deletions

View file

@ -59,7 +59,7 @@ _M.ButtonNames = {
"A", "A",
"X", "X",
"L", "L",
"R", "R"
} }
_M.BoxRadius = 6 _M.BoxRadius = 6

View file

@ -192,6 +192,7 @@ function _M.getExtendedSprites()
return extended return extended
end end
callcount = 0
function _M.getInputs() function _M.getInputs()
_M.getPositions() _M.getPositions()

View file

@ -7,27 +7,13 @@ mathFunctions = require "mathFunctions"
util = require "util" util = require "util"
guiWidth, guiHeight = gui.resolution() guiWidth, guiHeight = gui.resolution()
form = gui.renderctx.new(500, 500) form = nil
netPicture = gui.renderctx.new(470, 200) netPicture = nil
runInitialized = {} runInitialized = {}
frameAdvanced = {} frameAdvanced = {}
--int forms.pictureBox(int formhandle, [int? x = null], [int? y = null], [int? width = null], [int? height = null]) --int forms.pictureBox(int formhandle, [int? x = null], [int? y = null], [int? width = null], [int? height = null])
--[[ GenerationLabel = forms.label(form, "Generation: " .. pool.generation, 5, 5)
SpeciesLabel = forms.label(form, "Species: " .. pool.currentSpecies, 130, 5)
GenomeLabel = forms.label(form, "Genome: " .. pool.currentGenome, 230, 5)
MeasuredLabel = forms.label(form, "Measured: " .. "", 330, 5)
FitnessLabel = forms.label(form, "Fitness: " .. "", 5, 30)
MaxLabel = forms.label(form, "Max: " .. "", 130, 30)
BananasLabel = forms.label(form, "Bananas: " .. "", 5, 65)
CoinsLabel = forms.label(form, "Coins: " .. "", 130, 65, 90, 14)
LivesLabel = forms.label(form, "Lives: " .. "", 130, 80, 90, 14)
DmgLabel = forms.label(form, "Damage: " .. "", 230, 65, 110, 14)
PowerUpLabel = forms.label(form, "PowerUp: " .. "", 230, 80, 110, 14) ]]
--[[ startButton = forms.button(form, "Start", flipState, 155, 102) --[[ startButton = forms.button(form, "Start", flipState, 155, 102)
restartButton = forms.button(form, "Restart", initializePool, 155, 102) restartButton = forms.button(form, "Restart", initializePool, 155, 102)
@ -731,11 +717,11 @@ function evaluateCurrent()
controller[5] = false controller[5] = false
end end
for b=1,#config.ButtonNames,1 do for b=0,#config.ButtonNames - 1,1 do
if controller[b] then if controller[b] then
input.set(0, b - 1, 1) input.set(0, b, 1)
else else
input.set(0, b - 1, 0) input.set(0, b, 0)
end end
end end
end end
@ -746,6 +732,31 @@ function on_input()
end end
end end
formCtx = gui.renderctx.new(500, 500)
function displayForm()
formCtx:set()
gui.rectangle(0, 0, 500, 500, 1, 0x00ffffff, 0x00000000)
gui.circle(game.screenX-84, game.screenY-84, 192 / 2, 1, 0x50000000)
--gui.text(5, 30, "Fitness: " .. math.floor(rightmost - (pool.currentFrame) / 2 - (timeout + timeoutBonus)*2/3))
gui.text(5, 5, "Generation: " .. pool.generation)
gui.text(130, 5, "Species: " .. pool.currentSpecies)
gui.text(230, 5, "Genome: " .. pool.currentGenome)
gui.text(130, 30, "Max: " .. math.floor(pool.maxFitness))
--gui.text(330, 5, "Measured: " .. math.floor(measured/total*100) .. "%")
gui.text(5, 65, "Bananas: " .. (game.getBananas() - startBananas))
gui.text(130, 65, "Coins: " .. (game.getCoins() - startCoins))
gui.text(130, 80, "Lives: " .. Lives)
gui.text(230, 65, "Damage: " .. partyHitCounter)
gui.text(230, 80, "PowerUp: " .. powerUpCounter)
if netPicture ~= nil then
netPicture:draw(5, 200)
end
form = formCtx:render()
gui.renderctx.setnull()
end
function on_paint() function on_paint()
gui.left_gap(500) gui.left_gap(500)
gui.top_gap(0) gui.top_gap(0)
@ -753,9 +764,12 @@ function on_paint()
gui.right_gap(0) gui.right_gap(0)
if genomeDisplay ~= nil and movie.currentframe() % 10 == 0 then if genomeDisplay ~= nil and movie.currentframe() % 10 == 0 then
displayGenome(genomeDisplay) displayGenome(genomeDisplay)
displayForm()
end end
gui.renderctx.setnull() gui.renderctx.setnull()
form:render():draw(-500, 0) if form ~= nil then
form:draw(-500, 0)
end
end end
function advanceFrame(after) function advanceFrame(after)
@ -781,19 +795,6 @@ function mainLoop (species, genome)
end end
end end
gui.circle(game.screenX-84, game.screenY-84, 192 / 2, 1, 0x50000000)
--[[ forms.settext(FitnessLabel, "Fitness: " .. math.floor(rightmost - (pool.currentFrame) / 2 - (timeout + timeoutBonus)*2/3))
forms.settext(GenerationLabel, "Generation: " .. pool.generation)
forms.settext(SpeciesLabel, "Species: " .. pool.currentSpecies)
forms.settext(GenomeLabel, "Genome: " .. pool.currentGenome)
forms.settext(MaxLabel, "Max: " .. math.floor(pool.maxFitness))
forms.settext(MeasuredLabel, "Measured: " .. math.floor(measured/total*100) .. "%")
forms.settext(BananasLabel, "Bananas: " .. (game.getBananas() - startBananas))
forms.settext(CoinsLabel, "Coins: " .. (game.getCoins() - startCoins))
forms.settext(LivesLabel, "Lives: " .. Lives)
forms.settext(DmgLabel, "Damage: " .. partyHitCounter)
forms.settext(PowerUpLabel, "PowerUp: " .. powerUpCounter)
]]
pool.currentFrame = pool.currentFrame + 1 pool.currentFrame = pool.currentFrame + 1
end end
@ -806,11 +807,11 @@ function mainLoop (species, genome)
evaluateCurrent() evaluateCurrent()
end end
for b=1,#config.ButtonNames,1 do for b=0,#config.ButtonNames - 1,1 do
if controller[b] then if controller[b] then
input.set(0, b - 1, 1) input.set(0, b, 1)
else else
input.set(0, b - 1, 0) input.set(0, b, 0)
end end
end end
@ -955,10 +956,10 @@ function fitnessAlreadyMeasured()
return genome.fitness ~= 0 return genome.fitness ~= 0
end end
genomeCtx = gui.renderctx.new(470, 200)
function displayGenome(genome) function displayGenome(genome)
netPicture:clear() genomeCtx:set()
netPicture:set() gui.solidrectangle(0, 0, 470, 200, 0x00606060)
gui.solidrectangle(0, 0, 470, 200, 0x80808080)
local network = genome.network local network = genome.network
local cells = {} local cells = {}
local i = 1 local i = 1
@ -1048,18 +1049,18 @@ function displayGenome(genome)
config.BoxRadius*10+5, config.BoxRadius*10+5,
2, 2,
0xFF000000, 0xFF000000,
0x80808080 0x00808080
) )
for n,cell in pairs(cells) do for n,cell in pairs(cells) do
if n > Inputs or cell.value ~= 0 then if n > Inputs or cell.value ~= 0 then
local color = math.floor((cell.value+1)/2*256) local color = math.floor((cell.value+1)/2*256)
if color > 255 then color = 255 end if color > 255 then color = 255 end
if color < 0 then color = 0 end if color < 0 then color = 0 end
local opacity = 0xFF000000 local alpha = 0x50000000
if cell.value == 0 then if cell.value == 0 then
opacity = 0x50000000 alpha = 0xFF000000
end end
color = opacity + color*0x10000 + color*0x100 + color color = alpha + color*0x10000 + color*0x100 + color
gui.rectangle( gui.rectangle(
math.floor(cell.x-5), math.floor(cell.x-5),
math.floor(cell.y-5), math.floor(cell.y-5),
@ -1072,19 +1073,19 @@ function displayGenome(genome)
end end
end end
for _,gene in pairs(genome.genes) do for _,gene in pairs(genome.genes) do
if gene.enabled then if true then
local c1 = cells[gene.into] local c1 = cells[gene.into]
local c2 = cells[gene.out] local c2 = cells[gene.out]
local opacity = 0xA0000000 local alpha = 0x20000000
if c1.value == 0 then if c1.value == 0 then
opacity = 0x20000000 alpha = 0xA0000000
end end
local color = 0x80-math.floor(math.abs(mathFunctions.sigmoid(gene.weight))*0x80) local color = 0x80-math.floor(math.abs(mathFunctions.sigmoid(gene.weight))*0x80)
if gene.weight > 0 then if gene.weight > 0 then
color = opacity + 0x8000 + 0x10000*color color = alpha + 0x8000 + 0x10000*color
else else
color = opacity + 0x800000 + 0x100*color color = alpha + 0x800000 + 0x100*color
end end
gui.line( gui.line(
math.floor(c1.x+1), math.floor(c1.x+1),
@ -1102,7 +1103,7 @@ function displayGenome(genome)
2, 2,
7, 7,
0x00000000, 0x00000000,
0x80FF0000 0x00FF0000
) )
local pos = 100 local pos = 100
@ -1111,10 +1112,7 @@ function displayGenome(genome)
pos = pos + 14 pos = pos + 14
end end
netPicture = genomeCtx:render()
local bitmap = netPicture:render()
form:set()
bitmap:draw(5, 250)
gui.renderctx.setnull() gui.renderctx.setnull()
end end
@ -1236,8 +1234,6 @@ function playTop()
end end
function on_quit() function on_quit()
netPicture:clear()
form:clear()
end end
if pool == nil then if pool == nil then