Remote agent/Simulation: Difference between revisions

Revert to binary 'rd'
(Logic error)
(Revert to binary 'rd')
Line 5:
(gameServer), you can connect with 'telnet', type the commands, and see the
responses.
<lang PicoLisp>(load# "@lib/simul.l")Global variables:
 
# Global variables:
# '*Port' is the port where the server is listening
# '*Sock' is the TCP socket after a client connected
Line 14 ⟶ 12:
# '*Ball' is the ball the agent is holding
# '*Dir' is a circular list of directions (north east south west .)
 
(load "@lib/simul.l")
 
# The server port
Line 93:
(in *Sock
(out *Sock (prin "A")) # Greeting
(when (= `(char "A") (charrd 1))
(newGame 8 8 20 40)
(while (charrd 1)
(out *Sock
(case @ # Command character
(`(char "\^") # Forward
(ifn ((car *Dir) *Agent) # Hit wall?
(prin "|") # Yes: Bump event
Line 104:
(prin (: field))
(and (: ball) (prin (lowc @))) ) ) )
(`(char ">") # Turn right
(pop '*Dir) )
(`(char "<") # Turn left
(do 3 (pop '*Dir)) )
(`(char "@") # Get ball
(with *Agent
(cond
Line 116:
(setq *Ball (: ball))
(=: ball) ) ) ) )
(`(char "!") # Drop ball
(with *Agent
(cond
Line 134:
(: field)
(if (: ball) (lowc @) " ") ) ) ) )</lang>
An online demo version of this server runs on port 54545 of "picolisp.com". It can be used for testing.
For testing, you can start also it interactively:
 
For testinglocal tests, you can start also it interactively:
<pre>: (newGame 8 8 20 40) (showWorld)
+---+---+---+---+---+---+---+---+
Anonymous user