Remote agent/Simulation/Julia: Difference between revisions

m
link
mNo edit summary
m (link)
 
(2 intermediate revisions by 2 users not shown)
Line 1:
See [[Remote_agent/Simulation]]
 
This implementation uses the Gtk GUI library. There are two files: a module and a file to implement the GUI server's Gtk game view.
<br />
File: RemoteGameServerClient.jl
<langsyntaxhighlight lang="julia">module RemoteGameServerClient
 
using Sockets, Distributed, Colors
Line 96 ⟶ 98:
m = Matrix{Sector}(undef, height, width)
probinteriorwall = configs["wallchance"]
while true
for i in 1:height, j in 1:width
m[i, j] =for ((i ==in 1):height, || (j ==in 1) || (i == height) || (j == :width)) ?
m[i, j] = ((i == 1) || (j == 1) || (i == height) || (j == width)) ?
Sector(configs["walltile"], wallcolor, nocolor) :
m[i, j] = probinteriorwall > rand() ?
Sector(Char(configsm["walltile"])i, wallcolor,j] nocolor= probinteriorwall > rand() :?
Sector(Char(configs["ballchancewalltile"]), >wallcolor, rand(nocolor) ?:
Sector(Char(configs["emptytileballchance"]), > rand(sectorcolors, 2)...) :?
Sector(Char(configs["emptytile"]), rand(sectorcolors), nocolor2)...) :
Sector(Char(configs["emptytile"]), rand(sectorcolors), nocolor)
end
for i in 2:height-1, j in 2:width-1 # once walls up, open any isolated sectors
arr = adjacent(Pt(i, j))
if !iswall(m, i, j) &&arr all(p ->= iswalladjacent(mPt(i, pj), arr)
if !iswall(m[, i, j]) =&& Sectorall(Char(configs["emptytile"]),p rand-> iswall(sectorcolorsm, 2p)..., arr)
m[i, j] = Sector(Char(configs["emptytile"]), rand(sectorcolors, 2)...)
end
end
if all(colr -> sum(s -> s.clr == colr, m) >= sum(s -> s.ball == colr, m), sectorcolors)
break # redo if more balls than sectors for a color
end
end
Line 114 ⟶ 121:
while true
i, j = rand(rows), rand(cols)
if hasball(m[i, j]) # agent goes on empty sector at start
m[i, j] = Sector(configs["emptytile"], m[i, j].clr, nocolor)
return Grid(m, Agent(Pt(i, j), North, nocolor), 0)
Line 283 ⟶ 290:
 
end # modulino
</syntaxhighlight>
</lang>
File: gtk_remoteserversimulation.jl
<langsyntaxhighlight lang="julia">using Distributed, Sockets, Gtk, Colors, Graphics, Cairo
 
include("RemoteGameServerClient.jl")
Line 383 ⟶ 390:
end
 
matchballsgameserver()</syntaxhighlight>
</lang>
4,105

edits