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
m[i, j] = ((i == 1) || (j == 1) || (i == height) || (j == width)) ?
Sector(configs["walltile"], wallcolor, nocolor) :
Sector(Char(configs["
Sector(Char(configs["emptytile"]), rand(sectorcolors
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
if !iswall(m
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)
|