text:
julia> [RpcApi.SimpleOrganism(0x0000000000070b69,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            Creature.eatUp(o,Int(var_450))
            for i::Int8 = 1:div(var_450,_LOOP_STEPS_DIVIDER)
            end
            Creature.eatRight(o,Int(var_450))
            Creature.stepDown(o)
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            Creature.stepDown(o)
            Creature.stepRight(o)
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            Creature.eatUp(o,Int(var_435))
            var_285 = var_285 - var_285
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            if var_285 >= var_285
            end
            Creature.eatDown(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_285 = var_285 / var_285
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            var_285 = Int(Creature.getEnergy(o,Int(var_284),Int(var_284)))
            var_284 = var_284 / var_284
            var_285 = var_285 - var_285
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            local var_453::Bool = false
            var_231 = if haskey(o.mem,var_231)
                    o.mem[var_231]
                else
                    var_231
                end
            return var_230
        end
        function func_189(var_188::Int16=2883)
            return var_188
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        var_156 = var_120 - var_120
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_117 = var_117 + var_117
        o.mem[var_120] = var_156
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_156 = func_286(var_156)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_124 = var_280 * var_124
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatUp(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
        end
        Creature.eatLeft(o,Int(var_413))
        var_243 = var_123 & var_123
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_413))
        var_449 = var_449 * var_449
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_156 = var_120 * var_156
        o.mem[var_120] = var_120
        o.mem[var_156] = var_120
        var_120 = var_120 / var_120
        o.mem[var_156] = var_156
        Creature.stepUp(o)
        var_124 = func_142(var_124)
        var_120 = var_120 / var_156
        var_120 = func_189(var_120)
        Creature.stepLeft(o)
        var_124 = var_280 - var_124
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],0,5538,1,419829,0x0000041a,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[433,19],92
),RpcApi.SimpleOrganism(0x00000000000707da,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            local var_467::Int64 = 7164237047677896710
            Creature.stepUp(o)
            for i::Int8 = 1:div(var_450,_LOOP_STEPS_DIVIDER)
            end
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            o.mem[var_419] = var_419
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_464::Int64 = -5943198665221537125
            local var_435::Int8 = 48
            if var_285 !== var_285
                Creature.stepUp(o)
            end
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatRight(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_285 = var_285 / var_285
            if var_435 <= var_435
                local var_463::Bool = false
            end
            Creature.eatUp(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            local var_466::Int16 = 2702
            local var_462::Int64 = 5443692598024048229
            local var_465::Int64 = -3582633826587851317
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_124 = var_280 * var_124
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_120 = func_286(var_120,var_280)
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        var_120 = var_120 - var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        var_120 = var_120 * var_120
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        o.mem[var_156] = var_120
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatUp(o,Int(var_117))
        o.mem[var_120] = var_120
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_413))
        Creature.eatRight(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_243 = var_123 & var_123
        var_120 = var_156 * var_120
        var_449 = var_449 * var_449
        Creature.eatRight(o,Int(var_413))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_117 = var_117 / var_413
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
        end
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_124 = func_142(var_124)
        Creature.eatRight(o,Int(var_413))
        Creature.stepLeft(o)
        var_124 = var_280 - var_124
        Creature.eatLeft(o,Int(var_413))
        Creature.stepRight(o)
        return true
    end),[110,300,95,0,1,1,1],6,6740,1,407508,0x0000044a,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1920,958],
95),RpcApi.SimpleOrganism(0x0000000000070b8b,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            local var_467::Int64 = 7164237047677896710
            Creature.stepUp(o)
            for i::Int8 = 1:div(var_450,_LOOP_STEPS_DIVIDER)
            end
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            o.mem[var_419] = var_419
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_464::Int64 = -5943198665221537125
            local var_435::Int8 = 48
            if var_285 !== var_285
                Creature.stepUp(o)
            end
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatRight(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_285 = var_285 / var_285
            if var_435 <= var_435
                local var_463::Bool = false
            end
            Creature.eatUp(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            local var_466::Int16 = 2702
            local var_462::Int64 = 5443692598024048229
            local var_465::Int64 = -3582633826587851317
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_124 = var_280 * var_124
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_120 = func_286(var_120,var_280)
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        var_120 = var_120 - var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        var_120 = var_120 * var_120
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        o.mem[var_156] = var_120
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatUp(o,Int(var_117))
        o.mem[var_120] = var_120
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_413))
        var_280 = var_124 * var_124
        Creature.eatUp(o,Int(var_117))
        var_243 = var_123 & var_123
        var_120 = var_156 * var_120
        var_449 = var_449 * var_449
        Creature.eatRight(o,Int(var_413))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_117 = var_117 / var_413
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
        end
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_124 = func_142(var_124)
        Creature.eatRight(o,Int(var_413))
        Creature.stepLeft(o)
        var_124 = var_280 - var_124
        Creature.eatLeft(o,Int(var_413))
        Creature.stepRight(o)
        return true
    end),[110,300,95,0,1,1,1],6,6740,1,345552,0x0000044b,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,10070=>10070,-4015=>0,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1919,959],95),
RpcApi.SimpleOrganism(0x00000000000701bd,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            var_450 = var_450 * var_450
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            var_419 = var_419 / var_419
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            if var_285 == var_285
                local var_460::Int16 = 11207
            end
            Creature.eatUp(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatUp(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            var_284 = var_284 / var_284
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatRight(o,Int(var_435))
            var_285 = var_285 / var_285
            Creature.eatLeft(o,Int(var_435))
            o.mem[var_284] = var_284
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            var_231 = var_231 * var_231
            return var_230
        end
        function func_189(var_188::Int16=2883)
            local var_465::Int8 = 86
            Creature.stepRight(o)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        if var_117 == var_117
        end
        var_156 = var_120 - var_120
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_124 = var_280 * var_124
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_117 = var_117 + var_117
        var_449 = var_449 * var_449
        if var_243 === var_243
        end
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_117))
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepRight(o)
        end
        var_117 = var_117 / var_413
        var_449 = var_449[1:if length(var_449) > length(var_449)
                        0
                    else
                        length(var_449) - length(var_449)
                    end]
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 / var_120
        o.mem[var_156] = var_156
        Creature.stepUp(o)
        o.mem[var_120] = var_120
        var_124 = func_142(var_124)
        var_120 = var_120 / var_156
        var_120 = func_189(var_120)
        Creature.stepLeft(o)
        var_124 = var_280 - var_124
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
            local var_459::Bool = false
        end
        return true
    end),[110,300,95,0,1,1,1],6,9549,1,316852,0x00000466,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,4=>4,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1919,
74],94),RpcApi.SimpleOrganism(0x0000000000070725,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            local var_466::Int64 = 8567201790879618132
            Creature.stepRight(o)
            Creature.eatUp(o,Int(var_450))
            if var_451 == var_451
            end
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            local var_465::Int64 = -2310500698855040954
            var_465 = Int(Creature.getEnergy(o,Int(var_419),Int(var_419)))
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            if var_285 !== var_285
                Creature.stepLeft(o)
            end
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_285 = var_285 / var_285
            Creature.eatRight(o,Int(var_435))
            if var_435 <= var_435
                local var_464::Int8 = 27
            end
            Creature.eatDown(o,Int(var_435))
            Creature.eatRight(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            local var_468::ASCIIString = "mjA5L2Oq"
            return var_230
        end
        function func_189(var_188::Int16=2883)
            Creature.eatLeft(o,Int(var_463))
            var_188 = if haskey(o.mem,var_188)
                    o.mem[var_188]
                else
                    var_188
                end
            o.mem[var_188] = var_188
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            local var_467::Int8 = -13
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        var_156 = var_120 - var_120
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_280 = var_124 - var_280
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        var_120 = var_120 - var_120
        Creature.eatDown(o,Int(var_117))
        Creature.stepLeft(o)
        var_124 = var_124 - var_124
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_156 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        o.mem[var_156] = var_120
        var_120 = var_120 + var_120
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatUp(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        if var_124 != var_124
        end
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_413))
        Creature.eatUp(o,Int(var_117))
        var_243 = var_123 & var_123
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_243 = Bool(abs(var_243 - var_123))
        Creature.eatUp(o,Int(var_117))
        var_117 = var_117 / var_413
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = func_189(var_120)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.eatUp(o,Int(var_117))
        var_124 = func_142(var_124)
        var_120 = var_120 / var_156
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.stepLeft(o)
        Creature.stepRight(o)
        var_124 = var_280 - var_124
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],6,5538,1,300115,0x00000461,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1,2],101),
RpcApi.SimpleOrganism(0x000000000006f6f1,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            local var_464::Int8 = 9
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            Creature.eatRight(o,Int(var_435))
            if var_285 == var_285
                local var_460::Int16 = 11207
            end
            Creature.eatUp(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatLeft(o,Int(var_435))
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            Creature.eatLeft(o,Int(var_435))
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            var_284 = var_284 / var_284
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            Creature.eatRight(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            o.mem[var_231] = var_231
            var_231 = if haskey(o.mem,var_231)
                    o.mem[var_231]
                else
                    var_231
                end
            return var_230
        end
        function func_189(var_188::Int16=2883)
            Creature.stepLeft(o)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        o.mem[var_120] = var_120
        var_156 = var_120 - var_120
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        var_120 = var_120 + var_120
        var_449 = var_449 * var_449
        var_124 = var_280 * var_124
        Creature.eatDown(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatLeft(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        var_243 = var_123 & var_123
        var_117 = var_117 + var_117
        Creature.eatRight(o,Int(var_413))
        var_243 = var_123 & var_123
        var_449 = var_449 * var_449
        if var_243 === var_243
            local var_463::Int16 = -3316
        end
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
            local var_462::Bool = false
            Creature.stepLeft(o)
            Creature.stepRight(o)
        end
        var_117 = var_117 / var_413
        o.mem[var_120] = var_120
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 / var_120
        o.mem[var_156] = var_156
        Creature.stepUp(o)
        o.mem[var_120] = var_120
        var_124 = var_280 - var_124
        var_120 = var_120 / var_156
        var_120 = func_189(var_120)
        Creature.stepLeft(o)
        var_124 = var_280 - var_124
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
            local var_459::Bool = false
        end
        return true
    end),[110,300,95,0,1,1,1],6,9549,1,257778,0x00000463,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,4=>4,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1919,
53],97),RpcApi.SimpleOrganism(0x0000000000070ae0,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            Creature.eatUp(o,Int(var_450))
            var_450 = var_450 * var_450
            Creature.eatUp(o,Int(var_450))
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            local var_462::Bool = true
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            var_462 = var_462 * var_462
            Creature.eatUp(o,Int(var_435))
            o.mem[var_284] = var_284
            var_285 = Int(Creature.getEnergy(o,Int(var_284),Int(var_284)))
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            o.mem[var_284] = var_284
            Creature.eatUp(o,Int(var_435))
            o.mem[var_284] = var_284
            var_285 = var_285 * var_285
            Creature.eatLeft(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            var_230 = var_230 | var_230
            if var_230 === var_230
            end
            return var_230
        end
        function func_142(var_141::Int64=7558744495470982559)
            local var_463::Int64 = -6668135868029214075
            var_141 = var_141 / var_141
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        o.mem[var_120] = var_120
        var_156 = var_120 - var_120
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        Creature.eatRight(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_156 = func_286(var_156)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_449 = var_449 * var_449
        var_124 = var_280 * var_124
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_413))
        var_413 = var_117 * var_413
        var_243 = var_123 & var_123
        var_449 = var_449 * var_449
        if var_243 === var_243
            Creature.stepRight(o)
        end
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        o.mem[var_120] = var_156
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_117 = var_117 / var_413
        o.mem[var_120] = var_120
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_449 = var_449 * var_449
        o.mem[var_156] = var_156
        Creature.stepUp(o)
        o.mem[var_120] = var_120
        var_124 = func_142(var_124)
        var_120 = var_120 / var_156
        var_120 = func_189(var_120)
        Creature.stepLeft(o)
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],6,5538,1,243466,0x0000044a,Dict(-8030=>-4015,9312=>9312,-26815=>-26815,-26920=>-26920,10070=>10070,2=>2,-4015=>-4015,23323=>23323,19308=>0,-1631=>-1631,1512=>1512,0=>0,9463=>9463,-29748=>9312,26760=>26760,11
906=>11906,1=>1),[1920,182],91),RpcApi.SimpleOrganism(0x0000000000070813,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            Creature.stepDown(o)
            for i::Int8 = 1:div(var_450,_LOOP_STEPS_DIVIDER)
            end
            var_450 = var_450 / var_450
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            Creature.stepLeft(o)
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            if var_285 == var_285
                local var_460::Int16 = 11207
            end
            Creature.eatUp(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            var_284 = if haskey(o.mem,var_284)
                    o.mem[var_284]
                else
                    var_284
                end
            Creature.eatLeft(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            var_284 = var_284 / var_284
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatRight(o,Int(var_435))
            var_285 = var_285 / var_285
            Creature.eatLeft(o,Int(var_435))
            o.mem[var_284] = var_284
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            local var_461::ASCIIString = "pJv1ArTS"
            return var_230
        end
        function func_189(var_188::Int16=2883)
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        if var_117 == var_117
        end
        var_156 = var_120 - var_120
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_124 = var_280 * var_124
        Creature.eatDown(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_117 = var_117 + var_117
        var_243 = var_123 & var_123
        var_449 = var_449 * var_449
        if var_243 === var_243
        end
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        o.mem[var_120] = var_120
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.stepRight(o)
        Creature.eatUp(o,Int(var_117))
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.stepRight(o)
        end
        var_117 = var_117 / var_413
        var_449 = var_449[1:if length(var_449) > length(var_449)
                        0
                    else
                        length(var_449) - length(var_449)
                    end]
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 / var_120
        o.mem[var_156] = var_156
        Creature.stepUp(o)
        o.mem[var_120] = var_120
        var_124 = func_142(var_124)
        var_120 = var_120 / var_156
        var_120 = func_189(var_120)
        Creature.stepLeft(o)
        var_124 = var_280 - var_124
        for i::Int8 = 1:div(var_413,_LOOP_STEPS_DIVIDER)
            local var_459::Bool = false
        end
        return true
    end),[110,300,95,0,1,1,1],6,9608,1,215377,0x00000460,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,4=>4,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1917,
71],94),RpcApi.SimpleOrganism(0x000000000006fec7,:(function (o::Creature.Organism,)
        function func_466(var_465::Int8=20)
            Creature.stepDown(o)
            for i::Int8 = 1:div(var_465,_LOOP_STEPS_DIVIDER)
            end
            for i::Int8 = 1:div(var_465,_LOOP_STEPS_DIVIDER)
            end
            return var_465
        end
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            Creature.eatLeft(o,Int(var_450))
            Creature.stepUp(o)
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            Creature.stepLeft(o)
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_464::Int64 = -5943198665221537125
            local var_435::Int8 = 48
            if var_285 !== var_285
                local var_468::Bool = true
                var_468 = var_468 | var_468
                Creature.stepLeft(o)
            end
            var_284 = var_284 * var_284
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatRight(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatUp(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_285 = var_285 / var_285
            Creature.eatLeft(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_284 = var_284 * var_284
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            local var_471::ASCIIString = "xgytj3Ye"
            Creature.stepLeft(o)
            var_188 = if haskey(o.mem,var_188)
                    o.mem[var_188]
                else
                    var_188
                end
            var_188 = if haskey(o.mem,var_188)
                    o.mem[var_188]
                else
                    var_188
                end
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        Creature.eatUp(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_117 = var_117 + var_117
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        var_120 = var_120 - var_120
        Creature.eatDown(o,Int(var_117))
        var_120 = var_120 + var_120
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        var_120 = var_120 * var_120
        var_243 = var_123 * var_243
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        o.mem[var_156] = var_120
        var_120 = var_120 + var_120
        Creature.eatDown(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatUp(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_413))
        Creature.eatRight(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        var_243 = var_123 & var_123
        var_449 = var_449 * var_449
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_243 = func_232(var_123)
        Creature.eatRight(o,Int(var_117))
        var_117 = var_117 / var_413
        Creature.eatLeft(o,Int(var_117))
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = var_120 / var_120
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepUp(o)
        var_124 = func_142(var_124)
        Creature.eatUp(o,Int(var_117))
        Creature.eatRight(o,Int(var_413))
        Creature.stepUp(o)
        var_124 = var_280 - var_124
        var_124 = var_124 / var_124
        Creature.stepLeft(o)
        return true
    end),[110,300,95,0,1,1,1],6,7974,61,214574,0x00000473,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,10070=>10070,-4015=>0,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[1871,959],106
),RpcApi.SimpleOrganism(0x000000000006fe77,:(function (o::Creature.Organism,)
        function func_452(var_450::Int8=-38,var_451::ASCIIString="vVKNMUw5")
            local var_466::Int64 = 8567201790879618132
            Creature.stepRight(o)
            var_450 = var_450 - var_450
            return var_450
        end
        function func_420(var_419::Int16=-11171)
            local var_465::Int64 = -2310500698855040954
            return var_419
        end
        local var_413::Int8 = -128
        function func_286(var_284::Int16=2081,var_285::Int64=9145930075523767031)
            local var_435::Int8 = 48
            Creature.eatRight(o,Int(var_435))
            if var_285 !== var_285
                Creature.stepLeft(o)
            end
            Creature.eatUp(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            Creature.eatDown(o,Int(var_435))
            o.mem[var_284] = var_284
            var_435 = var_435 + var_435
            Creature.eatDown(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            var_285 = var_285 / var_285
            Creature.eatRight(o,Int(var_435))
            if var_435 <= var_435
                local var_464::Int8 = 27
            end
            Creature.eatDown(o,Int(var_435))
            Creature.eatUp(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            Creature.eatLeft(o,Int(var_435))
            return var_284
        end
        local var_280::Int64 = -2141542542016055773
        local var_243::Bool = false
        function func_232(var_230::Bool=false,var_231::Int16=-29748)
            return var_230
        end
        function func_189(var_188::Int16=2883)
            Creature.stepRight(o)
            Creature.eatRight(o,Int(var_463))
            return var_188
        end
        function func_142(var_141::Int64=7558744495470982559)
            Creature.stepDown(o)
            return var_141
        end
        local var_123::Bool = true
        local var_120::Int16 = -4015
        local var_117::Int8 = 61
        local var_449::ASCIIString = "4WmdDLRo"
        var_156 = var_120 - var_120
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_243 = func_232(var_243,var_120)
        var_156 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_156
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        var_280 = var_124 - var_280
        var_117 = var_117 + var_117
        o.mem[var_120] = var_120
        o.mem[var_120] = var_120
        var_120 = var_120 - var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_156 = func_286(var_156)
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatRight(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = func_286(var_120)
        var_156 = func_286(var_120)
        var_120 = func_286(var_120,var_280)
        var_243 = var_123 | var_123
        o.mem[var_156] = var_120
        var_120 = var_120 + var_120
        o.mem[var_120] = var_120
        Creature.eatDown(o,Int(var_117))
        Creature.eatRight(o,Int(var_117))
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.eatUp(o,Int(var_117))
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_156)))
        var_413 = var_413 + var_413
        Creature.eatRight(o,Int(var_117))
        if var_124 != var_124
        end
        Creature.eatRight(o,Int(var_117))
        Creature.eatLeft(o,Int(var_413))
        Creature.eatUp(o,Int(var_117))
        var_243 = var_123 & var_123
        var_124 = Int(Creature.getEnergy(o,Int(var_120),Int(var_120)))
        Creature.eatRight(o,Int(var_117))
        var_124 = func_142(var_124)
        Creature.eatLeft(o,Int(var_117))
        Creature.eatUp(o,Int(var_117))
        Creature.eatDown(o,Int(var_117))
        var_243 = Bool(abs(var_243 - var_123))
        Creature.eatUp(o,Int(var_117))
        var_117 = var_117 / var_413
        var_120 = if haskey(o.mem,var_156)
                o.mem[var_156]
            else
                var_120
            end
        var_120 = if haskey(o.mem,var_120)
                o.mem[var_120]
            else
                var_120
            end
        var_120 = func_189(var_120)
        Creature.stepRight(o)
        Creature.stepUp(o)
        var_243 = var_243 | var_123
        var_124 = func_142(var_124)
        var_120 = var_120 / var_156
        var_124 = Int(Creature.getEnergy(o,Int(var_156),Int(var_120)))
        Creature.stepLeft(o)
        Creature.stepRight(o)
        var_124 = var_280 - var_124
        return true
    end),[110,300,95,0,1,1,1],6,5538,1,213685,0x00000460,Dict(9312=>9312,-26920=>-26920,2=>2,-1631=>-1631,0=>0,-29748=>9312,26760=>26760,-8030=>-8030,10070=>10070,-4015=>-4015,23323=>23323,19308=>0,1512=>1512,9463=>9463,1=>1),[197,960],97)]

max_stars_repo_name: tmptrash/jevo

max_issues_repo_name: tmptrash/jevo

max_forks_repo_name: tmptrash/jevo


text:
import Escher: @api, render

desc = md"""
# Hello, World!
You can write any **Markdown** text and place it in the middle of other
tiles.
""" |> Escher.pad(1em)

main(window) = begin
    push!(window.assets, "layout2")
    push!(window.assets, "icons")
    push!(window.assets, "widgets")

    t, p = wire(tabs([hbox(icon("home"), hskip(1em), "Home"),
                      hbox(icon("info-outline"), hskip(1em),  "Notifications"),
                      hbox(icon("settings"), hskip(1em), "Settings")]),
                pages([desc, "Notification tab content", "Settings tab content"]), :tabschannel, :selected)

    vbox(toolbar([iconbutton("face"), "My App", flex(), iconbutton("search")]),
         maxwidth(30em, t),
         Escher.pad(1em, p))
end

ext: jl


text:
# Unit tests for Distances

using Distance
using Base.Test

# helpers

# is_approx(a::Number, b::Number, tol::Number) = abs(a - b) < tol
# all_approx(a::ContiguousArray, b::ContiguousArray, tol::Number) = size(a) == size(b) && all(abs(a - b) .< tol)

# test individual metrics
a = 1
b = 2
@test sqeuclidean(a, a) == 0.
@test sqeuclidean(a, b) == 1.

@test euclidean(a, a) == 0.
@test euclidean(a, b) == 1.

@test cityblock(a, a) == 0.
@test cityblock(a, b) == 1.

@test chebyshev(a, a) == 0.
@test chebyshev(a, b) == 1.

@test minkowski(a, a, 2) == 0.
@test minkowski(a, b, 2) == 1.

@test hamming(a, a) == 0
@test hamming(a, b) == 1

x = [4., 5., 6., 7.]
y = [3., 9., 8., 1.]

a = [1., 2., 1., 3., 2., 1.]
b = [1., 3., 0., 2., 2., 0.]

p = rand(12)
p[p .< 0.3] = 0.
q = rand(12)

@test sqeuclidean(x, x) == 0.
@test sqeuclidean(x, y) == 57.

@test euclidean(x, x) == 0.
@test euclidean(x, y) == sqrt(57.)

@test cityblock(x, x) == 0.
@test cityblock(x, y) == 13.

@test chebyshev(x, x) == 0.
@test chebyshev(x, y) == 6.

@test minkowski(x, x, 2) == 0.
@test minkowski(x, y, 2) == sqrt(57.)

@test hamming(a, a) == 0
@test hamming(a, b) == 4

@test_approx_eq_eps cosine_dist(x, x) 0.0 1.0e-12
@test_approx_eq_eps cosine_dist(x, y) (1.0 - 112. / sqrt(19530.)) 1.0e-12

@test_approx_eq_eps corr_dist(x, x) 0. 1.0e-12
@test_approx_eq corr_dist(x, y) cosine_dist(x .- mean(x), y .- mean(y))

@test chisq_dist(x, x) == 0.
@test chisq_dist(x, y) == sum((x - y).^2 ./ (x + y))

klv = 0.
for i = 1 : length(p)
    if p[i] > 0
        klv += p[i] * log(p[i] / q[i])
    end
end
@test_approx_eq_eps kl_divergence(p, q) klv 1.0e-12

pm = (p + q) / 2
jsv = kl_divergence(p, pm) / 2 + kl_divergence(q, pm) / 2
@test_approx_eq_eps js_divergence(p, p) 0.0 1.0e-12
@test_approx_eq_eps js_divergence(p, q) jsv 1.0e-12

@test spannorm_dist(x, x) == 0.
@test spannorm_dist(x, y) == maximum(x - y) - minimum(x - y)

w = rand(size(x))

@test wsqeuclidean(x, x, w) == 0.
@test_approx_eq_eps wsqeuclidean(x, y, w) dot((x - y).^2, w) 1.0e-12

@test weuclidean(x, x, w) == 0.
@test weuclidean(x, y, w) == sqrt(wsqeuclidean(x, y, w))

@test wcityblock(x, x, w) == 0.
@test_approx_eq_eps wcityblock(x, y, w) dot(abs(x - y), w) 1.0e-12

@test wminkowski(x, x, w, 2) == 0.
@test_approx_eq_eps wminkowski(x, y, w, 2) weuclidean(x, y, w) 1.0e-12

w = rand(size(a))

@test whamming(a, a, w) == 0.
@test whamming(a, b, w) == sum((a .!= b) .* w)

Q = rand(length(x), length(x))
Q = Q * Q'  # make sure Q is positive-definite

@test sqmahalanobis(x, x, Q) == 0.
@test_approx_eq_eps sqmahalanobis(x, y, Q) dot(x - y, Q * (x - y)) 1.0e-12

@test mahalanobis(x, x, Q) == 0.
@test mahalanobis(x, y, Q) == sqrt(sqmahalanobis(x, y, Q))

# Bhattacharyya and Hellinger distances are defined for discrete
# probability distributions so to calculate the expected values
# we need to normalize vectors.
px = x ./ sum(x)
py = y ./ sum(y)
expected_bc_x_y = sum(sqrt(px .* py))
@test_approx_eq_eps Distance.bhattacharyya_coeff(x, y) expected_bc_x_y 1.0e-12
@test_approx_eq_eps bhattacharyya(x, y) (-log(expected_bc_x_y)) 1.0e-12
@test_approx_eq_eps hellinger(x, y) sqrt(1 - expected_bc_x_y) 1.0e-12

pa = a ./ sum(a)
pb = b ./ sum(b)
expected_bc_a_b = sum(sqrt(pa .* pb))
@test_approx_eq_eps Distance.bhattacharyya_coeff(a, b) expected_bc_a_b 1.0e-12
@test_approx_eq_eps bhattacharyya(a, b) (-log(expected_bc_a_b)) 1.0e-12
@test_approx_eq_eps hellinger(a, b) sqrt(1 - expected_bc_a_b) 1.0e-12

pp = p ./ sum(p)
pq = q ./ sum(q)
expected_bc_p_q = sum(sqrt(pp .* pq))
@test_approx_eq_eps Distance.bhattacharyya_coeff(p, q) expected_bc_p_q 1.0e-12
@test_approx_eq_eps bhattacharyya(p, q) (-log(expected_bc_p_q)) 1.0e-12
@test_approx_eq_eps hellinger(p, q) sqrt(1 - expected_bc_p_q) 1.0e-12

# Ensure it is semimetric
@test_approx_eq_eps bhattacharyya(x, y) bhattacharyya(y, x) 1.0e-12

# test column-wise metrics

m = 5
n = 8
X = rand(m, n)
Y = rand(m, n)
A = rand(1:3, m, n)
B = rand(1:3, m, n)

P = rand(m, n)
Q = rand(m, n)
P[P .< 0.3] = 0.

macro test_colwise(dist, x, y, tol)
    quote
        local n = size($x, 2)
        r1 = zeros(n)
        r2 = zeros(n)
        r3 = zeros(n)
        for j = 1 : n
            r1[j] = evaluate($dist, ($x)[:,j], ($y)[:,j])
            r2[j] = evaluate($dist, ($x)[:,1], ($y)[:,j])
            r3[j] = evaluate($dist, ($x)[:,j], ($y)[:,1])
        end
        @test_approx_eq_eps colwise($dist, $x, $y) r1 $tol
        @test_approx_eq_eps colwise($dist, ($x)[:,1], $y) r2 $tol
        @test_approx_eq_eps colwise($dist, $x, ($y)[:,1]) r3 $tol
    end
end

@test_colwise SqEuclidean() X Y 1.0e-12
@test_colwise Euclidean() X Y 1.0e-12
@test_colwise Cityblock() X Y 1.0e-12
@test_colwise Chebyshev() X Y 1.0e-16
@test_colwise Minkowski(2.5) X Y 1.0e-13
@test_colwise Hamming() A B 1.0e-16

@test_colwise CosineDist() X Y 1.0e-12
@test_colwise CorrDist() X Y 1.0e-12

@test_colwise ChiSqDist() X Y 1.0e-12
@test_colwise KLDivergence() P Q 1.0e-13
@test_colwise JSDivergence() P Q 1.0e-13
@test_colwise SpanNormDist() X Y 1.0e-12

@test_colwise BhattacharyyaDist() X Y 1.0e-12
@test_colwise HellingerDist() X Y 1.0e-12

w = rand(m)

@test_colwise WeightedSqEuclidean(w) X Y 1.0e-12
@test_colwise WeightedEuclidean(w) X Y 1.0e-12
@test_colwise WeightedCityblock(w) X Y 1.0e-12
@test_colwise WeightedMinkowski(w, 2.5) X Y 1.0e-12
@test_colwise WeightedHamming(w) A B 1.0e-12

Q = rand(m, m)
Q = Q * Q'  # make sure Q is positive-definite

@test_colwise SqMahalanobis(Q) X Y 1.0e-13
@test_colwise Mahalanobis(Q) X Y 1.0e-13

# test pairwise metrics

nx = 6
ny = 8

X = rand(m, nx)
Y = rand(m, ny)
A = rand(1:3, m, nx)
B = rand(1:3, m, ny)

P = rand(m, nx)
Q = rand(m, ny)

macro test_pairwise(dist, x, y, tol)
    quote
        local nx = size($x, 2)
        local ny = size($y, 2)
        rxy = zeros(nx, ny)
        rxx = zeros(nx, nx)
        for j = 1 : ny, i = 1 : nx
            rxy[i, j] = evaluate($dist, ($x)[:,i], ($y)[:,j])
        end
        for j = 1 : nx, i = 1 : nx
            rxx[i, j] = evaluate($dist, ($x)[:,i], ($x)[:,j])
        end
        @test_approx_eq_eps pairwise($dist, $x, $y) rxy $tol
        @test_approx_eq_eps pairwise($dist, $x) rxx $tol
    end
end

@test_pairwise SqEuclidean() X Y 1.0e-12
@test_pairwise Euclidean() X Y 1.0e-12
@test_pairwise Cityblock() X Y 1.0e-12
@test_pairwise Chebyshev() X Y 1.0e-16
@test_pairwise Minkowski(2.5) X Y 1.0e-12
@test_pairwise Hamming() A B 1.0e-16

@test_pairwise CosineDist() X Y 1.0e-12
@test_pairwise CorrDist() X Y 1.0e-12

@test_pairwise ChiSqDist() X Y 1.0e-12
@test_pairwise KLDivergence() P Q 1.0e-13
@test_pairwise JSDivergence() P Q 1.0e-13

@test_pairwise BhattacharyyaDist() X Y 1.0e-12
@test_pairwise HellingerDist() X Y 1.0e-12

w = rand(m)

@test_pairwise WeightedSqEuclidean(w) X Y 1.0e-12
@test_pairwise WeightedEuclidean(w) X Y 1.0e-12
@test_pairwise WeightedCityblock(w) X Y 1.0e-12
@test_pairwise WeightedMinkowski(w, 2.5) X Y 1.0e-12
@test_pairwise WeightedHamming(w) A B 1.0e-12

Q = rand(m, m)
Q = Q * Q'  # make sure Q is positive-definite

@test_pairwise SqMahalanobis(Q) X Y 1.0e-13
@test_pairwise Mahalanobis(Q) X Y 1.0e-13


text:
# This file is a part of TypeDBClient.  License is MIT: https://github.com/Humans-of-Julia/TypeDBClient.jl/blob/main/LICENSE

Optional{T} = Union{Nothing,T}

function _set_supertype_for_type(context, abstract_type::Type{<:g.AbstractThingType}, norm_type::String, super_type::String)
    attr = g.get(ConceptManager(context[:transaction]), abstract_type, norm_type)
    super_type = g.get(ConceptManager(context[:transaction]), abstract_type, super_type)
    g.set_supertype(g.as_remote(attr, context[:transaction]),
                    super_type)
end

function _is_supertype_for_type(context, abstract_type::Type{<:g.AbstractThingType}, attr_name::String, super_type_name::String)
    attr = g.get(ConceptManager(context[:transaction]), abstract_type, attr_name)
    super_type = g.get_supertype(g.as_remote(attr, context[:transaction]))

    return super_type.label.name == super_type_name
end

function _supertypes_contain(context, abstract_type::Type{<:g.AbstractThingType}, attr_name::String)
    super_types = [db[1] for db in context.datatable]
    attr = g.get(ConceptManager(context[:transaction]), abstract_type, attr_name)
    res_types = g.get_supertypes(g.as_remote(attr, context[:transaction]))
    res_array = Bool[]
    for attr in res_types
        push!(res_array, in(attr.label.name, super_types))
    end
    return res_array
end

function _supertypes_contain(context, ::Type{g.RoleType},
    relation_name::String,
    role_name::String;
    debug::Bool = false)

    db_roles = [_split_role(db[1])[1]=>_split_role(db[1])[2] for db in context.datatable]
    res = g.get(ConceptManager(context[:transaction]),
                RelationType,
                relation_name)
    role_play = g.relation_type_get_relates_for_role_label(g.as_remote(res, context[:transaction]), role_name)
    res_supertypes = g.get_supertypes(g.as_remote(role_play, context[:transaction]))

    isempty(res_supertypes) && println("Supertypes of $relation_name - $role_name aren't there")

    res_array = Bool[]

    debug && @info "Supertypes:"
    debug && println.(res_supertypes)

    debug && @info "Table should be there"
    for i in 1:length(db_roles)
        super_role = RoleType(g.Label(db_roles[i].first, db_roles[i].second), false)
        debug && println(super_role)
        push!(res_array, in(super_role, res_supertypes))
    end
    return res_array
end

function _subtypes_contain(context, abstract_type::Type{<:g.AbstractThingType}, attr_name::String)
    sub_types = [db[1] for db in context.datatable]
    attr = g.get(ConceptManager(context[:transaction]), abstract_type, attr_name)
    res_types = g.get_subtypes(g.as_remote(attr, context[:transaction]))

    isempty(res_types) && println("Subtypes of $attr_name isn't there")

    res_array = Bool[]
    for i in 1:length(sub_types)
        sub_type = g.get(context[:cm], abstract_type, sub_types[i])
        push!(res_array, in(sub_type, res_types))
    end
    return res_array
end

function _subtypes_contain(context, ::Type{g.RoleType}, relation_name::String, role_name::String)
    db_roles = [_split_role(db[1])[1]=>_split_role(db[1])[2] for db in context.datatable]
    res = g.get(ConceptManager(context[:transaction]),
                RelationType,
                relation_name)
    role_play = g.relation_type_get_relates_for_role_label(g.as_remote(res, context[:transaction]), role_name)
    res_subtypes = g.get_subtypes(g.as_remote(role_play, context[:transaction]))
    res_array = Bool[]
    for i in 1:length(db_roles)
        sub_role = RoleType(g.Label(db_roles[i].first, db_roles[i].second), false)
        push!(res_array, in(sub_role, res_subtypes))
    end
    return res_array
end

function _get_owns_contain(context, abstract_type::Type{<:g.AbstractThingType}, owner::String, is_key::Bool=false)
    key_types = [db[1] for db in context.datatable]
    attr = g.get(ConceptManager(context[:transaction]), abstract_type, owner)
    types_owns = g.get_owns(g.as_remote(attr, context[:transaction]),
                                nothing,
                                is_key)

    isempty(types_owns) && println("Owner $owner owns no attribute as it should be")

    res_array = Bool[]
    for i in 1:length(key_types)
        key_type = g.get(ConceptManager(context[:transaction]),
                            ThingType,
                            key_types[i])
        push!(res_array, in(key_type, types_owns))
    end

    return res_array
end

function _get_players_contain(relation_name::String, role_name::String, context; should_contain::Bool = true)
    db = [db[1] for db in context.datatable]
    res = g.get_players(context[:transaction], g.Label(relation_name,role_name))

    isempty(res) && should_contain && println("Relation $relation_name with Role $role_name haven't players")

    res_array = Bool[]
    for i in 1:length(db)
        entity = g.get(ConceptManager(context[:transaction]),
                        ThingType,
                        db[i])
        push!(res_array, in(entity, res))
    end
    return res_array
end

function _get_playing_roles_contain(player::String, player_type::Type{<:g.AbstractThingType}, context)
    db = [string(split(x[1],':')[1])=>string(split(x[1],':')[2]) for x in context.datatable]
    attr = g.get(ConceptManager(context[:transaction]),
                    player_type,
                    player)
    res_array = Bool[]
    play_roles = g.get_plays(g.as_remote(attr, context[:transaction]))

    isempty(play_roles) && println("played_roles of $player isn't there")

    for i in 1:length(db)
        role = RoleType(g.Label(db[i].first, db[i].second), false)
        push!(res_array, in(role, play_roles))
    end
    return res_array
end

function _get_related_roles_contain(context, relation_name::String)
    inp_roles = filter(x->x !== nothing,[_split_role(db[1]) for db in context.datatable])

    res = g.get(ConceptManager(context[:transaction]),
                RelationType,
                relation_name)

    relates = g.get_relates(g.as_remote(res, context[:transaction]))
    res_array = Bool[]
    for i in 1:length(inp_roles)
        inp_role = RoleType(g.Label(inp_roles[i].first, inp_roles[i].second),false)
        push!(res_array, in(inp_role, relates))
    end
    return res_array
end

function _thing_type_unset_type(context,
            type::Type{<:g.AbstractThingType},
            thing_name::String,
            unset_type::Type{<:g.AbstractType},
            unset_name::String)
    thing_type = g.get(context[:cm], type, thing_name)
    type_to_unset = g.get(context[:cm], unset_type, unset_name)
    g.unset_owns(g.as_remote(thing_type, context[:transaction]), type_to_unset)
end

function _split_role(role::String)
    res = split(role,":")
    return (string(res[1])=>string(res[2]))
end

# Scenario: Root thing type can retrieve all types
@then("thing type root get supertypes contain:") do context
    super_types = [db[1] for db in context.datatable]
    attr = g.get(ConceptManager(context[:transaction]), ThingType, "thing")
    res_types = g.get_supertypes(g.as_remote(attr, context[:transaction]))
    for attr in res_types
        @expect in(attr.label.name, super_types)
    end
end

@then("thing type root get supertypes do not contain:") do context
    super_types = [db[1] for db in context.datatable]
    attr = g.get(ConceptManager(context[:transaction]), ThingType, "thing")
    res_types = g.get_supertypes(g.as_remote(attr, context[:transaction]))
    for attr in res_types
        @expect !in(attr.label.name, super_types)
    end
end

@then("thing type root get subtypes contain:") do context
    res_contain = _subtypes_contain(context, ThingType, "thing")
    @expect all(res_contain)
end

@then("thing type root get subtypes do not contain:") do context
    res_contain = _subtypes_contain(context, ThingType, "thing")
    @expect all(res_contain) === false
end

# Scenario: Root thing type can retrieve all instances
@when("\$att1 = attribute(is-alive) as(boolean) put: true") do context
    attr = g.get(context[:cm], AttributeType, "is-alive")
    res = g.put(g.as_remote(attr, context[:transaction]), true)
    context[:att1] = res
end

@when("\$att2 = attribute(age) as(long) put: 21") do context
    attr = g.get(context[:cm], AttributeType, "age")
    res = g.put(g.as_remote(attr, context[:transaction]), 21)
    context[:att2] = res
end

@when("\$att3 = attribute(score) as(double) put: 123.456") do context
    attr = g.get(context[:cm], AttributeType, "score")
    res = g.put(g.as_remote(attr, context[:transaction]), 123.456)
    context[:att3] = res
end

@when("\$att4 = attribute(username) as(string) put: alice") do context
    attr = g.get(context[:cm], AttributeType, "username")
    res = g.put(g.as_remote(attr, context[:transaction]), "alice")
    context[:att4] = res
end

@when("\$att5 = attribute(license) as(string) put: abc") do context
    attr = g.get(context[:cm], AttributeType, "license")
    res = g.put(g.as_remote(attr, context[:transaction]), "abc")
    context[:att5] = res
end

@when("\$att6 = attribute(birth-date) as(datetime) put: 1990-01-01 11:22:33") do context
    attr = g.get(context[:cm], AttributeType, "birth-date")
    res = g.put(g.as_remote(attr, context[:transaction]), parse(DateTime, "1990-01-01T11:22:33"))
    context[:att6] = res
end

@when("\$ent1 = entity(person) create new instance with key(username): alice") do context
    ent_type = g.get(context[:cm], EntityType, "person")
    attr_type = g.get(context[:cm], AttributeType, "username")
    user_name = g.get(g.as_remote(attr_type, context[:transaction]), "alice")
    res = g.create(g.as_remote(ent_type, context[:transaction]))
    context[:ent1] = res
    set_has(context[:transaction], context[:ent1], user_name)
end

@when("\$rel1 = relation(marriage) create new instance with key(license): abc") do context
    ent_type = g.get(context[:cm], RelationType, "marriage")
    attr_type = g.get(context[:cm], AttributeType, "license")
    user_name = g.get(g.as_remote(attr_type, context[:transaction]), "abc")
    res = g.create(g.as_remote(ent_type, context[:transaction]))
    context[:rel1] = res
    set_has(context[:transaction], context[:rel1], user_name)
end

@then("root(thing) get instances count: 8") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))
    @expect length(res) == 8
end

@then("root(thing) get instances contain: \$att1") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:att1], res)
end

@then("root(thing) get instances contain: \$att2") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:att2], res)
end

@then("root(thing) get instances contain: \$att3") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:att3], res)
end

@then("root(thing) get instances contain: \$att4") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:att4], res)
end

@then("root(thing) get instances contain: \$att5") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:att5], res)
end

@then("root(thing) get instances contain: \$att6") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:att6], res)
end

@then("root(thing) get instances contain: \$ent1") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:ent1], res)
end

@then("root(thing) get instances contain: \$rel1") do context
    type = g.get(context[:cm], ThingType, "thing")
    res = g.get_instances(g.as_remote(type, context[:transaction]))

    @expect in(context[:rel1], res)
end


text:
# MIT License

# Copyright (c) Microsoft Corporation.

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE

"""
Module to enclose [Chebyshev polynomial](https://en.wikipedia.org/wiki/Chebyshev_polynomials) specific functionality.
"""
module Chebyshev
using OpticSim: NaNsafeacos

"""
    T(n::Int, q::R, fast::Bool = true) -> R

Evaluate Chebyshev polynomial of the first kind ``T_n(q)``.

`fast` will use trigonometric definition, rather than the recursive definition which is much faster but slightly less precise.
"""
@inline function T(n::Int, q::R, fast::Bool = true)::R where {R<:Real}
    @assert n >= 0
    if n === 0
        return one(R)
    elseif n === 1
        return q
    elseif fast && n > 3
        if abs(q) < one(R)
            return cos(n * NaNsafeacos(q))
        elseif q >= one(R)
            return cosh(n * acosh(q))
        else
            return (-1)^n * cosh(n * acosh(-q))
        end
    else
        return 2q * T(n - 1, q, fast) - T(n - 2, q, fast)
    end
end

"""
    U(n::Int, q::R, fast::Bool = true) -> R

Evaluate Chebyshev polynomial of the second kind ``U_n(q)``.

`fast` will use trigonometric definition, rather than the recursive definition which is much faster but slightly less precise.
"""
@inline function U(n::Int, q::R, fast::Bool = true)::R where {R<:Real}
    @assert n >= 0
    if n === 0
        return one(R)
    elseif n === 1
        return 2q
    elseif abs(q) < one(R) && fast && q > 3
        # much faster but not stable at |q| = 1
        aq = NaNsafeacos(q)
        return sin((n + 1) * aq) / sin(aq)
    else
        return 2q * U(n - 1, q, fast) - U(n - 2, q, fast)
    end
end

"""
    dTdq(n::Int, q::R, fast::Bool = true) -> R

Evaluate derivative of Chebyshev polynomial of the first kind ``\\frac{dT_n}{dq}(q)``.

`fast` will use trigonometric definition, rather than the recursive definition which is much faster but slightly less precise.
"""
@inline function dTdq(n::Int, q::R, fast::Bool = true)::R where {R<:Real}
    @assert n >= 0
    if n === 0
        return zero(R)
    elseif n === 1
        return one(R)
    elseif fast && n > 4
        if abs(q) == one(R)
            return q^(n + 1) * n^2
        elseif abs(q) < one(R)
            return n * sin(n * acos(q)) / sqrt(1 - q^2)
        elseif q > one(R)
            return n * sinh(n * acosh(q)) / sqrt(q^2 - 1)
        else
            return -n * (-1)^n * sinh(n * acosh(-q)) / sqrt(q^2 - 1)
        end
    else
        return n * U(n - 1, q, fast)
    end
end

# dUdq(n::Int, q::R)::R where {R<:Real} = ((n + 1) * T(n + 1, q) - q * U(n, q)) / (q^2 - one(T))
# d2Tq2(n::Int, q::R)::R where {R<:Real} = n * ((n + 1) * T(n, q) - U(n, q)) / (q^2 - 1)

end # module Chebyshev

"""
    ChebyshevSurface{T,N,P,Q} <: ParametricSurface{T,N}

Rectangular surface incorporating Chebyshev polynomials as well as radius and conic terms.
`T` is the datatype, `N` is the dimensionality, `P` is the number of Chebyshev terms in u and `Q` is the number of Chebyshev terms in v.

The surface is centered at the origin and treated as being the cap of an infinite rectangular prism, thus creating a true half-space.
**Note that the surface is vertically offset so that the center (i.e., `(u,v) == (0,0)`) lies at 0 on the z-axis.**

```julia
ChebyshevSurface(halfsizeu, halfsizev, chebycoeff; radius = Inf, conic = 0)
```

`chebycoeff` is a vector containing tuples of the form `(i, j, v)` where `v` is the value of the coefficient ``c_{ij}``.

The sag is defined by the equation

```math
z(u,v) = \\frac{c(u^2 + v^2)^2}{1 + \\sqrt{1 - (1+k)c^2(u^2 + v^2)}} + \\sum_{i}^{P}\\sum_{j}^{Q}c_{ij}T_i(u)T_j(v)
```

where ``c = \\frac{1}{\\texttt{radius}}``, ``k = \\texttt{conic}`` and ``T_n`` is the nᵗʰ Chebyshev polynomial of the first kind.
"""
struct ChebyshevSurface{T,N,P} <: ParametricSurface{T,N}
    halfsizeu::T
    halfsizev::T
    curvature::T
    conic::T
    boundingprism::BoundingBox{T}
    chebycoeff::SVector{P,Tuple{Int,Int,T}}
    offset::T

    function ChebyshevSurface(halfsizeu::T, halfsizev::T, chebycoeff::Union{Nothing,Vector{Tuple{Int,Int,T}}}; radius::T = typemax(T), conic::T = zero(T)) where {T<:Real}
        @assert !isnan(halfsizeu) && !isnan(halfsizev) && !isnan(radius) && !isnan(conic)
        @assert halfsizeu > zero(T) && halfsizev > zero(T)
        @assert one(T) - (1 / radius)^2 * (conic + one(T)) * (halfsizeu^2 + halfsizev^2) > 0 "Invalid surface (conic/radius combination: $radius, $conic)"
        offset = zero(T)
        if chebycoeff === nothing
            P = 0
        else
            for (i, j, c) in chebycoeff
                @assert i >= 0 && j >= 0 "i and j must be non-negative"
                if i % 2 == 0 && j % 2 == 0
                    offset += c * (-1)^(i ÷ 2) * (-1)^(j ÷ 2)
                end
            end
            chebycoeff = filter(k -> abs(k[3]) > zero(T), chebycoeff)
            P = length(chebycoeff)
        end
        bounding_prism = BoundingBox(-halfsizeu, halfsizeu, -halfsizev, halfsizev, typemin(T), typemax(T))
        return new{T,3,P}(halfsizeu, halfsizev, 1 / radius, conic, bounding_prism, SVector{P,Tuple{Int,Int,T}}(P === 0 ? [] : chebycoeff), offset)
    end
end
export ChebyshevSurface

uvrange(::Type{ChebyshevSurface{T,N,P}}) where {T<:Real,N,P} = ((-one(T), one(T)), (-one(T), one(T)))

boundingobj(z::ChebyshevSurface{T}) where {T<:Real} = z.boundingprism
halfsizeu(z::ChebyshevSurface{T}) where {T<:Real} = z.halfsizeu
halfsizev(z::ChebyshevSurface{T}) where {T<:Real} = z.halfsizev

function point(s::ChebyshevSurface{T,3,P}, u::T, v::T)::SVector{3,T} where {T<:Real,P}
    x = u * s.halfsizeu
    y = v * s.halfsizev
    r2 = (x^2 + y^2)
    q = (one(T) + s.conic) * s.curvature^2 * r2
    if q > one(T)
        return SVector{3,T}(NaN, NaN, NaN)
    end
    z = s.curvature * r2 / (one(T) + sqrt(one(T) - q))
    @inbounds @simd for ci in 1:P
        i, j, c = s.chebycoeff[ci]
        z += c * Chebyshev.T(i, u) * Chebyshev.T(j, v)
    end
    return SVector{3,T}(x, y, z - s.offset)
end

function partials(s::ChebyshevSurface{T,3,P}, u::T, v::T)::Tuple{SVector{3,T},SVector{3,T}} where {T<:Real,P}
    x = u * s.halfsizeu
    y = v * s.halfsizev
    r2 = x^2 + y^2
    t = one(T) - s.curvature^2 * (1 + s.conic) * r2
    if t < zero(T)
        return SVector{3,T}(NaN, NaN, NaN), SVector{3,T}(NaN, NaN, NaN)
    end
    q = s.curvature * sqrt(t) / t
    dhdu = x * q * s.halfsizeu
    dhdv = y * q * s.halfsizev
    @inbounds @simd for k in s.chebycoeff
        i, j, c = k
        dhdu += c * Chebyshev.dTdq(i, u) * Chebyshev.T(j, v)
        dhdv += c * Chebyshev.T(i, u) * Chebyshev.dTdq(j, v)
    end
    return SVector{3,T}(s.halfsizeu, 0.0, dhdu), SVector{3,T}(0.0, s.halfsizev, dhdv)
end

function normal(s::ChebyshevSurface{T,3,P}, u::T, v::T)::SVector{3,T} where {T<:Real,P}
    du, dv = partials(s, u, v)
    return normalize(cross(du, dv))
end

function uv(s::ChebyshevSurface{T,3,P}, p::SVector{3,T}) where {T<:Real,P}
    return SVector{2,T}(p[1] / s.halfsizeu, p[2] / s.halfsizev)
end

function onsurface(surf::ChebyshevSurface{T,3,P}, p::SVector{3,T}) where {T<:Real,P}
    u, v = uv(surf, p)
    if abs(u) > one(T) || abs(v) > one(T)
        return false
    else
        surfpoint = point(surf, u, v)
        return samepoint(p[3], surfpoint[3])
    end
end

function inside(surf::ChebyshevSurface{T,3,P}, p::SVector{3,T}) where {T<:Real,P}
    u, v = uv(surf, p)
    if abs(u) > one(T) || abs(v) > one(T)
        return false
    else
        surfpoint = point(surf, u, v)
        return p[3] < surfpoint[3]
    end
end

#########################################################################################################

# Assumes the ray has been transformed into the canonical coordinate frame which has the vertical axis passing through (0,0,0) and aligned with the z axis.
function surfaceintersection(surf::AcceleratedParametricSurface{T,3,ChebyshevSurface{T,3,P}}, r::AbstractRay{T,3}) where {T<:Real,P}
    bboxint = surfaceintersection(surf.surface.boundingprism, r)
    if bboxint isa EmptyInterval{T}
        return EmptyInterval(T)
    else
        if doesintersect(surf.triangles_bbox, r) || inside(surf.triangles_bbox, origin(r))
            surfint = triangulatedintersection(surf, r)
            if !(surfint isa EmptyInterval{T})
                return intervalintersection(bboxint, surfint)
            end
        end
        # hasn't hit the surface
        if lower(bboxint) isa RayOrigin{T} && upper(bboxint) isa Infinity{T}
            if inside(surf.surface, origin(r))
                return Interval(RayOrigin(T), Infinity(T))
            else
                return EmptyInterval(T)
            end
            # otherwise check that the intersection is underneath the surface
        else
            p = point(closestintersection(bboxint, false))
            ρ, ϕ = uv(surf, p)
            surfpoint = point(surf.surface, ρ, ϕ)
            if p[3] < surfpoint[3]
                return bboxint # TODO!! UV (and interface) issues?
            else
                return EmptyInterval(T)
            end
        end
    end
end

function BoundingBox(surf::ChebyshevSurface{T,3,P}) where {T<:Real,P}
    xmin = -surf.halfsizeu
    xmax = surf.halfsizeu
    ymin = -surf.halfsizev
    ymax = surf.halfsizev
    # polynomials range between -1 and 1 so we have to sum the absolute value of every coefficient to get the theoretical max
    zmax = P > 0 ? sum(abs(c) for (_, _, c) in surf.chebycoeff) : zero(T)
    zmin = -zmax
    q = one(T) - (one(T) + surf.conic) * surf.curvature^2 * (surf.halfsizeu^2 + surf.halfsizev^2)
    if q < zero(T)
        throw(ErrorException("The surface is invalid, no bounding box can be constructed"))
    end
    hmax = surf.curvature * (surf.halfsizeu^2 + surf.halfsizev^2) / (one(T) + sqrt(q))
    if hmax > zero(T)
        zmax += hmax
    else
        zmin += hmax
    end
    return BoundingBox(xmin, xmax, ymin, ymax, zmin, zmax)
end


text:
PARAM_LOCATION = ""
import UUIDs
const PKG_UUID = parse(UUIDs.UUID,"7c7805af-46cc-48c9-995b-ed0ed2dc909a")

#not constant,as is modified at runtime
#performance is not priority

function random_csv_name(table_type)
    #return repr(table_type) * repr(rand(UInt))
    return "$(Symbol(table_type))_$(repr(rand(UInt))).csv"
end
"""
    ParamTable(type::Symbol,table,location = nothing,name = nothing, options = ParamOptions())

Creates a clapeyron CSV file and returns the location of that file. the type determines the table type:
- `:single` creates a table with single parameters
- `:pair` creates a table with pair parameters
- `:assoc` creates a table with association parameters
- `:group` creates a table with association parameters

By default, the name is generated randomly, and the table is stored as a temporary scratch space (provided by Scratch.jl).
You can clean said scratch space by using `Clapeyron.cleartemp!()`.

## Examples:
```julia-repl
julia> data = (species = ["water"],Mw = [18.03]) #it could be a Dict, a named tuple, or any Tables.jl compatible table
(species = ["water"], Mw = [18.9])

julia> file = ParamTable(:single,data ,name="water_new_mw")
"C:\\Users\\user\\.julia\\scratchspaces\\7c7805af-46cc-48c9-995b-ed0ed2dc909a\\ParamTables\\singledata_water_new_mw.csv"

julia> model = PCSAFT(["water","methanol"],userlocations = [file])
PCSAFT{BasicIdeal} with 2 components:
 "water"
 "methanol"
Contains parameters: Mw, segment, sigma,
epsilon, epsilon_assoc, bondvol

julia> model.params.Mw
SingleParam{Float64}("Mw") with 2 components:
 "water" => 18.9
 "methanol" => 32.042
```
"""
function ParamTable(type::Symbol,data;location::Union{String,Nothing} = nothing,name::Union{String,Nothing} = nothing,options::ParamOptions = DefaultOptions)
    if location === nothing
        location = generate_location!()
    end
    table_type = _readcsvtype(String(type))
    if name === nothing
        name = repr(rand(UInt))
    end
    csvname =  "$(Symbol(table_type))_$(name).csv"
    headers = String.(Tables.columnnames(data))
    normalised_headers = normalisestring.(headers)
    _,_,_ = col_indices(table_type,normalised_headers,options) #basically to check the schema
    file = joinpath(location,csvname)
    io = open(file,"w")
    pretext =
    """Clapeyron Database File
    $(name) $type Parameters
    """
    write(io,pretext)
    CSV.write(io, data,append = true,header = true)
    close(io)
    return file
end

function generate_location!()
    if PARAM_LOCATION === ""
        global PARAM_LOCATION = @get_scratch!("ParamTables")
    end
    return PARAM_LOCATION
end
"""
    cleartemp!()

Deletes all files in the temporary Clapeyron scratch space, used to store the csvs created by `ParamTable`.
"""
function cleartemp!()
    Scratch.delete_scratch!(PKG_UUID,"ParamTables")
end
export ParamTable