Remote agent/Agent logic/Julia: Difference between revisions

m
avoid certain unwinnable positions
(julia example)
 
m (avoid certain unwinnable positions)
Line 4:
<br />
When the agent holds a ball, it will have a preference for straight line paths leading to an empty sector the color of the agent's ball in order to drop the ball.
<br />
If the agent carries the same ball for over 25 moves, it will drop that ball and look for a differently colored ball.
<lang julia>using Distributed, Gtk, Colors, Cairo
 
Line 16 ⟶ 18:
const turnpi = [[East, West], [South, North], [West, East], [North, South]]
const dlabl = Dict(North => "north", East => "east", South => "south", West => "west")
const param = Dict("won" => [false], "carriedsame" => 0, "bannedball" => nocolor)
 
function ballhandler(grid)
sector = grid.mat[grid.agent.location.x, grid.agent.location.y]
agent = grid.agent
if rand() > 0.8
param["bannedball"] = nocolor # banned color is one that was hard to drop last time
end
if sector.ch == configs["emptytile"] && sector.clr != sector.ball
if (sector.ball == nocolor && agent.ball == sector.clr) ||
(sector.ball == nocolor && agent.ball != nocolor && param["carriedsame"] > 25)
sector.ball = agent.ball
agent.ball = nocolor
param["carriedsame"] = 0 # was able to drop this color
param["bannedball"] = (sector.clr != sector.ball) ? sector.ball : nocolor
return [Drop]
elseif sector.ball != nocolor && agent.ball == nocolor &&
sector.ball != param["bannedball"]
agent.ball = sector.ball
sector.ball = nocolor
Line 64 ⟶ 73:
allempty = [orderdir[i] for i in 1:length(nearby) if nearby[i] == configs["emptytile"]]
grid.turncount += 1
if ag.ball != nocolor
param["carriedsame"] += 1
end
if nearby[dirorder[ag.direction]] == configs["unknowntile"]
return vcat(ret, [Forward])
Line 97 ⟶ 109:
warnexec(c, g, s, l) = @warn("Server told client command was in error because $c")
ballexec(c, g, s, l) = begin s.ball = ballcolordict[c] end
wonexec(c, g, s, l) = wonparam[1"won"] = true
 
function bumpexec(c, g, s, l)
Line 113 ⟶ 126:
s.clr = scolordict[c]
end
 
wonexec(c, g, s, l) = won[1] = true
 
const charexec = Dict{Char, Function}(GameOver => wonexec,
Line 212 ⟶ 223:
debug && println("clientsendcommand: Reply from server is $reply")
processreplies(reply, grid)
if wonparam[1"won"] == true
println("Game over, agent won in ", grid.turncount, " moves.")
warn_dialog("You have WON the game!\nTotal moves: $(grid.turncount)", win)
4,102

edits