GithubHelp home page GithubHelp logo

big2-util's Introduction

big2-util

A utility library for the game Big2 (鋤大Dee)

This library provides methods for validating moves between plays and some other useful helper functions.

Install

# Yarn
yarn add big2-util

# NPM
npm install --save big2-util

Usage

import { Big2Engine, Card } from 'big2-util';

// Create Card object using Card(number, suit)
const royalFlush = [
  Card(1, 1),
  Card(2, 1),
  Card(3, 1),
  Card(4, 1),
  Card(5, 1),
];

const regularFlush = [
  Card(1, 1),
  Card(3, 1),
  Card(5, 1),
  Card(7, 1),
  Card(9, 1),
];

// Compare 2 plays with Big2Engine.validateMove(previousPlay, currentPlay)
const isValid = Big2Engine.validateMove(royalFlush, regularFlush);
// false, because Royal Flush beats Regular Flush!

API

Card parameters

Name Type Description
number number The card's number, where 1 = A, 11 = J, 12 = Q and 13 = K
suit number The card's suit, where 1 = Diamond, 2 = Club, 3 = Heart and 4 = Spade

Big2Engine

Method Description
isSingle(cards: Card[]) Check if player played a single card.
isPair(cards: Card[]) Check if player played a valid pair.
isThreeOfAKind(cards: Card[]) Check if player played a valid three of a kind.
isThreeOfAKind(cards: Card[]) Check if player played a valid three of a kind.
isStraight(cards: Card[]) Check if player played a valid straight.
isFlush(cards: Card[]) Check if player played a valid flush.
isFullHouse(cards: Card[]) Check if player played a valid full house.
isFourOfAKind(cards: Card[]) Check if player played a valid four of a kind. (4 cards with same number plus any other card)
isRoyalFlush(cards: Card[]) Check if player played a valid royal flush.
isPass(cards: Card[]) Check if player have passed his/her turn.
isCardMorePowerful(card1: Card, card2: Card) Check if card 1 is more powerful than card 2.
validateCombination(cards: Card[]) Check if player played a valid combination.
validateMove(lastPlayedCards: Card[], cards: Card[]) Compare two sets of cards and check if the move is valid.

License

MIT © Colloque Tsui

big2-util's People

Contributors

colloquet avatar

Watchers

 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.