Remote agent/Simulation/Julia: Difference between revisions

m
avoid generating some unwinnable maps
mNo edit summary
m (avoid generating some unwinnable maps)
Line 96:
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 ⟶ 119:
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)
4,102

edits