Jump to content

Remote agent/Simulation/Julia: Difference between revisions

m
no edit summary
(julia example)
 
mNo edit summary
Line 47:
colorant"blue", colorant"yellow", colorant"transparent"
const sectorcolors = [Red, Green, Blue, Yellow]
const colorsectors = Dict{ColorColorant,Char}(Red => SectorRed, Green => SectorGreen,
Blue => SectorBlue, Yellow => SectorYellow)
const colorballs = Dict{ColorColorant,Char}(Red => BallRed, Green => BallGreen,
Blue => BallBlue, Yellow => BallYellow)
 
const configs = Dict{String,Any}("dimensions" => (8, 12), "ballchance" => 0.7567,
"wallchance" => 0.10, "walltile" => '▒', "emptytile" => ' ',
"balltile" => '\u25cd', "agenttile" => '\u2603', "agentwithball" => '\u26f9',
"unknowntile" => '?', "ip" => ip"127.0.0.1","portnumber" => 5021,
"wallcolor" => colorant"darkgray", "unknowncolor" => colorant"gold")
Line 60 ⟶ 59:
mutable struct Sector
ch::Char
clr::ColorColorant
ball::ColorColorant
end
 
Line 73 ⟶ 72:
location::Pt
direction::Direction
ball:: ColorColorant
end
 
Line 248 ⟶ 247:
 
 
# modulino for testing
if occursin(Base.PROGRAM_FILE, @__FILE__)
 
Line 283 ⟶ 282:
newgame()
 
end # modulino for testing
</lang>
Second fileFile: gtk_remoteserversimulation.jl
<lang julia>using Distributed, Sockets, Gtk, Colors, Graphics, Cairo
 
Line 297 ⟶ 296:
# 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
# height and width randomly excahngedexchanged, so knowing facing north gives no net
# information about the shape and contents of the grid.
height, width = configs["dimensions"]
Line 336 ⟶ 335:
line_to(ctx, (i - 1) * l + fontsize * 1.25, (j - 1) * l + fontsize * 0.2)
stroke(ctx)
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)
fill(ctx)
Line 362 ⟶ 361:
end
if GameOver in response
for ch in [GameOver, GameOver, GameOver, GameOver, GameOver, Stop]
put!(outchan, ch)
end
sleep(10)
close(inchan)
close(outchan)
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.