Skip to content

Commit

Permalink
Merge branch 'release/v1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kobalab committed Feb 25, 2024
2 parents 0ea2d0a + 7540097 commit 171ec32
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v1.2.1 / 2024-02-25

- String の非推奨のメソッドを変更: substr() → slice()

## v1.2.0 / 2024-02-03

- #5 麻雀サーバーに関する処理を追加
Expand Down
2 changes: 1 addition & 1 deletion lib/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = class Board {
this.lunban = dapai.l;
this.shoupai[dapai.l].dapai(dapai.p, false);
this.he[dapai.l].dapai(dapai.p);
this._lizhi = dapai.p.substr(-1) == '*';
this._lizhi = dapai.p.slice(-1) == '*';
}

fulou(fulou) {
Expand Down
18 changes: 9 additions & 9 deletions lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = class Game {
}

say(name, l) {
if (this._view) this._view.say(name, l);
if (this._view) this._view.say(name, l);
}

stop(callback = ()=>{}) {
Expand Down Expand Up @@ -298,12 +298,12 @@ module.exports = class Game {

if (this._diyizimo) {
if (! dapai.match(/^z[1234]/)) this._fengpai = false;
if (this._dapai && this._dapai.substr(0,2) != dapai.substr(0,2))
if (this._dapai && this._dapai.slice(0,2) != dapai.slice(0,2))
this._fengpai = false;
}
else this._fengpai = false;

if (dapai.substr(-1) == '*') {
if (dapai.slice(-1) == '*') {
this._lizhi[model.lunban] = this._diyizimo ? 2 : 1;
this._yifa[model.lunban] = this._rule['一発あり'];
}
Expand Down Expand Up @@ -448,8 +448,8 @@ module.exports = class Game {
let menfeng = this._hule.length ? this._hule.shift() : model.lunban;
let rongpai = menfeng == model.lunban ? null
: (this._hule_option == 'qianggang'
? this._gang[0] + this._gang.substr(-1)
: this._dapai.substr(0,2)
? this._gang[0] + this._gang.slice(-1)
: this._dapai.slice(0,2)
) + '_+=-'[(4 + model.lunban - menfeng) % 4];
let shoupai = model.shoupai[menfeng].clone();
let fubaopai = shoupai.lizhi ? model.shan.fubaopai : null;
Expand Down Expand Up @@ -728,7 +728,7 @@ module.exports = class Game {
else if (reply.dapai) {
let dapai = reply.dapai.replace(/\*$/,'');
if (this.get_dapai().find(p => p == dapai)) {
if (reply.dapai.substr(-1) == '*' && this.allow_lizhi(dapai)) {
if (reply.dapai.slice(-1) == '*' && this.allow_lizhi(dapai)) {
this.say('lizhi', model.lunban);
return this.delay(()=>this.dapai(reply.dapai));
}
Expand Down Expand Up @@ -770,7 +770,7 @@ module.exports = class Game {
return this.delay(()=>this.hule());
}

if (this._dapai.substr(-1) == '*') {
if (this._dapai.slice(-1) == '*') {
model.defen[model.player_id[model.lunban]] -= 1000;
model.lizhibang++;

Expand Down Expand Up @@ -872,7 +872,7 @@ module.exports = class Game {
this._hule.push(l);
}
else {
let p = this._gang[0] + this._gang.substr(-1);
let p = this._gang[0] + this._gang.slice(-1);
let shoupai = model.shoupai[l].clone().zimo(p);
if (Majiang.Util.xiangting(shoupai) == -1)
this._neng_rong[l] = false;
Expand Down Expand Up @@ -969,7 +969,7 @@ module.exports = class Game {
}
else {
let p = (this._status == 'gang'
? this._gang[0] + this._gang.substr(-1)
? this._gang[0] + this._gang.slice(-1)
: this._dapai
) + '_+=-'[(4 + model.lunban - l) % 4];
let hupai = model.shoupai[l].lizhi
Expand Down
2 changes: 1 addition & 1 deletion lib/he.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = class He {
if (! Majiang.Shoupai.valid_mianzi(m)) throw new Error(m);
let p = m[0] + m.match(/\d(?=[\+\=\-])/), d = m.match(/[\+\=\-]/);
if (! d) throw new Error(m);
if (this._pai[this._pai.length - 1].substr(0,2) != p)
if (this._pai[this._pai.length - 1].slice(0,2) != p)
throw new Error(m);
this._pai[this._pai.length - 1] += d;
return this;
Expand Down
10 changes: 5 additions & 5 deletions lib/hule.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function hule_mianzi_qidui(shoupai, hulepai) {
for (let n = 1; n < bingpai.length; n++) {
if (bingpai[n] == 0) continue;
if (bingpai[n] == 2) {
let m = (s+n == hulepai.substr(0,2))
let m = (s+n == hulepai.slice(0,2))
? s+n+n + hulepai[2] + '!'
: s+n+n;
mianzi.push(m);
Expand All @@ -140,14 +140,14 @@ function hule_mianzi_guoshi(shoupai, hulepai) {
let nn = (s == 'z') ? [1,2,3,4,5,6,7] :[1,9];
for (let n of nn) {
if (bingpai[n] == 2) {
let m = (s+n == hulepai.substr(0,2))
let m = (s+n == hulepai.slice(0,2))
? s+n+n + hulepai[2] + '!'
: s+n+n;
mianzi.unshift(m);
n_duizi++;
}
else if (bingpai[n] == 1) {
let m = (s+n == hulepai.substr(0,2))
let m = (s+n == hulepai.slice(0,2))
? s+n + hulepai[2] + '!'
: s+n;
mianzi.push(m);
Expand Down Expand Up @@ -177,7 +177,7 @@ function hule_mianzi_jiulian(shoupai, hulepai) {
}
}
if (mianzi.length != 14) return [];
mianzi += hulepai.substr(1) + '!';
mianzi += hulepai.slice(1) + '!';

return [ [mianzi] ];
}
Expand Down Expand Up @@ -684,7 +684,7 @@ function hule(shoupai, rongpai, param) {

if (rongpai) {
if (! rongpai.match(/[\+\=\-]$/)) throw new Error(rongpai);
rongpai = rongpai.substr(0,2) + rongpai.substr(-1);
rongpai = rongpai.slice(0,2) + rongpai.slice(-1);
}

let max;
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @kobalab/majiang-core v1.2.0
* @kobalab/majiang-core v1.2.1
*
* Copyright(C) 2021 Satoshi Kobayashi
* Released under the MIT license
Expand Down
2 changes: 1 addition & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = class Player {

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;
let s = gang.m[0], n = +gang.m.slice(-1)||5;
if (this.hulepai.find(p=> p == s+n)) this._neng_rong = false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/shoupai.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = class Shoupai {
}

shoupai._zimo = shoupai._zimo || zimo || null;
shoupai._lizhi = bingpai.substr(-1) == '*';
shoupai._lizhi = bingpai.slice(-1) == '*';

return shoupai;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ module.exports = class Shoupai {
let s = p[0], n = +p[1];
this.decrease(s, n);
this._zimo = null;
if (p.substr(-1) == '*') this._lizhi = true;
if (p.slice(-1) == '*') this._lizhi = true;
return this;
}

Expand Down Expand Up @@ -224,11 +224,11 @@ module.exports = class Shoupai {
this._fulou.push(m);
}
else if (m.match(/\d{3}[\+\=\-]\d$/)) {
let m1 = m.substr(0,5);
let m1 = m.slice(0,5);
let i = this._fulou.findIndex(m2 => m1 == m2);
if (i < 0) throw new Error([this, m]);
this._fulou[i] = m;
this.decrease(s, m.substr(-1));
this.decrease(s, m.slice(-1));
}
else throw new Error([this, m]);
this._zimo = null;
Expand Down Expand Up @@ -381,7 +381,7 @@ module.exports = class Shoupai {
else {
if (this._lizhi) continue;
for (let m of this._fulou) {
if (m.replace(/0/g,'5').substr(0,4) == s+n+n+n) {
if (m.replace(/0/g,'5').slice(0,4) == s+n+n+n) {
if (n == 5 && bingpai[0] > 0) mianzi.push(m+0);
else mianzi.push(m+n);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kobalab/majiang-core",
"version": "1.2.0",
"version": "1.2.1",
"description": "麻雀基本ライブラリ",
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 171ec32

Please sign in to comment.