display all tests for all yakus and fixe chinroutou

This commit is contained in:
Didictateur 2025-04-12 18:44:02 +02:00
parent 18be98aa2a
commit eb93dec6ba
4 changed files with 149 additions and 43 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -11,10 +11,10 @@ function ord(g: Group): boolean {
function term(g: Group): boolean { function term(g: Group): boolean {
return g.getTiles().every( return g.getTiles().every(
t => { t =>
t.getFamily() < 4 && t.getFamily() < 4 &&
(t.getValue() === 1 || (t.getValue() === 1 ||
t.getValue() === 9)} t.getValue() === 9)
); );
} }
@ -488,13 +488,9 @@ chinroutou: function(
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
): number { ): number {
let h = hand.toGroup(); let gr = groups.concat(hand.toGroup() as NonNullable<Array<Group>>);
if (h === undefined) {
return 0;
}
if ( if (
groups.every(g => term(g)) && gr.every(g => term(g))
h.every(g => term(g))
) { ) {
return 13; return 13;
} }
@ -654,23 +650,70 @@ suuankou: function(
return 0; return 0;
}, },
sanshokuDoukou: function( //TODO /**
/**
* triple brelan * triple brelan
* 2/2 * 2/2
*/ */
sanshokuDoukou: function(
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
): number { ): number {
let h = hand.toGroup();
let gr = [];
if (h !== undefined) {
gr = groups.concat(h);
} else {
gr = groups;
}
gr = gr.filter(g => pon(g) && g.getTiles().length === 3);
gr.sort((g1, g2) => g1.compare(g2))
if (gr.length < 3) { // pas assez de chii
return 0; return 0;
} else if(gr.length === 3) {
let t0 = gr[0].getTiles();
let t1 = gr[1].getTiles();
let t2 = gr[2].getTiles();
if (
t0[0].getValue() === t1[0].getValue() &&
t0[0].getValue() === t2[0].getValue() &&
t0[0].getFamily() !== t1[0].getFamily() &&
t0[0].getFamily() !== t2[0].getFamily() &&
t1[0].getFamily() !== t2[0].getFamily()
) {
return groups.length > 0 ? 1 : 2;
}
return 0;
} else {// il y a un intrus
for (let i = 0; i < 4; i++) {
let index = []
for (let j = 0; j < 4; j++) {
if (j !== i) {
index.push(j);
}
}
let t0 = gr[index[0]].getTiles();
let t1 = gr[index[1]].getTiles();
let t2 = gr[index[2]].getTiles();
if (
t0[0].getValue() === t1[0].getValue() &&
t0[0].getValue() === t2[0].getValue() &&
t0[0].getFamily() !== t1[0].getFamily() &&
t0[0].getFamily() !== t2[0].getFamily() &&
t1[0].getFamily() !== t2[0].getFamily()
) {
return groups.length > 0 ? 1 : 2;
}
}
return 0;
}
}, },
sankantsu: function( //TODO /**
/**
* trois carrés * trois carrés
* 2/2 * 2/2
*/ */
sankantsu: function( //TODO
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
@ -678,11 +721,11 @@ sankantsu: function( //TODO
return 0; return 0;
}, },
suukantsu: function( //TODO /**
/**
* quatre carrés * quatre carrés
* 13/13 * 13/13
*/ */
suukantsu: function( //TODO
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
@ -690,23 +733,49 @@ suukantsu: function( //TODO
return 0; return 0;
}, },
honitsu: function( //TODO /**
/**
* semie pure * semie pure
* 2/3 * 2/3
*/ */
honitsu: function(
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
): number { ): number {
let h = hand.toGroup();
let gr = [];
if (h !== undefined) {
gr = groups.concat(h);
} else {
gr = groups;
}
gr.sort((g1, g2) => g1.compare(g2))
if (gr.length === 0) {
return 0;
}
if (gr[gr.length - 1].getTiles()[0].getFamily() < 4) { // main pure
return 0;
}
let f = gr[0].getTiles()[0].getFamily();
if (f > 3) { // tout honneur
return 0;
}
if (gr.every(
g => {
let ff = g.getTiles()[0].getFamily();
return ff > 3 || f === ff
}
)) {
return groups.length > 0 ? 2 : 3;
}
return 0; return 0;
}, },
chinitsu: function( /**
/**
* main pure * main pure
* 5/6 * 5/6
*/ */
chinitsu: function(
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
@ -722,11 +791,11 @@ chinitsu: function(
return 0; return 0;
}, },
ryuuisou: function( //TODO /**
/**
* main verte * main verte
* 13/13 * 13/13
*/ */
ryuuisou: function( //TODO
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number
@ -737,11 +806,11 @@ ryuuisou: function( //TODO
return 0; return 0;
}, },
chuurenPoutou: function( //TODO /**
/**
* neuf portes * neuf portes
* 0/13 * 0/13
*/ */
chuurenPoutou: function( //TODO
hand: Hand, hand: Hand,
groups: Array<Group>, groups: Array<Group>,
wind: number wind: number

View file

@ -23,7 +23,8 @@ let h15 = new Hand("m1m9m9 p1p9 s1s9 w1w2w3w4 d1d2d3");
let h16 = new Hand("m1m1 m2m2 m3m3 m4m4 m5m5 m6m6 m7m7"); let h16 = new Hand("m1m1 m2m2 m3m3 m4m4 m5m5 m6m6 m7m7");
let h17 = new Hand("m1m1 m2m2 m3m3 m4m4 m5m5 m6m6 m6m6"); let h17 = new Hand("m1m1 m2m2 m3m3 m4m4 m5m5 m6m6 m6m6");
let h18 = new Hand("m1m2m3 m4m4m4 m7m7m7 p1p1p1 p5p5"); let h18 = new Hand("m1m2m3 m4m4m4 m7m7m7 p1p1p1 p5p5");
let h19 = new Hand("m1m2m3 m7m7m7 p1p1p1 p5p5"); let h19 = new Hand("m1m1m1 p1p1p1 s1s1s1 s1s2s3 p5p5");
let h20 = new Hand("m1m1m1 p1p1p1 s1s1 s1s2s3 p5p5p5");
// lipeikou // lipeikou
count += assert(yakus.lipekou(h5, [], 0) === 1, "m123 m123 p789 p789 w33 is Lipeikou"); count += assert(yakus.lipekou(h5, [], 0) === 1, "m123 m123 p789 p789 w33 is Lipeikou");
@ -114,7 +115,7 @@ count += assert(yakus.tsuuiisou(h3, [], 0) === 0, "m111 p999 s111 w222 d11 is no
total += 2; total += 2;
// kokushiMusou // kokushiMusou
count += assert(yakus.kokushiMusou(h15, [], 0) === 13, "m1m9m9 p1p9 s1s9 w1w2w3w4 d1d2d3 is Kokushi Musou"); count += assert(yakus.kokushiMusou(h15, [], 0) === 13, "m199 p19 s19 w1234 d123 is Kokushi Musou");
count += assert(yakus.kokushiMusou(h3, [], 0) === 0, "m111 p999 s111 w222 d11 is not Kokushi Musou"); count += assert(yakus.kokushiMusou(h3, [], 0) === 0, "m111 p999 s111 w222 d11 is not Kokushi Musou");
total += 2; total += 2;
@ -141,5 +142,41 @@ count += assert(yakus.suuankou(h18, [], 0) === 0, "m123 m444 m777 p111 p55 is no
count += assert(yakus.suuankou(h7, [], 0) === 0, "m123 p123 s123 m789 p99 is not Sanankou"); count += assert(yakus.suuankou(h7, [], 0) === 0, "m123 p123 s123 m789 p99 is not Sanankou");
total += 3; total += 3;
// sanshoku doukou
count += assert(yakus.sanshokuDoukou(h19, [], 0) === 2, "m111 p111 s111 s123 p55 is Shanshoku Doukou");
count += assert(yakus.sanshokuDoukou(h20, [], 0) === 0, "m11 p111 s111 s123 p555 is not Shanshoku Doukou");
count += assert(yakus.sanshokuDoukou(h7, [], 0) === 0, "m123 p123 s123 m789 p99 is not Shanshoku Doukou");
total += 3;
// sankantsu
count += assert(false, "Sankantsu not implemented")
total += 1;
// suukantsu
count += assert(false, "suukantsu not implemented");
total += 1;
// honitsu
count += assert(yakus.honitsu(h9, [], 0) === 3, "m123 m123 d111 d222 d33 is Honitsu");
count += assert(yakus.honitsu(h13, [], 0) === 0, "d11 w111 w222 w333 w444 is not Honitsu");
count += assert(yakus.honitsu(h1, [], 0) === 0, "m123 m456 m789 m123 m55 is not Honitsu");
count += assert(yakus.honitsu(h7, [], 0) === 0, "m123 p123 s123 m789 p99 is not Honitsu");
total += 4;
// chinitsu
count += assert(yakus.chinitsu(h1, [], 0) === 6, "m123 m456 m789 m123 m55 is Chinitsu");
count += assert(yakus.chinitsu(h9, [], 0) === 0, "m123 m123 d111 d222 d33 is not Chinitsu");
count += assert(yakus.chinitsu(h13, [], 0) === 0, "d11 w111 w222 w333 w444 is not Chinitsu");
count += assert(yakus.chinitsu(h7, [], 0) === 0, "m123 p123 s123 m789 p99 is not Chinitsu");
total += 4;
// ryuuisou
count += assert(false, "Ryuuisou not implemented")
total += 1;
// chuuren poutou
count += assert(false, "Chuuren Poutou not implemented")
total += 1;
// total // total
console.log("Succès: " + count.toString() + "/" + total.toString()); console.log("Succès: " + count.toString() + "/" + total.toString());