1.1.4 • Published 9 years ago

skiano.president v1.1.4

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

President

An implementation of the cardgame President.

Installation

$ npm install skiano.president

The Rules

This describes the rules as implemented, ignoring other variations

  • Setup

    • Between 3 and 8 players
    • All cards are dealt to players (as evenly as possible)
    • Players can only see their own hand
    • Whoever has the 4 of clubs begins by placing it on the table (automatic)
    • Gameplay rotates through the players (beginning clockwise)
  • Goals

    • Players are trying to get rid of all their cards
    • Players exit the game when the run out of cards
    • The last player holding cards looses
  • Rules

    • You can play a single card or multiples if they are all the same numeric value
    • You must always play an equal or higher value than the preivious play
    • Value follows this heirarchy
      • Ace is high
      • Higher numbers are more valuable: 4 > 3 and 4,4 > 3,3
      • Doubles are higher than singles, tripples higher than doubles: 4,4,4,4 > 9,9 > 13
    • If you play the same value as the previos player, the next player is skipped
    • No matter what, you can always play a 2 or 3
    • Playing a 2 resets the table to the lowest value
    • Playing a 3 reverses the direction of gameplay
    • If you cannot play a higher card you must pass
    • If all the players pass (full circle) the table is cleared.
    • When the table is cleared the following player may play anything they have

The interface

Running a single game

president is a function that takes players creators, runs them to create players, and returns the result of one game.

var president = require('skiano.president');
var createPlayer = require(/* your player creator */);
var results = president(createPlayer, createPlayer, createPlayer);
  • results {object} the result of a single game. It has the following properties:
    • winner {string} The id of the winning player
    • rank {list} A list of player ids sorted from winner to loser
    • events {list} The complete history of the game

Creating a Player

To play the game, you create a function that returns a player function. The player function will be called for each game event. When it is your turn you may return cards from your hand. (more on this below)

function createPlayer(setName) {
  setName('myStrategy')

  return function player(isMyPlay, myView) {
    if (isMyPlay) {
    } else {
    }
  }
}
  • setName {function} (optional) allows you to set a custom name prefix for your player

  • isMyPlay {boolean} lets you know if you need to play

  • myView {object} a snapshot of the game with the following properties:

    • hand {list} The cards you currently hold
    • players {number} The number of players still in the game (including you)
    • table {array} The card(s) on the table. There are times when the array is empty
    • getValidPlays {function} returns all valid plays for your current hand

Note: myView does not expose the history of the game to you. So if you are interested in using previous plays in your strategy you must collect the data you want within createPlayer()

The Deck

Cards are represented as strings. Face cards are represented by their numerical value. Your hand is a list of card strings. For Example:

var yourHand = ['4h','11d','2s','14c'];

Represents the following:

  • Four of hearts
  • Jack of Diamonds
  • Two of Spades
  • Ace of clubs
1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago