Code Monkey home page Code Monkey logo

warjs's Introduction

War.JS

Running the Game

This program requires Node to run. Start with an npm install, then the program can be run using npm start from a command line at the project directory.

Running the Tests

This project uses Jest for testing. The tests can be run using npm test, and a coverage report can be generated using npm test -- --coverage. Jest was chosen due to its simplicity, likeness to existing test frameworks, and speed of configuration.

About the Card Game, War

Wikipedia Article

Differences Between "Standard" War and this Program

War is typically played with a standard 52-card deck between two players. The requirements given for this program allowed for the deck to be configured by number of suits and ranks, and allows for 1 or more players. This means that some mechanisms needed to be invented in order to handle non-standard games.

Losing Conditions

There are several variations on how players lose the game. The approach I took was to have players who run out of cards be unable to gain any more cards for the rest of the game, effectively cutting them out. Whoever is left with the entire deck of cards wins.

Suits

Suits are not regarded for scoring in War. They affect the game through the probability of players playing the same rank of card, thus causing wars to start. Want more wars to happen? Increase the number of suits and decrease the number of ranks in your deck.

Ranks

In War, ranks are ordered as such: A K Q J 10 9 8 7 6 5 4 3 2. Since the number of ranks in the deck used for War.JS is configurable as a number, cards are considered only by a "converted, numerical rank", and so do not have non-numerical names or values.

New Mechanisms

Larger Scale Wars

One of the largest gameplay impacts of having multiple players in War was resolving wars. If a war starts between 8 players, the war will continue going until only one player is left, and they will win all of the played cards in the war.

Tie Resolution

In standard War, cards flow between two players who take part in all parts of the game, until one player has run out of cards. It is impossible for players to tie in a way which cannot be resolved by starting a war.

In War.JS, some players may enter a battle while others wait for the battle to complete. This can give rise to a situation where two players enter a battle with not enough cards to actually complete the battle, and so they will tie. In another way, take a game situation such as this:

Starting turn

Player 1: 20 cards
Player 2: 2 cards
Player 3: 2 cards
Player 4: 18 cards

Played Cards

Player 1: Rank 1
Player 2: Rank 7
Player 3: Rank 7
Player 4: Rank 2

Move to War

Players 2 and 3 have tied, but each only have one card left. Players 1 and 4 are still in the game, but lost this round and so have to wait for players 2 and 3 to carry out their war.

Since the steps of war are:

  1. Put a card in the prize pool (face-down stack)
  2. Play a card face-up

This means that both players 2 and 3 are able to put their last cards in the prize pool, but they cannot play a card face-up.

Resolution

In order to break the tie, I wrote in a simple mechanism which will select a winner at random from the war participants. In such a case, one player will be out of the game, while the winner will have won their cards, allowing the game to continue.

warjs's People

Contributors

turnqujo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.