npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

doudizhu

v1.1.1

Published

瞎猫的JavaScript 斗地主算法封装

Readme

doudizhu

瞎猫的JavaScript 斗地主算法封装

起步 Start

var doudizhu = require('doudizhu')

文档 Doc

洗牌

记录并返回1副乱序id的扑克牌数组

doudizhu.getShuffleCards()
/*
[ 15,  43,  49,  21,  51,  40,  23,  14,  25,  5,  4,  44,  3,  32,  53,  11,  41,  27,  7,  18,  38,  28,  8,  31,  17,  36,  42,  26,  47,  45,  22,  12,  34,  16,  2,  9,  1,  35,  52,  10,  20,  30,  29,  46,  13,  0,  6,  39,  48,  24,  19,  37,  33,  50 ]
*/

查看当前洗完的扑克牌

返回上次洗牌完成后的1副扑克牌数组(未洗过牌则为空数组)

doudizhu.getCards()
/*
[ 15,  43,  49,  21,  51,  40,  23,  14,  25,  5,  4,  44,  3,  32,  53,  11,  41,  27,  7,  18,  38,  28,  8,  31,  17,  36,  42,  26,  47,  45,  22,  12,  34,  16,  2,  9,  1,  35,  52,  10,  20,  30,  29,  46,  13,  0,  6,  39,  48,  24,  19,  37,  33,  50 ]
*/

发牌

返回1个对象记录4组牌:3组17张的随机牌、1组3张的地主牌

doudizhu.dealCards()
/*
{
    player1: [ 15, 21, 23, 5, 3, 11, 7, 28, 17, 26, 22, 16, 1, 10, 29, 0, 48 ],
    player2: [ 43, 51, 14, 4, 32, 41, 18, 8, 36, 47, 12, 2, 35, 20, 46, 6, 24 ],
    player3: [ 49, 40, 25, 44, 53, 27, 38, 31, 42, 45, 34, 9, 52, 30, 13, 39, 19 ],
    leaveCards: [ 37, 33, 50 ]
}
*/

获取扑克牌组的类型及权重信息

接收1个扑克牌id数组(可乱序),返回1个牌信息对象 如果出牌不合规则则返回 false

doudizhu.getCardType([8,12,16,20,24])
/*
{
    cardType: 'DAN_SHUN_ZI', // 牌型别名
    cardTypeWeight: 1, //牌类型权重
    groupCardsWeight: 1 // 当前扑克牌组权重
}
*/

压牌

接收2个扑克牌id数组(可乱序),返回两个牌的比较结果 若第二组牌可压第一组则返回 true 不可压或者牌不合法则返回 false

doudizhu.beat([8,12,16,20,24], [12,16,20,24,28])
/*
true
*/

默认排序

对给定的数组进行排序,按照从小到大,返回排序后的数组

传入数组元素必须为非负整数,否则返回 false

不限制数组元素大小,不限制数组元素不重复

注意:此排序为直接影响修改原数组

不可直接对当前的整副扑克牌数组对象进行排序,防止造成变量污染,故对此行为进行了异常抛出处理

doudizhu.sort([34, 6, 2, 8, 22])
/*
[ 2, 6, 8, 22, 22, 34 ]
*/

根权重排序

对给定的数组,根据牌权重、花色权重对牌进行排序

一般用于排列玩家手牌排序呈现

传入数组元素应该为小于54的非负整数,不可重复,否则返回false

注意:此排序为直接影响修改原数组

不可直接对当前的整副扑克牌数组对象进行排序,防止造成变量污染,故对此行为进行了异常抛出处理

doudizhu.weightSort([34, 6, 2, 8, 22, 53])
/*
[ 8, 22, 34, 2, 6, 53 ]
*/

牌型 Type

| 牌型 | 别名 | 权重 | 示例 | | -------- | -------- | -------- | -------- | | 单条 | DAN_TIAO | 1 |
| 单顺子 | DAN_SHUN_ZI | 1 | | 王炸 | WANG_ZHA | 3 | | -- | -- | -- | -- | | 对子 | DUI_ZI | 1 |
| 双顺子 | SHUANG_SHUN_ZI | 1 | | -- | -- | -- | -- | | 三条 | SAN_TIAO | 1 | | | 三带一 | SAN_DAI_YI | 1 | | 三带一对 | SAN_DAI_YI_DUI | 1 | | 三顺子 | SAN_SHUN_ZI | 1 | | 飞机带单 | FEI_JI_DAI_DAN | 1 |
| 飞机带对 | FEI_JI_DAI_DUI | 1 | | -- | -- | -- | -- | | 炸弹 | ZHA_DAN | 2 |
| 四带双单 | SI_DAI_SHUANG_DAN | 1 | | 四带双对 | SI_DAI_SHUANG_DUI | 1 |