Skip to content

Instantly share code, notes, and snippets.

@amitport
Last active December 23, 2015 01:39
Show Gist options
  • Save amitport/6561557 to your computer and use it in GitHub Desktop.
Save amitport/6561557 to your computer and use it in GitHub Desktop.
War
#wait until every player perform the "battle!" action
action 'Battle!', ->
#move the top card from each player down pile to battle pile
for p in [player, opponent]
p.down.top().flip()
p.down.moveTo(p.battle, 1)
#check if we have a war
while (pV=player.battle.top().value.rank) is (oV=opponent.battle.top().value.rank)
for p in [player, opponent]
#end the game if one of the player don't have enough cards for war
if p.down.size() < 4 then return "end"
#move 3 faced-down and 1 face-up card to the battle pile
p.down.moveTo(p.battle, 3)
p.down.top().flip()
p.down.moveTo(p.battle, 1)
#determine the winner of the battle
[battleWinner, battleLoser] = if pV > oV then [player, opponent] else [opponent, player]
#end the game if the loser don't have any more cards
if battleLoser.down.isEmpty() then return "end"
#move the battle cards to the winner
battleLoser.battle.moveTo(battleWinner.battle, battleLoser.battle.size())
battleWinner.battle.flipDown().shuffle().moveTo(battleWinner.down, battleWinner.battle.size())
mainGameLoop()
mainGameLoop()
<div class="container">
<div class="row">
<div class="col-xs-5">
<pile container="player" name="battle" />
</div>
<div class="col-xs-2">
<action name="Battle!" />
</div>
<div class="col-xs-5">
<pile class="pull-right" container="opponent" name="battle" />
</div>
</div>
<br/>
<div class="row">
<div class="col-xs-5">
<pile container="player" name="down" />
</div>
<div class="col-xs-7">
<pile class="pull-right" container="opponent" name="down" />
</div>
</div>
</div>

War typically involves two players. It uses a standard [French playing card deck][]. Due to its simplicity, it is played most often by children.

Deal

The deck is divided evenly among the two players, giving each a down stack. In unison, each player reveals the top card of their deck - this is called, a battle.

Battle

The player with the higher card takes both the cards played and moves them to the bottom of their stack.

If the two cards played are of equal value, then there is a war:

  • Both players play the next 3 cards of their pile face down and then another (4th) card face-up.
  • The owner of the higher face-up card wins the war and adds all 10 cards on the table to the bottom of their deck.
  • If the face-up cards are again equal then the battle repeats.

Ending

If a player runs out of cards after a battle or during a war that player immediately loses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment