Snake and ladder: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by 2 users not shown)
Line 2,192:
 
main()</syntaxhighlight>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ this ] is .. ( --> [ )
 
[ table 0
.. .. .. 14 .. .. .. .. 31 ..
.. .. .. .. .. .. -7 .. .. 38
.. .. .. .. .. .. .. 84 .. ..
.. .. .. .. .. .. .. .. .. 59
.. .. .. .. .. .. .. .. .. ..
67 .. .. -34 .. .. .. .. .. ..
.. -19 81 -60 .. .. .. .. .. ..
91 .. .. .. .. .. .. .. .. ..
.. .. .. .. .. .. -24 .. .. ..
.. .. -73 .. -75 .. .. .. -78 .. ] is board ( n --> x )
 
[ $ "What are the player's names? "
input nest$ shuffle
cr say "Order of play: "
dup witheach [ echo$ sp ] cr cr
dup size 0 swap of
false temp put
[ temp share if
[ say "Rolling 6 means the player"
say " receives another go." cr
-1 split swap join
dip [ -1 split swap join ] ]
dip
[ behead dup echo$
nested join ]
behead
say " rolls "
6 random 1+ dup echo
dup 6 = temp replace
2dup + 100 > iff
[ say " which is too many "
say "so they don't move." cr
drop join ]
again
say " and moves to "
+ dup echo
dup 100 = iff
[ say " and wins." cr
drop ]
done
dup board
dup .. = iff
[ drop join
say "." cr ]
again
dup 0 < iff
[ say " which is a snake"
say " so they drop to "
abs dup echo say "." cr
nip join ]
again
say " which is a ladder"
say " so they rise to "
dup echo say "." cr
nip join
again ]
2drop
temp release ] is play ( --> [ )
 
play</syntaxhighlight>
 
{{out}}
 
<div style="height: 320px;overflow:scroll">
<pre>What are the player's names? Hector Zsazsa Kiki
 
Order of play: Kiki Zsazsa Hector
 
Kiki rolls 6 and moves to 6.
Rolling 6 means the player receives another go.
Kiki rolls 4 and moves to 10.
Zsazsa rolls 5 and moves to 5.
Hector rolls 1 and moves to 1.
Kiki rolls 2 and moves to 12.
Zsazsa rolls 2 and moves to 7.
Hector rolls 3 and moves to 4 which is a ladder so they rise to 14.
Kiki rolls 3 and moves to 15.
Zsazsa rolls 4 and moves to 11.
Hector rolls 1 and moves to 15.
Kiki rolls 4 and moves to 19.
Zsazsa rolls 5 and moves to 16.
Hector rolls 1 and moves to 16.
Kiki rolls 4 and moves to 23.
Zsazsa rolls 4 and moves to 20 which is a ladder so they rise to 38.
Hector rolls 2 and moves to 18.
Kiki rolls 5 and moves to 28 which is a ladder so they rise to 84.
Zsazsa rolls 3 and moves to 41.
Hector rolls 6 and moves to 24.
Rolling 6 means the player receives another go.
Hector rolls 2 and moves to 26.
Kiki rolls 3 and moves to 87 which is a snake so they drop to 24.
Zsazsa rolls 6 and moves to 47.
Rolling 6 means the player receives another go.
Zsazsa rolls 5 and moves to 52.
Hector rolls 6 and moves to 32.
Rolling 6 means the player receives another go.
Hector rolls 6 and moves to 38.
Rolling 6 means the player receives another go.
Hector rolls 3 and moves to 41.
Kiki rolls 5 and moves to 29.
Zsazsa rolls 5 and moves to 57.
Hector rolls 3 and moves to 44.
Kiki rolls 2 and moves to 31.
Zsazsa rolls 1 and moves to 58.
Hector rolls 4 and moves to 48.
Kiki rolls 4 and moves to 35.
Zsazsa rolls 3 and moves to 61.
Hector rolls 4 and moves to 52.
Kiki rolls 1 and moves to 36.
Zsazsa rolls 3 and moves to 64 which is a snake so they drop to 60.
Hector rolls 6 and moves to 58.
Rolling 6 means the player receives another go.
Hector rolls 4 and moves to 62 which is a snake so they drop to 19.
Kiki rolls 4 and moves to 40 which is a ladder so they rise to 59.
Zsazsa rolls 6 and moves to 66.
Rolling 6 means the player receives another go.
Zsazsa rolls 6 and moves to 72.
Rolling 6 means the player receives another go.
Zsazsa rolls 4 and moves to 76.
Hector rolls 4 and moves to 23.
Kiki rolls 3 and moves to 62 which is a snake so they drop to 19.
Zsazsa rolls 3 and moves to 79.
Hector rolls 3 and moves to 26.
Kiki rolls 6 and moves to 25.
Rolling 6 means the player receives another go.
Kiki rolls 2 and moves to 27.
Zsazsa rolls 4 and moves to 83.
Hector rolls 6 and moves to 32.
Rolling 6 means the player receives another go.
Hector rolls 6 and moves to 38.
Rolling 6 means the player receives another go.
Hector rolls 6 and moves to 44.
Rolling 6 means the player receives another go.
Hector rolls 1 and moves to 45.
Kiki rolls 2 and moves to 29.
Zsazsa rolls 2 and moves to 85.
Hector rolls 6 and moves to 51 which is a ladder so they rise to 67.
Rolling 6 means the player receives another go.
Hector rolls 1 and moves to 68.
Kiki rolls 2 and moves to 31.
Zsazsa rolls 3 and moves to 88.
Hector rolls 6 and moves to 74.
Rolling 6 means the player receives another go.
Hector rolls 4 and moves to 78.
Kiki rolls 6 and moves to 37.
Rolling 6 means the player receives another go.
Kiki rolls 1 and moves to 38.
Zsazsa rolls 3 and moves to 91.
Hector rolls 5 and moves to 83.
Kiki rolls 3 and moves to 41.
Zsazsa rolls 4 and moves to 95 which is a snake so they drop to 75.
Hector rolls 6 and moves to 89.
Rolling 6 means the player receives another go.
Hector rolls 5 and moves to 94.
Kiki rolls 4 and moves to 45.
Zsazsa rolls 6 and moves to 81.
Rolling 6 means the player receives another go.
Zsazsa rolls 3 and moves to 84.
Hector rolls 3 and moves to 97.
Kiki rolls 1 and moves to 46.
Zsazsa rolls 6 and moves to 90.
Rolling 6 means the player receives another go.
Zsazsa rolls 6 and moves to 96.
Rolling 6 means the player receives another go.
Zsazsa rolls 1 and moves to 97.
Hector rolls 6 which is too many so they don't move.
Rolling 6 means the player receives another go.
Hector rolls 2 and moves to 99 which is a snake so they drop to 78.
Kiki rolls 4 and moves to 50.
Zsazsa rolls 5 which is too many so they don't move.
Hector rolls 1 and moves to 79.
Kiki rolls 2 and moves to 52.
Zsazsa rolls 3 and moves to 100 and wins.
</pre>
</div>
 
=={{header|Racket}}==
Line 2,704 ⟶ 2,885:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
 
var rand = Random.new()
Line 2,797 ⟶ 2,978:
Player 3, on square 96, rolls a 4 and moves to square 100.
Player 3 wins!
</pre>
 
=={{header|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">include xpllib; \for Print
 
def SixThrowsAgain = true;
 
func NextSquare(Square);
int Square;
[case Square of
4: return 14;
9: return 31;
17: return 7;
20: return 38;
28: return 84;
40: return 59;
51: return 67;
54: return 34;
62: return 19;
63: return 81;
64: return 60;
71: return 91;
87: return 24;
93: return 73;
95: return 75;
99: return 78
other return Square;
];
 
func Turn(Player, Square);
int Player, Square;
int Roll, Next;
[loop [Roll:= Ran(6)+1;
Print("Player %d, on square %d, rolls a %d", Player, Square, Roll);
if Square + Roll > 100 then
Print(" but cannot move.\n")
else [Square:= Square + Roll;
Print(" and moves to square %d.\n", Square);
if Square = 100 then return 100;
Next:= NextSquare(Square);
if Square < Next then
[Print("Yay! Landed on a ladder. Climb up to %d.\n", Next);
if Next = 100 then return 100;
Square:= Next;
]
else if Square > Next then
[Print("Oops! Landed on a snake. Slither down to %d.\n", Next);
Square:= Next;
];
];
if Roll < 6 or not SixThrowsAgain then return Square;
Print("Rolled a 6 so roll again.\n");
];
];
 
int Players, I, NS;
[Players:= [1, 1, 1]; \three Players starting on square one
loop [for I:= 0 to 3-1 do
[NS:= Turn(I+1, Players(I));
if NS = 100 then
[Print("Player %d wins!\n", I+1);
return;
];
Players(I):= NS;
CrLf(0);
];
];
]</syntaxhighlight>
{{out}}
<pre>
Player 1, on square 1, rolls a 5 and moves to square 6.
 
Player 2, on square 1, rolls a 1 and moves to square 2.
 
Player 3, on square 1, rolls a 5 and moves to square 6.
 
Player 1, on square 6, rolls a 5 and moves to square 11.
 
Player 2, on square 2, rolls a 4 and moves to square 6.
 
Player 3, on square 6, rolls a 4 and moves to square 10.
 
Player 1, on square 11, rolls a 3 and moves to square 14.
 
Player 2, on square 6, rolls a 2 and moves to square 8.
 
Player 3, on square 10, rolls a 4 and moves to square 14.
 
Player 1, on square 14, rolls a 3 and moves to square 17.
Oops! Landed on a snake. Slither down to 7.
 
Player 2, on square 8, rolls a 6 and moves to square 14.
Rolled a 6 so roll again.
Player 2, on square 14, rolls a 2 and moves to square 16.
 
. . .
 
Player 3, on square 88, rolls a 6 and moves to square 94.
Rolled a 6 so roll again.
Player 3, on square 94, rolls a 3 and moves to square 97.
 
Player 1, on square 80, rolls a 1 and moves to square 81.
 
Player 2, on square 85, rolls a 6 and moves to square 91.
Rolled a 6 so roll again.
Player 2, on square 91, rolls a 6 and moves to square 97.
Rolled a 6 so roll again.
Player 2, on square 97, rolls a 3 and moves to square 100.
Player 2 wins!
</pre>
 
9,482

edits