This commit is contained in:
syuilo
2024-02-03 18:02:00 +09:00
parent 586a458c7a
commit 00bf57d243
5 changed files with 203 additions and 72 deletions

View File

@@ -310,34 +310,21 @@ export class MasterGameEngine {
let canPonHouse: House | null = null;
switch (house) {
case 'e':
canPonHouse = this.canPon('s', tile) ? 's' : this.canPon('w', tile) ? 'w' : this.canPon('n', tile) ? 'n' : null;
break;
case 's':
canPonHouse = this.canPon('e', tile) ? 'e' : this.canPon('w', tile) ? 'w' : this.canPon('n', tile) ? 'n' : null;
break;
case 'w':
canPonHouse = this.canPon('e', tile) ? 'e' : this.canPon('s', tile) ? 's' : this.canPon('n', tile) ? 'n' : null;
break;
case 'n':
canPonHouse = this.canPon('e', tile) ? 'e' : this.canPon('s', tile) ? 's' : this.canPon('w', tile) ? 'w' : null;
break;
case 'e': canPonHouse = this.canPon('s', tile) ? 's' : this.canPon('w', tile) ? 'w' : this.canPon('n', tile) ? 'n' : null; break;
case 's': canPonHouse = this.canPon('e', tile) ? 'e' : this.canPon('w', tile) ? 'w' : this.canPon('n', tile) ? 'n' : null; break;
case 'w': canPonHouse = this.canPon('e', tile) ? 'e' : this.canPon('s', tile) ? 's' : this.canPon('n', tile) ? 'n' : null; break;
case 'n': canPonHouse = this.canPon('e', tile) ? 'e' : this.canPon('s', tile) ? 's' : this.canPon('w', tile) ? 'w' : null; break;
}
const canCiiHouse: House | null = null;
// TODO
//let canCii: boolean = false;
//if (house === 'e') {
// canCii = this.state.sHandTiles...
//} else if (house === 's') {
// canCii = this.state.wHandTiles...
//} else if (house === 'w') {
// canCii = this.state.nHandTiles...
//} else if (house === 'n') {
// canCii = this.state.eHandTiles...
//}
let canCiiHouse: House | null = null;
switch (house) {
case 'e': canCiiHouse = this.canCii('s', house, tile) ? 's' : this.canCii('w', house, tile) ? 'w' : this.canCii('n', house, tile) ? 'n' : null; break;
case 's': canCiiHouse = this.canCii('e', house, tile) ? 'e' : this.canCii('w', house, tile) ? 'w' : this.canCii('n', house, tile) ? 'n' : null; break;
case 'w': canCiiHouse = this.canCii('e', house, tile) ? 'e' : this.canCii('s', house, tile) ? 's' : this.canCii('n', house, tile) ? 'n' : null; break;
case 'n': canCiiHouse = this.canCii('e', house, tile) ? 'e' : this.canCii('s', house, tile) ? 's' : this.canCii('w', house, tile) ? 'w' : null; break;
}
if (canRonHouses.length > 0 || canPonHouse != null) {
if (canRonHouses.length > 0 || canPonHouse != null || canCiiHouse != null) {
if (canRonHouses.length > 0) {
this.state.ronAsking = {
callee: house,
@@ -447,9 +434,9 @@ export class MasterGameEngine {
};
}
public commit_resolveCallAndRonInterruption(answers: {
public commit_resolveCallingInterruption(answers: {
pon: boolean;
cii: false | [Tile, Tile];
cii: false | [Tile, Tile, Tile];
kan: boolean;
ron: House[];
}) {
@@ -484,6 +471,7 @@ export class MasterGameEngine {
const rinsyan = this.tsumo();
this.state.turn = kan.caller;
return {
type: 'kanned' as const,
caller: kan.caller,
@@ -499,6 +487,7 @@ export class MasterGameEngine {
this.state.huros[pon.caller].push({ type: 'pon', tile, from: pon.callee });
this.state.turn = pon.caller;
return {
type: 'ponned' as const,
caller: pon.caller,
@@ -513,6 +502,7 @@ export class MasterGameEngine {
this.state.huros[cii.caller].push({ type: 'cii', tiles: [tile, answers.cii[0], answers.cii[1]], from: cii.callee });
this.state.turn = cii.caller;
return {
type: 'ciied' as const,
caller: cii.caller,

View File

@@ -55,13 +55,10 @@ export type PlayerState = {
};
latestDahaiedTile: Tile | null;
turn: House | null;
canPonSource: House | null;
canCiiSource: House | null;
canKanSource: House | null;
canRonSource: House | null;
canCiiTo: House | null;
canKanTo: House | null;
canRonTo: House | null;
canPon: { callee: House } | null;
canCii: { callee: House } | null;
canKan: { callee: House } | null; // = 大明槓
canRon: { callee: House } | null;
};
export type KyokuResult = {
@@ -138,11 +135,16 @@ export class PlayerGameEngine {
} else {
const canRon = Common.getHoraSets(this.myHandTiles.concat(tile)).length > 0;
const canPon = this.myHandTiles.filter(t => t === tile).length === 2;
const canKan = this.myHandTiles.filter(t => t === tile).length === 3;
const canCii = house === Common.prevHouse(this.myHouse) &&
Common.SHUNTU_PATTERNS.some(pattern =>
pattern.includes(tile) &&
pattern.filter(t => this.myHandTiles.includes(t)).length >= 2);
// TODO: canCii
if (canRon) this.state.canRonSource = house;
if (canPon) this.state.canPonSource = house;
if (canRon) this.state.canRon = { callee: house };
if (canPon) this.state.canPon = { callee: house };
if (canKan) this.state.canKan = { callee: house };
if (canCii) this.state.canCii = { callee: house };
}
}
@@ -193,7 +195,7 @@ export class PlayerGameEngine {
}): Record<House, KyokuResult | null> {
console.log('commit_ronHora', this.state.turn, callers, callee);
this.state.canRonSource = null;
this.state.canRon = null;
const resultMap: Record<House, KyokuResult> = {
e: { yakus: [], doraCount: 0, pointDeltas: { e: 0, s: 0, w: 0, n: 0 } },
@@ -236,7 +238,7 @@ export class PlayerGameEngine {
* @param callee 牌を捨てた人
*/
public commit_pon(caller: House, callee: House) {
this.state.canPonSource = null;
this.state.canPon = null;
const lastTile = this.state.hoTiles[callee].pop();
if (lastTile == null) throw new PlayerGameEngine.InvalidOperationError();
@@ -253,8 +255,10 @@ export class PlayerGameEngine {
}
public commit_nop() {
this.state.canRonSource = null;
this.state.canPonSource = null;
this.state.canRon = null;
this.state.canPon = null;
this.state.canKan = null;
this.state.canCii = null;
}
public get isMenzen(): boolean {
@@ -270,4 +274,22 @@ export class PlayerGameEngine {
if (Common.getTilesForRiichi(this.myHandTiles).length === 0) return false;
return true;
}
public canAnkan(): boolean {
if (this.state.turn !== this.myHouse) return false;
return this.myHandTiles.filter(t => this.myHandTiles.filter(tt => tt === t).length >= 4).length > 0;
}
public canKakan(): boolean {
if (this.state.turn !== this.myHouse) return false;
return this.state.huros[this.myHouse].filter(h => h.type === 'pon' && this.myHandTiles.includes(h.tile)).length > 0;
}
public getAnkanableTiles(): Tile[] {
return this.myHandTiles.filter(t => this.myHandTiles.filter(tt => tt === t).length >= 4);
}
public getKakanableTiles(): Tile[] {
return this.state.huros[this.myHouse].filter(h => h.type === 'pon' && this.myHandTiles.includes(h.tile)).map(h => h.tile);
}
}