Snake and ladder: Difference between revisions

m
→‎{{header|REXX}}: used an idiomatic method to leave the DO loops, fixed a comment.
(→‎{{header|J}}: load required addons)
m (→‎{{header|REXX}}: used an idiomatic method to leave the DO loops, fixed a comment.)
Line 1,020:
end /*k*/ /* [↑] number when landing on a square*/
/* [↓] define ladder destination.*/
@.4=14; @.9=31; @.20=38; @.28=84; @.40=59; @.51=67; @.63=81; @.71=91; @.95=75
@.17=7; @.54=34; @.62=19; @.64=60; @.87=24; @.93=73; @.99=78
/* [↑] define snake destination.*/
player.= 1 /*start all players on the 1st square. */
do games=1 until $==100; say center(' turn ' games" ", 75, "─") /*shot title. */
do j=1 for np until $==100; $= turn(j, player.j); player.j= /*do P's turn.*/$
end player. /*j=*/ $; if $==100 then leave games /*haveprocess each of the number of winner?players*/
end /*games*/ end /*jexit both loops when there's a winner*/
end /*forever*/
say pad 'Player ' j " wins!" /*announce the winner; the game is over*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
turn: parse arg P, square; ?= random(1, 6) /*simulate a roll of a six─sided die. */
?@does= random(1,pad 6) 'Player ' P " on square " right(square, 2) ' /*simulaterolls a roll' of a six─sided die. */?
@does= pad 'Player ' P " on square " right(square,2) ' rolls a ' ?
if square+?>100 then do
say @does " but can't move. Next player's turn."
return square
end
else do
square= square + ? /*move a player.*/
say @does " and moves to square" right(square, 3)
end
next= @.square /*where moved to*/