Remote agent/Simulation: Difference between revisions
Content added Content deleted
(Revert to binary 'rd') |
(Cleaned up) |
||
Line 2: | Line 2: | ||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
This is the server. For the client, see [[Remote agent/Agent logic#PicoLisp]]. |
|||
Here is my first attempt on the server part. It works. After starting |
|||
(gameServer), you |
After starting (gameServer), you might for testing purposesalso connect with 'telnet', type the commands, and see the responses. |
||
responses. |
|||
<lang PicoLisp># Global variables: |
<lang PicoLisp># Global variables: |
||
# '*Port' is the port where the server is listening |
# '*Port' is the port where the server is listening |
||
Line 85: | Line 84: | ||
# Start the game server |
# Start the game server |
||
(de gameServer () |
(de gameServer (DX DY Balls Walls) |
||
(loop |
(loop |
||
(setq *Sock (listen *Port)) |
(setq *Sock (listen *Port)) |
||
Line 93: | Line 92: | ||
(in *Sock |
(in *Sock |
||
(out *Sock (prin "A")) # Greeting |
(out *Sock (prin "A")) # Greeting |
||
(when (= |
(when (= "A" (char (rd 1))) |
||
(newGame |
(newGame DX DY Balls Walls) |
||
(and *Dbg (showWorld)) |
|||
(while (rd 1) |
(while (rd 1) |
||
(out *Sock |
(out *Sock |
||
(case @ # Command character |
(case (char @) # Command character |
||
( |
("\^" # Forward |
||
(ifn ((car *Dir) *Agent) # Hit wall? |
(ifn ((car *Dir) *Agent) # Hit wall? |
||
(prin "|") # Yes: Bump event |
(prin "|") # Yes: Bump event |
||
Line 104: | Line 104: | ||
(prin (: field)) |
(prin (: field)) |
||
(and (: ball) (prin (lowc @))) ) ) ) |
(and (: ball) (prin (lowc @))) ) ) ) |
||
( |
(">" # Turn right |
||
(pop '*Dir) ) |
(pop '*Dir) ) |
||
( |
("<" # Turn left |
||
(do 3 (pop '*Dir)) ) |
(do 3 (pop '*Dir)) ) |
||
( |
("@" # Get ball |
||
(with *Agent |
(with *Agent |
||
(cond |
(cond |
||
Line 116: | Line 116: | ||
(setq *Ball (: ball)) |
(setq *Ball (: ball)) |
||
(=: ball) ) ) ) ) |
(=: ball) ) ) ) ) |
||
( |
("!" # Drop ball |
||
(with *Agent |
(with *Agent |
||
(cond |
(cond |
||
((not *Ball) (prin "a")) # No ball in agent |
((not *Ball) (prin "a")) # No ball in agent |
||
((: ball) (prin "S")) # Sector full |
((: ball) (prin "S")) # Sector full |
||
( |
(T (=: ball *Ball) |
||
(off *Ball) |
|||
(and (ending?) (prin "+")) ) ) ) ) ) # Game over |
|||
(prin ".") ) ) ) ) # Stop event |
(prin ".") ) ) ) ) # Stop event |
||
(bye) ) |
(bye) ) |
||
Line 137: | Line 138: | ||
For local tests, you can start also it interactively: |
For local tests, you can start also it interactively: |
||
<pre>: (newGame 8 8 20 40) (showWorld) |
<pre>: (newGame 8 8 20 40) (showWorld) |
||
+---+---+---+---+---+---+---+---+ |
+---+---+---+---+---+---+---+---+ |
||
8 | R Y | B | R R Br| Rb Br| |
8 | R Y | B | R R Br| Rb Br| |
||
Line 156: | Line 157: | ||
+---+---+---+---+---+---+---+---+ |
+---+---+---+---+---+---+---+---+ |
||
a b c d e f g h</pre> |
a b c d e f g h</pre> |
||
This displays the field colors in upper case letters, the balls in lower case |
This displays the field colors in upper case letters, the balls in lower case letters, and the position of the agent with an asterisk. |
||
letters, and the position of the agent with an asterisk. |