Skip to content

Commit

Permalink
Merge branch 'release/v0.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
kobalab committed Nov 13, 2021
2 parents c90fa8a + 908dc1e commit 08a3468
Show file tree
Hide file tree
Showing 11 changed files with 3,191 additions and 144 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### v0.0.5 / 2021-11-13

- Majiang.Player を追加
- 脆弱性警告に対応
- mocha 8.4.0 → 9.1.3
- ansi-regex 5.0.0 → 5.0.1
- browserslist 4.16.3 → 4.17.6

### v0.0.4 / 2021-05-23

- Majiang.Board を追加
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const Majiang = require('@kobalab/majiang-core');
| ``Majiang.Shoupai`` | 手牌を表現するクラス |
| ``Majiang.Shan`` | 牌山を表現するクラス |
| ``Majiang.He`` | 捨て牌を表現するクラス |
| ``Majiang.Board`` | 卓に関する情報を表現するクラス |
| ``Majiang.Util`` | シャンテン数計算、和了点計算ルーチン |
| ``Majiang.Game`` | 局進行を実現するクラス |
| ``Majiang.Board`` | 卓に関する情報を表現するクラス |
| ``Majiang.Player`` | 対局者を実現する基底クラス |

[API仕様](https://github.com/kobalab/majiang-core/wiki)
- [API仕様](https://github.com/kobalab/majiang-core/wiki)

## ライセンス
[MIT](https://github.com/kobalab/majiang-core/blob/master/LICENSE)
Expand Down
6 changes: 5 additions & 1 deletion lib/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Shan {

module.exports = class Board {

constructor(kaiju = {}) {
constructor(kaiju) {

this.title = kaiju.title;
this.player = kaiju.player;
Expand All @@ -41,6 +41,10 @@ module.exports = class Board {
this._fenpei;
}

menfeng(id) {
return (id + 4 - this.qijia + 4 - this.jushu) % 4;
}

qipai(qipai) {
this.zhuangfeng = qipai.zhuangfeng;
this.jushu = qipai.jushu;
Expand Down
20 changes: 15 additions & 5 deletions lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const Majiang = {
Shoupai: require('./shoupai'),
Shan: require('./shan'),
He: require('./he'),
Board: require('./board'),
Util: Object.assign(require('./xiangting'),
require('./hule'))
};
Expand All @@ -21,10 +20,20 @@ module.exports = class Game {
this._callback = callback || (()=>{});
this._rule = rule || Majiang.rule();

this._model = new Majiang.Board();
this._model.title = title || '電脳麻将\n' + new Date().toLocaleString();
this._model.player = ['私','下家','対面','上家'];
this._model.defen = [0,0,0,0].map(x=>this._rule['配給原点']);
this._model = {
title: title || '電脳麻将\n' + new Date().toLocaleString(),
player: ['私','下家','対面','上家'],
qijia: 0,
zhuangfeng: 0,
jushu: 0,
changbang: 0,
lizhibang: 0,
defen: [0,0,0,0].map(x=>this._rule['配給原点']),
shan: null,
shoupai: [],
he: [],
player_id: [ 0, 1, 2, 3 ]
};

this._view;

Expand Down Expand Up @@ -173,6 +182,7 @@ module.exports = class Game {
kaiju: {
id: id,
rule: this._rule,
title: this._paipu.title,
player: this._paipu.player,
qijia: this._paipu.qijia
}
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
He: require('./he'),
Board: require('./board'),
Game: require('./game'),
Player: require('./player'),
Util: Object.assign(require('./xiangting'),
require('./hule'))
}
126 changes: 126 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Majiang.Player
*/
"use strict";

const Majiang = {
Shoupai: require('./shoupai'),
He: require('./he'),
Game: require('./game'),
Board: require('./board'),
Util: Object.assign(require('./xiangting'),
require('./hule'))
};

module.exports = class Player {

action(msg, callback) {

this._callback = callback;

if (msg.kaiju) this.kaiju (msg.kaiju);
else if (msg.qipai) this.qipai (msg.qipai);
else if (msg.zimo) this.zimo (msg.zimo);
else if (msg.dapai) this.dapai (msg.dapai);
else if (msg.fulou) this.fulou (msg.fulou);
else if (msg.gang) this.gang (msg.gang);
else if (msg.gangzimo) this.zimo (msg.gangzimo, true)
else if (msg.kaigang) this.kaigang(msg.kaigang);
else if (msg.hule) this.hule (msg.hule);
else if (msg.pingju) this.pingju (msg.pingju);
else if (msg.jieju) this.jieju (msg.jieju);
}

get shoupai() { return this._model.shoupai[this._menfeng] }
get he() { return this._model.he[this._menfeng] }
get shan() { return this._model.shan }
get tingpai() {
return Majiang.Util.xiangting(this.shoupai) == 0
&& Majiang.Util.tingpai(this.shoupai)
|| [];
}

kaiju(kaiju) {
this._id = kaiju.id;
this._rule = kaiju.rule;
this._model = new Majiang.Board(kaiju);
}
qipai(qipai) {
this._model.qipai(qipai);
this._menfeng = this._model.menfeng(this._id);
this._diyizimo = true;
this._n_gang = 0;
this._neng_rong = true;
}
zimo(zimo, gangzimo) {
this._model.zimo(zimo);
if (gangzimo) this._n_gang++;
}
dapai(dapai) {
this._model.dapai(dapai);

if (dapai.l == this._menfeng) {
this._diyizimo = false;
if (! this.shoupai.lizhi) this._neng_rong = true;
if (this.tingpai.find(p=> this.he.find(p))) this._neng_rong = false;
}
else {
if (this.tingpai.find(p=> p == dapai.p)) this._neng_rong = false;
}
}
fulou(fulou) {
this._model.fulou(fulou);
this._diyizimo = false;
}
gang(gang) {
this._model.gang(gang);
this._diyizimo = false;
if (gang.l != this._menfeng && ! gang.m.match(/^[mpsz]\d{4}$/)) {
let s = gang.m[0], n = +gang.m.substr(-1)||5;
if (this.tingpai.find(p=> p == s+n)) this._neng_rong = false;
}
}
kaigang(kaigang) {
this._model.kaigang(kaigang);
}
hule(hule) {
this._model.hule(hule);
}
pingju(pingju) {
this._model.pingju(pingju);
}
jieju(paipu) {
this._paipu = paipu;
}

get_dapai(shoupai) {
return Majiang.Game.get_dapai(this._rule, shoupai);
}
get_chi_mianzi(shoupai, p) {
return Majiang.Game.get_chi_mianzi(this._rule, shoupai, p,
this.shan.paishu);
}
get_peng_mianzi(shoupai, p) {
return Majiang.Game.get_peng_mianzi(this._rule, shoupai, p,
this.shan.paishu);
}
get_gang_mianzi(shoupai, p) {
return Majiang.Game.get_gang_mianzi(this._rule, shoupai, p,
this.shan.paishu, this._n_gang);
}
allow_lizhi(shoupai, p) {
return Majiang.Game.allow_lizhi(this._rule, shoupai, p,
this.shan.paishu,
this._model.defen[this._id]);
}
allow_hule(shoupai, p, hupai) {
hupai = hupai || shoupai.lizhi || this.shan.paishu == 0;
return Majiang.Game.allow_hule(this._rule, shoupai, p,
this._model.zhuangfeng, this._menfeng,
hupai, this._neng_rong);
}
allow_pingju(shoupai) {
return Majiang.Game.allow_pingju(this._rule, shoupai,
this._diyizimo);
}
}
Loading

0 comments on commit 08a3468

Please sign in to comment.