Remote agent/Simulation/Julia: Difference between revisions

Content added Content deleted
(julia example)
 
mNo edit summary
Line 47: Line 47:
colorant"blue", colorant"yellow", colorant"transparent"
colorant"blue", colorant"yellow", colorant"transparent"
const sectorcolors = [Red, Green, Blue, Yellow]
const sectorcolors = [Red, Green, Blue, Yellow]
const colorsectors = Dict{Color,Char}(Red => SectorRed, Green => SectorGreen,
const colorsectors = Dict{Colorant,Char}(Red => SectorRed, Green => SectorGreen,
Blue => SectorBlue, Yellow => SectorYellow)
Blue => SectorBlue, Yellow => SectorYellow)
const colorballs = Dict{Color,Char}(Red => BallRed, Green => BallGreen,
const colorballs = Dict{Colorant,Char}(Red => BallRed, Green => BallGreen,
Blue => BallBlue, Yellow => BallYellow)
Blue => BallBlue, Yellow => BallYellow)


const configs = Dict{String,Any}("dimensions" => (8, 12), "ballchance" => 0.75,
const configs = Dict{String,Any}("dimensions" => (8, 12), "ballchance" => 0.67,
"wallchance" => 0.10, "walltile" => '▒', "emptytile" => ' ',
"wallchance" => 0.10, "walltile" => '▒', "emptytile" => ' ',
"balltile" => '\u25cd', "agenttile" => '\u2603', "agentwithball" => '\u26f9',
"unknowntile" => '?', "ip" => ip"127.0.0.1","portnumber" => 5021,
"unknowntile" => '?', "ip" => ip"127.0.0.1","portnumber" => 5021,
"wallcolor" => colorant"darkgray", "unknowncolor" => colorant"gold")
"wallcolor" => colorant"darkgray", "unknowncolor" => colorant"gold")
Line 60: Line 59:
mutable struct Sector
mutable struct Sector
ch::Char
ch::Char
clr::Color
clr::Colorant
ball::Color
ball::Colorant
end
end


Line 73: Line 72:
location::Pt
location::Pt
direction::Direction
direction::Direction
ball:: Color
ball::Colorant
end
end


Line 248: Line 247:




# modulino for testing
# modulino
if occursin(Base.PROGRAM_FILE, @__FILE__)
if occursin(Base.PROGRAM_FILE, @__FILE__)


Line 283: Line 282:
newgame()
newgame()


end # modulino for testing
end # modulino
</lang>
</lang>
Second file: gtk_remoteserversimulation.jl
File: gtk_remoteserversimulation.jl
<lang julia>using Distributed, Sockets, Gtk, Colors, Graphics, Cairo
<lang julia>using Distributed, Sockets, Gtk, Colors, Graphics, Cairo


Line 297: Line 296:
# want the map as learned by agent to be aligned with the map known to server.
# want the map as learned by agent to be aligned with the map known to server.
# To do so, we start agent facin north, but in a random location with the map
# To do so, we start agent facin north, but in a random location with the map
# height and width randomly excahnged, so knowing facing north gives no net
# height and width randomly exchanged, so knowing facing north gives no net
# information about the shape and contents of the grid.
# information about the shape and contents of the grid.
height, width = configs["dimensions"]
height, width = configs["dimensions"]
Line 336: Line 335:
line_to(ctx, (i - 1) * l + fontsize * 1.25, (j - 1) * l + fontsize * 0.2)
line_to(ctx, (i - 1) * l + fontsize * 1.25, (j - 1) * l + fontsize * 0.2)
stroke(ctx)
stroke(ctx)
set_source(ctx, grid.agent.ball)
set_source(ctx, grid.agent.ball == nocolor ? colorant"black" : grid.agent.ball)
circle(ctx, (i - 1) * l + fontsize * 1.25, (j - 1) * l + fontsize * 2, fontsize / 4)
circle(ctx, (i - 1) * l + fontsize * 1.25, (j - 1) * l + fontsize * 2, fontsize / 4)
fill(ctx)
fill(ctx)
Line 362: Line 361:
end
end
if GameOver in response
if GameOver in response
for ch in [GameOver, GameOver, GameOver, GameOver, GameOver, Stop]
put!(outchan, ch)
end
sleep(10)
close(inchan)
close(inchan)
close(outchan)
close(outchan)