War card game: Difference between revisions

15,822 bytes added ,  2 months ago
Added FreeBASIC
(Added FreeBASIC)
 
(18 intermediate revisions by 7 users not shown)
Line 25:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">UInt32 seed = 0
F nonrandom(n)
:seed = (1664525 * :seed + 1013904223) [&] FFFF'FFFF
Line 94:
V WG = WarCardGame()
L WG.turn()
L.continue</langsyntaxhighlight>
 
{{out}}
Line 129:
 
Player 2 wins the game.
</pre>
 
=={{header|Applesoft BASIC}}==
{{trans|Python}}
* The Bicycle rules are set up by default.
* When the winning player picks up cards, the cards are randomized when added to the bottom of the player's deck. see [[War_card_game#Raku|Raku]] for details.
* Other variations can be played by passing different parameters.
<syntaxhighlight lang="autohotkey"> 100 R = RND (0): REM SEED
110 W = 1: REM BICYCLE RULE: ONLY ONE EXTRA CARD GIVEN UP IN WAR
120 P = 2: REM BICYCLE RULE: ONLY TWO PLAYERS
130 D = 1: REM BICYCLE RULE: ONLY ONE DECK OF CARDS
140 DIM D$(P),C$(P),G(P),L(P)
150 SUIT$ = "CDHS"
160 FACE$ = "23456789TJQKA"
170 M = LEN (SUIT$)
180 FOR I = 1 TO D: FOR S = 1 TO M: FOR F = 1 TO LEN (FACE$):P$ = P$ + CHR$ ((F - 1) * M + (S - 1)): NEXT F,S,I
190 TEXT : HOME : POKE 34,12
REM DEAL TO PLAYERS
200 GOSUB 700"SHUFFLE
210 E = INT (N / P)
220 FOR I = 1 TO P
230 D$(I) = MID$ (P$,(I - 1) * E + 1,E)
240 NEXT
250 P$ = MID$ (P$,(I - 1) * E + 1): REM WINNER OF THE FIRST PLAY KEEPS THESE REMAINING CARDS
260 P$ = "": REM REMOVE REMAINING CARDS FROM THE GAME
REM PLAY
300 FOR T = 0 TO 1E38
310 GOSUB 400"TURN
320 IF Q = 0 THEN NEXT T
330 PRINT " IN "T" TURNS": TEXT : VTAB 11: PRINT : CALL - 868: PRINT "...": VTAB 23
340 END
 
REM TURN
400 PRINT : GOSUB 900"IS GAME OVER?
410 IF Q THEN RETURN
420 U = 0: REM UTMOST CARD
430 C = 0: REM COUNT THE PLAYERS WITH THE UTMOST CARD
440 FOR I = 1 TO P
450 C$(I) = "" : IF NOT L(I) THEN C$(I) = MID$ (D$(I),1,1)
460 IF LEN (C$(I)) THEN GOSUB 800"DRAW CARD
470 NEXT I
480 IF C = 1 GOTO 600"WINNER TAKE CARDS
490 FOR I = 1 TO P:L(I) = G(I) < > U: NEXT I
500 PRINT "WAR! ";
510 GOSUB 900"IS GAME OVER?
520 IF Q THEN RETURN
530 C = 0
540 FOR I = 1 TO P:P$ = P$ + C$(I): NEXT I
550 FOR I = 1 TO P
REM DOES NOT APPLY TO 2 PLAYER GAMES (BICYCLE RULE): Y MEANS IGNORE THE RULE THAT ONLY THE WINNERS PLACE CARD(S) FACE DOWN
560 IF Y OR NOT L(I) THEN FOR J = 1 TO W:C$ = MID$ (D$(I),1,1) :C = C + LEN(C$) : P$ = P$ + C$ :D$(I) = MID$ (D$(I),2): NEXT J
570 NEXT I
580 PRINT C" CARDS PLACED FACE DOWN.";
590 RETURN
 
REM WINNER TAKE CARDS
600 FOR I = 1 TO P
610 L(I) = 0
620 P$ = P$ + C$(I)
630 NEXT I
640 PRINT "PLAYER "A" TAKES "LEN(P$);
650 IF NOT Z THEN GOSUB 710"SHUFFLE
660 D$(A) = D$(A) + P$
670 P$ = ""
680 RETURN
 
REM SHUFFLE
700 PRINT "SHUFFLING ";
710 N = LEN (P$)
720 FOR I = 1 TO N
730 IF I - INT (I / 4) * 4 = 1 THEN PRINT ".";
740 R = INT ( RND (1) * N + 1)
750 R$ = MID$ (P$,R,1) : C$ = MID$ (P$,I,1)
760 P$ = MID$ (P$,1,I - 1) + R$ + MID$ (P$,I + 1)
770 P$ = MID$ (P$,1,R - 1) + C$ + MID$ (P$,R + 1)
780 NEXT
790 RETURN
 
REM DRAW CARD
800 G = ASC (C$(I))
810 G(I) = INT (G / M) + 1
820 PRINT MID$ (FACE$,G(I),1) MID$ (SUIT$,G - (G(I) - 1) * M + 1,1)" ";
830 D$(I) = MID$ (D$(I),2)
840 C = C + (G(I) = U)
850 IF G(I) > U THEN U = G(I):C = 1:A = I
860 RETURN
 
REM IS GAME OVER?
900 C = 0
910 FOR I = 1 TO P
920 IF LEN (D$(I)) THEN A = I:C = C + 1
930 NEXT I
940 IF C > 1 THEN RETURN
REM GAME OVER - WHO WON MESSAGE
950 Q = 1
960 IF C THEN PRINT "PLAYER "A" WINS THE GAME";: RETURN
970 PRINT "GAME ENDS AS A TIE";: RETURN</syntaxhighlight>
<syntaxhighlight lang="autohotkey">CLEAR : R = RND ( - 58) : GOTO 110</syntaxhighlight>
{{out}}
<pre>SHUFFLING .............
JD 9H PLAYER 1 TAKES 2.
4C 5C PLAYER 2 TAKES 2.
2D 8C PLAYER 2 TAKES 2.
TH AS PLAYER 2 TAKES 2.
7D QS PLAYER 2 TAKES 2.
4S 8H PLAYER 2 TAKES 2.
AD 7C PLAYER 1 TAKES 2.
JS 2S PLAYER 1 TAKES 2.
3C 3S WAR! 2 CARDS PLACED FACE DOWN.
TD KH PLAYER 2 TAKES 6..
...
8D 2D PLAYER 1 TAKES 2.
TD 7C PLAYER 1 TAKES 2.
7S 6C PLAYER 1 TAKES 2.
9H 8H PLAYER 1 TAKES 2.
3D 8C PLAYER 2 TAKES 2.
AD 3C PLAYER 1 TAKES 2.
4H 4C WAR! 2 CARDS PLACED FACE DOWN.
7D 7H WAR! 2 CARDS PLACED FACE DOWN.
JH 3D PLAYER 1 TAKES 10...
9D 8C PLAYER 1 TAKES 2.
PLAYER 1 WINS THE GAME IN 432 TURNS
</pre>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">suits := ["♠", "♦", "♥", "♣"]
faces := [2,3,4,5,6,7,8,9,10,"J","Q","K","A"]
deck := [], p1 := [], p2 := []
Line 196 ⟶ 318:
output := StrReplace(output, " )", ") ")
output := StrReplace(output, " -", " -")
return output</langsyntaxhighlight>
{{out}}
<pre>------------------------------------------
Line 273 ⟶ 395:
round# 70 10♣ vs 10♦ **WAR** 50 0
P1 Wins</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
 
#include <iostream>
#include <vector>
#include <algorithm>
 
class war_game {
public:
war_game() {
for ( char suit : SUITS ) {
for ( char pip : PIPS ) {
deck.emplace_back(card(suit, pip));
}
}
std::random_shuffle(deck.begin(), deck.end());
 
handA = { deck.begin(), deck.begin() + 26 };
handB = { deck.begin() + 26, deck.end() };
}
 
void next_turn() {
card cardA = handA.front(); handA.erase(handA.begin());
card cardB = handB.front(); handB.erase(handB.begin());
tabledCards.emplace_back(cardA);
tabledCards.emplace_back(cardB);
int32_t rankA = getRank(cardA.pip);
int32_t rankB = getRank(cardB.pip);
std::cout << cardA.pip << cardA.suit << " " << cardB.pip << cardB.suit << std::endl;
 
if ( rankA > rankB ) {
std::cout << " Player A takes the cards" << std::endl;
std::random_shuffle(tabledCards.begin(), tabledCards.end());
handA.insert(handA.end(), tabledCards.begin(), tabledCards.end());
tabledCards.clear();
} else if ( rankA < rankB ) {
std::cout << " Player B takes the cards" << std::endl;
std::random_shuffle(tabledCards.begin(), tabledCards.end());
handB.insert(handB.end(), tabledCards.begin(), tabledCards.end());;
tabledCards.clear();
} else {
std::cout << " War!" << std::endl;
if ( game_over() ) {
return;
}
 
card cardAA = handA.front(); handA.erase(handA.begin());
card cardBB = handB.front(); handB.erase(handB.begin());
tabledCards.emplace_back(cardAA);
tabledCards.emplace_back(cardBB);
std::cout << "? ? Cards are face down" << std::endl;
if ( game_over() ) {
return;
}
 
next_turn();
}
}
 
bool game_over() const {
return handA.size() == 0 || handB.size() == 0;
}
 
void declare_winner() const {
if ( handA.size() == 0 && handB.size() == 0 ) {
std::cout << "The game ended in a tie" << std::endl;
} else if ( handA.size() == 0 ) {
std::cout << "Player B has won the game" << std::endl;
} else {
std::cout << "Player A has won the game" << std::endl;
}
}
private:
class card {
public:
card(const char suit, const char pip) : suit(suit), pip(pip) {};
char suit, pip;
};
 
int32_t getRank(const char ch) const {
auto it = find(PIPS.begin(), PIPS.end(), ch);
if ( it != PIPS.end() ) {
return it - PIPS.begin();
}
return -1;
}
 
std::vector<card> deck, handA, handB, tabledCards;
inline static const std::vector<char> PIPS = { '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
inline static const std::vector<char> SUITS = { 'C', 'D', 'H', 'S' };
};
 
int main() {
war_game wargame;
srand((unsigned) time(NULL));
while ( ! wargame.game_over() ) {
wargame.next_turn();
}
 
wargame.declare_winner();
}
</syntaxhighlight>
{{ out }}
<pre>
JD 9D
Player A takes the cards
TH 7S
Player A takes the cards
6H QC
Player B takes the cards
9C 9H
War!
? ? Cards are face down
AC 3C
Player A takes the cards
 
... many lines elided
 
3D 6C
Player B takes the cards
6D 4D
Player A takes the cards
JD 2C
Player A takes the cards
3C 3D
War!
? ? Cards are face down
Player A has won the game
</pre>
 
=={{header|FreeBASIC}}==
{{trans|XPLo}}
<syntaxhighlight lang="vbnet">Dim Shared As Integer stack(1, 51) ' each player's stack of cards (52 maximum)
Dim Shared As Integer inx(1) ' index to last card (+1) for each stack
Dim Shared As Integer carta
 
Sub MoveCard(hacia As Integer, desde As Integer) ' Move top card desde stack to bottom of To stack
Dim As Integer i
carta = stack(desde, 0) ' take top carta from desde stack
For i = 0 To inx(desde) - 2 ' shift remaining cards over
stack(desde, i) = stack(desde, i + 1)
Next i
If inx(desde) > 0 Then inx(desde) -= 1 ' remove desde card from its stack
stack(hacia, inx(hacia)) = carta ' add carta to bottom of To stack
If inx(hacia) < 52 Then inx(hacia) += 1 ' remove desde card from its stack
End Sub
 
Dim As String suit = "HDCS "
Dim As String rank = "23456789TJQKA "
Dim As Integer top ' index to compared cards, = stack top if not war
Dim As Integer deck(51) ' initial card deck (low 2 bits = suit)
For carta = 0 To 51 ' make a complete deck of cards
deck(carta) = carta
Next carta
Dim As Integer n, i, j, p, t
 
Randomize Timer
For n = 0 To 10000 ' shuffle the deck by swapping random locations
i = Int(Rnd * 52): j = Int(Rnd * 52)
Swap deck(i), deck(j)
Next n
For n = 0 To 51 ' deal deck into two stacks
carta = deck(n)
i = n \ 2
p = n Mod 2
stack(p, i) = carta
Next n
inx(0) = 52 \ 2: inx(1) = 52 \ 2 ' set indexes to last card +1
 
Do
For p = 0 To 1 ' show both stacks of cards
For i = 0 To inx(p) - 1
carta = stack(p, i)
Print Left(rank, carta Shr 2);
Next i
Print
For i = 0 To inx(p) - 1
carta = stack(p, i)
Print Mid(suit, (carta And 3) + 1, 1);
Next i
Print
Next p
If inx(0) = 0 Or inx(1) = 0 Then Exit Do ' game over
top = 0 ' compare card ranks (above 2-bit suits)
Do
If (stack(0, top) Shr 2) = (stack(1, top) Shr 2) Then
Color 3 : Print "War!" : Print : Color 7
top += 2 ' play a card down and a card up
Elseif (stack(0, top) Shr 2) > (stack(1, top) Shr 2) Then
For i = 0 To top ' move cards to stack 0
MoveCard(0, 0): MoveCard(0, 1)
Next i
Exit Do
Else
For i = 0 To top ' move cards to stack 1
MoveCard(1, 1): MoveCard(1, 0)
Next i
Exit Do
End If
Loop
Sleep 1000, 1
Print
Loop
 
End</syntaxhighlight>
 
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 381 ⟶ 710:
rand.Seed(time.Now().UnixNano())
war()
}</langsyntaxhighlight>
 
{{out}}
Line 411 ⟶ 740:
Player 2 has insufficient cards left.
Player 1 wins the game!
</pre>
 
=={{header|J}}==
Implementation:<syntaxhighlight lang="j">DECK=: '2 3 4 5 6 7 8 9 10 J K Q A' (,' of ',])&.>/&cut '♣ ♦ ♥ ♠'
rank=: DECK {{ {."1 ($m)#:(,m) i. y }}
shuffle=: {~ ?~@#
deal=: _26 ]\ shuffle@,@DECK
cardwar=: {{
TURNS=: 0
'P1 P2'=: <each deal''
while. 0<P1 *&# P2 do. turn TURNS=: TURNS+1 end.
after=. ' after ',TURNS,&":' turn','s'#~1~:TURNS
if. #P1 do. 'Player 1 wins', after
elseif. #P2 do. 'Player 2 wins', after
else. 'Tie',after end.
}}
plays=: {{ ((m)=: }.".m)](echo n,~(m,' plays '),;'nothing'&[^:(0=#@]){.".m)]({.".m) }}
turn=: {{
c=. (b=. 'P2' plays''),(a =. 'P1' plays'')
while. a =&rank b do.
if. 0=P1 *&# P2 do. echo 'No more cards to draw' return. end.
c=. c, (a=. 'P1' plays''),(b =. 'P2' plays''), 'P1' plays' face down', 'P2' plays' face down'
end.
('P',":1+a <&rank b) takes ({~ ?~@#)c-.a:
}}
takes=: {{
(m)=: (".m),y
echo m,' takes ',;(<' and ') _2}}.,(<', '),.y
echo''
}}</syntaxhighlight>
 
Example run:<syntaxhighlight lang="j"> cardwar''
P1 plays 6 of ♦
P2 plays 9 of ♥
P2 takes 6 of ♦ and 9 of ♥
 
P1 plays K of ♣
P2 plays 6 of ♣
P1 takes K of ♣ and 6 of ♣
 
P1 plays A of ♦
P2 plays A of ♥
P2 plays 5 of ♠ face down
P1 plays J of ♥ face down
P2 plays 2 of ♣
P1 plays J of ♦
P1 takes A of ♥, J of ♥, A of ♦, 2 of ♣, 5 of ♠ and J of ♦
 
P1 plays 7 of ♥
P2 plays 10 of ♣
P2 takes 10 of ♣ and 7 of ♥
 
(... many lines deleted ...)
 
P1 plays 2 of ♦
P2 plays 5 of ♥
P2 takes 2 of ♦ and 5 of ♥
 
P1 plays K of ♥
P2 plays 4 of ♥
P1 takes 4 of ♥ and K of ♥
 
P1 plays 3 of ♦
P2 plays 3 of ♣
P2 plays 2 of ♦ face down
P1 plays 6 of ♠ face down
P2 plays 5 of ♥
P1 plays K of ♠
P1 takes 6 of ♠, K of ♠, 5 of ♥, 3 of ♣, 3 of ♦ and 2 of ♦
 
Player 1 wins after 86 turns</syntaxhighlight>
 
=={{header|Java}}==
 
<syntaxhighlight lang="java">
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
 
public final class WarCardGame {
 
public static void main(String[] args) {
WarGame warGame = new WarGame();
while ( ! warGame.gameOver() ) {
warGame.nextTurn();
}
warGame.declareWinner();
}
}
 
final class WarGame {
public WarGame() {
deck = new ArrayList<Card>(52);
for ( Character suit : SUITS ) {
for ( Character pip : PIPS ) {
deck.add( new Card(suit, pip) );
}
}
Collections.shuffle(deck);
handA = new ArrayList<Card>(deck.subList(0, 26));
handB = new ArrayList<Card>(deck.subList(26, 52));
tabledCards = new ArrayList<Card>();
}
public void nextTurn() {
Card cardA = handA.remove(0);
Card cardB = handB.remove(0);
tabledCards.add(cardA);
tabledCards.add(cardB);
int rankA = PIPS.indexOf(cardA.pip);
int rankB = PIPS.indexOf(cardB.pip);
System.out.print(cardA + " " + cardB);
if ( rankA > rankB ) {
System.out.println(" Player A takes the cards");
Collections.shuffle(tabledCards);
handA.addAll(tabledCards);
tabledCards.clear();
} else if ( rankA < rankB ) {
System.out.println(" Player B takes the cards");
Collections.shuffle(tabledCards);
handB.addAll(tabledCards);
tabledCards.clear();
} else {
System.out.println(" War!");
if ( gameOver() ) {
return;
}
Card cardAA = handA.remove(0);
Card cardBB = handB.remove(0);
tabledCards.add(cardAA);
tabledCards.add(cardBB);
System.out.println("? ? Cards are face down");
if ( gameOver() ) {
return;
}
nextTurn();
}
}
public boolean gameOver() {
return handA.size() == 0 || handB.size() == 0;
}
public void declareWinner() {
if ( handA.size() == 0 && handB.size() == 0 ) {
System.out.println("The game ended in a tie");
} else if ( handA.size() == 0 ) {
System.out.println("Player B has won the game");
} else {
System.out.println("Player A has won the game");
}
}
private record Card(Character suit, Character pip) {
@Override
public String toString() {
return "" + pip + suit;
}
}
private List<Card> deck, handA, handB, tabledCards;
private static final List<Character> PIPS =
Arrays.asList( '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' );
private static final List<Character> SUITS = List.of( 'C', 'D', 'H', 'S' );
}
</syntaxhighlight>
{{ out }}
<pre>
5H 7D Player B takes the cards
QS 4C Player A takes the cards
KS 4H Player A takes the cards
7S 7C War!
? ? Cards are face down
2D 4D Player B takes the cards
3H JC Player B takes the cards
JD AH Player B takes the cards
8C 5S Player A takes the cards
TH KH Player B takes the cards
9C QD Player B takes the cards
3C QH Player B takes the cards
JH 9H Player A takes the cards
7H KC Player B takes the cards
9D 2C Player A takes the cards
AS AD War!
? ? Cards are face down
5C QC Player B takes the cards
2S 9S Player B takes the cards
8D KD Player B takes the cards
 
... many lines elided
 
7S 9D Player B takes the cards
9H 2S Player A takes the cards
8D KS Player B takes the cards
AH AC War!
? ? Cards are face down
2S 2H War!
Player B has won the game
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># https://bicyclecards.com/how-to-play/war/
 
using Random
Line 463 ⟶ 1,004:
 
warcardgame()
</langsyntaxhighlight>{{out}}
<pre>
5♦ 3♥ Player 1 takes the cards.
Line 501 ⟶ 1,042:
=={{header|Lua}}==
{{libheader|LÖVE}}
<langsyntaxhighlight Lualang="lua">-- main.lua
function newGame ()
-- new deck
Line 631 ⟶ 1,172:
end
end
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
We use module "playing_cards" from task https://rosettacode.org/wiki/Playing_cards.
<langsyntaxhighlight Nimlang="nim">import strformat
import playing_cards
 
Line 727 ⟶ 1,268:
if hands[Player2].len == 0:
echo "Player 1 wins this game."
break</langsyntaxhighlight>
 
{{out}}
Line 833 ⟶ 1,374:
=={{header|Perl}}==
There are two players, 'one' and 'two'. This shows each players hand as the game progresses.
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/War_Card_Game
Line 852 ⟶ 1,393:
s/^(.{4})(.*)\n(.{4})(.*)$/ print "WAR!!!\n\n"; $war .= "$1$3";
"$2\n$4" /e; # tie means war
print "player '", /^.{10}/ ? 'one' : 'two', "' wins in $cnt moves\n";</langsyntaxhighlight>
{{out}}
<pre>
Line 904 ⟶ 1,445:
=={{header|Phix}}==
Shuffles on pickup to significantly shorten the games
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">deck</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">shuffle</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">52</span><span style="color: #0000FF;">)),</span>
Line 962 ⟶ 1,503:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 984 ⟶ 1,525:
=={{header|Python}}==
{{trans|Julia}}
<langsyntaxhighlight lang="python">""" https://bicyclecards.com/how-to-play/war/ """
 
from numpy.random import shuffle
Line 1,049 ⟶ 1,590:
while WG.turn():
continue
</langsyntaxhighlight>{{out}}
<pre>
8♠ K♠ Player 2 takes the cards.
Line 1,094 ⟶ 1,635:
{{trans|Julia}} (and inspired by Raku's thnudergnat rules)
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define current-battle-length (make-parameter 3))
Line 1,132 ⟶ 1,673:
turn))
 
(displayln (war-card-game))</langsyntaxhighlight>
 
{{out}}
Line 1,194 ⟶ 1,735:
In glorious ANSI color! (The output loses much when pasted in as text so show output as screenshot images.)
 
<syntaxhighlight lang="raku" perl6line>unit sub MAIN (:$war where 2..4 = 4, :$sleep = .1);
 
my %c = ( # convenience hash of ANSI colors
Line 1,307 ⟶ 1,848:
print-at $height + 2, $cols div 2 - 40, "{%c<blue>} Player 1: {+@player[0] ?? '52' !! "{%c<red>}0"}{%c<blue>} cards ";
print-at $height + 2, $cols div 2 + 20, "{%c<blue>} Player 2: {+@player[1] ?? '52' !! "{%c<red>}0"}{%c<blue>} cards ";
clean-up;</langsyntaxhighlight>
 
{{out|Sample outout Bicycle}}
Line 1,321 ⟶ 1,862:
 
I've also assumed that if a player wins a round, his/her own cards (in the order played) are added back to the bottom of his/her hand before the other player's cards.
<langsyntaxhighlight ecmascriptlang="wren">import "random" for Random
import "./queue" for Deque
 
var rand = Random.new()
Line 1,396 ⟶ 1,937:
}
 
war.call()</langsyntaxhighlight>
 
{{out}}
Line 1,439 ⟶ 1,980:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">char Deck(52), \initial card deck (low 2 bits = suit)
Stack(2, 52); \each player's stack of cards (52 maximum)
int Inx(2), \index to last card (+1) for each stack
Line 1,505 ⟶ 2,046:
];
]
]</langsyntaxhighlight>
 
{{out}}
2,122

edits