Snake and ladder: Difference between revisions

add PicoLisp
m (→‎{{header|Perl}}: Fix link: Perl 6 --> Raku)
(add PicoLisp)
Line 1,437:
Player 2, on square 97, rolls a 3 and moves to square 100
Player 2 wins!
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(seed (in "/dev/urandom" (rd 8)))
(setq *D
'((4 14 T) (9 31 T) (17 7) (20 38 T)
(28 84 T) (40 59 T) (51 67 T) (54 34)
(62 19) (63 81 T) (64 60) (71 91 T)
(87 24) (93 73) (95 75) (99 78) ) )
(de players (N)
(make
(for I N
(let P (pack "Player " I)
(set P 1)
(link P) ) ) ) )
(de turn (P)
(use D
(loop
(setq D (rand 1 6))
(prin P " on square " (val P) ", rolls a " D)
(if (> (+ (val P) D) 100)
(prinl " but cannot move")
(set P (+ (val P) D))
(prinl " and move to square " (val P))
(when (= (val P) 100)
(prinl P " wins!")
(throw 'win) )
(when (assoc (val P) *D)
(set P (cadr @))
(if (cddr @)
(prinl "Yay! Landed on ladder. Climb up to " (val P))
(prinl "Ooops! Landed on snake. Slither down to " (val P)) ) ) )
(T (> 6 D))
(prinl "Rolled a 6 so roll again") ) ) )
(de main (N)
(let P (players N)
(catch 'win
(loop
(mapc turn P) ) ) ) )
(main 10)</lang>
{{out}}
<pre>
Player 1 on square 1, rolls a 5 and move to square 6
Player 2 on square 1, rolls a 2 and move to square 3
Player 3 on square 1, rolls a 2 and move to square 3
Player 4 on square 1, rolls a 6 and move to square 7
Rolled a 6 so roll again
Player 4 on square 7, rolls a 5 and move to square 12
Player 5 on square 1, rolls a 3 and move to square 4
Yay! Landed on ladder. Climb up to 14
Player 6 on square 1, rolls a 4 and move to square 5
Player 7 on square 1, rolls a 1 and move to square 2
Player 8 on square 1, rolls a 4 and move to square 5
Player 9 on square 1, rolls a 1 and move to square 2
Player 10 on square 1, rolls a 2 and move to square 3
...
...
...
Ooops! Landed on snake. Slither down to 60
Rolled a 6 so roll again
Player 9 on square 60, rolls a 6 and move to square 66
Rolled a 6 so roll again
Player 9 on square 66, rolls a 2 and move to square 68
Player 10 on square 96, rolls a 4 and move to square 100
Player 10 wins!
</pre>
 
298

edits