Coder Social home page Coder Social logo

huujiee / mahjongalogic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nfhorizon/mahjongalogic

0.0 0.0 0.0 47 KB

基于查表法的麻将算法库,支持带癞子听牌算法,且能计算出听的牌的基础番型(mahjong algorithm lib)

License: MIT License

C# 58.55% Rust 41.45%

mahjongalogic's Introduction

MahjongaLogic(mahjong algorithm lib)

基于查表法,开箱即用的麻将算法库,支持带癞子听牌算法,且能计算出听的牌的基础番型。并支持麻将所需的绝大部分计算(AI出牌算法,判胡,判听,算番),在使用上,需要先将牌组转化为库中所用的格式再进行计算,这是为了最大化效能

c#(cs)版本用法

  1. 自建c#工程运行或直接在已有C#项目中包含,unity或.NET都支持
  2. 调用库方法之前,需要初始化查表法所用到的表,为什么库不直接做这个工作呢,是因为生成所需的表较为耗时,如果使用已缓存的表,则可以大大优化初始化速度,因此留给用户来选择,你可以调用MahjongaLogic.Init(MahjongLogic.gen_laizimap(0, 7)) 来进行初始化,或者将生成的表序列化后存到txt中,在下次启动库时从txt中反序列化表
  3. 然后构造一个MahjongaLogic的实例来调用方法(这是为了适配不同的游戏中麻将算法的配置不同的情况)
  4. 现在你就可以自由调用库中的函数了,如下是一段用于测试一副手牌是否是九莲宝灯的测试代码
//测试九莲宝灯
List<int> cards = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 9, 9, 2 };
long[] m = mahjongLogic.cards_to_matrix(cards);

var is_jiulianbaodeng = mahjongLogic.is_jiulianbaodeng(m);
Assert.True(is_jiulianbaodeng);

cards = new() { 0x61, 0x61, 1, 4, 4, 0x15, 0x15, 0x19, 0x19, 0x21, 0x21, 0x27, 0x28, 6 };
m = mahjongLogic.cards_to_matrix(cards);

Assert.False(mahjongLogic.is_qidui(m));

cards = new() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 1, 9, 9 };
m = mahjongLogic.cards_to_matrix(cards);
is_jiulianbaodeng = mahjongLogic.is_jiulianbaodeng(m);
Assert.True(is_jiulianbaodeng);

mahjongalogic's People

Contributors

nfhorizon 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.