fixe issue in the creation pf a hand

This commit is contained in:
Didictateur 2025-04-04 10:02:11 +02:00
parent 201385d7e8
commit 2a1267fefb
13 changed files with 342 additions and 18 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

156
build/test.js Normal file

File diff suppressed because one or more lines are too long

126
build/test_hand.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -162,7 +162,7 @@
}
//tests
loadScript('test_yakus.js', false);
loadScript('test.js', false);
//script initial
loadScript('dp5.js');

View file

@ -7,8 +7,8 @@ export class Hand {
public constructor(stiles: string = "") {
this.tiles = [];
for (let i = 0; 2 * i + 1 < stiles.length; i++) {
let ss = stiles.substring(2*i, 2*(i+1));
for (let i = 0; i < stiles.length - 1; i++) {
let ss = stiles.substring(i, i+2);
if (ss[0] === "m") {
this.tiles.push(new Tile(1, Number(ss[1]), false));
} else if (ss[0] === "p") {
@ -139,11 +139,11 @@ export class Hand {
this.tiles.push(t1);
this.tiles.sort();
return undefined;
} else {
return [];
}
return undefined
}
public drawHand (

2
src/tests/test.ts Normal file
View file

@ -0,0 +1,2 @@
import "./test_hand"
import "./test_yakus"

20
src/tests/test_hand.ts Normal file
View file

@ -0,0 +1,20 @@
import { Hand } from "../hand"
import { assert } from "./assert";
let h0 = new Hand("s1s1");
let h1 = new Hand("m1m2m3");
let h2 = new Hand("m2m2m2 p1p1");
let h3 = new Hand("m1m2m3 p1p2p3 s1s2s3 m9m9m9 p9p9");
let h4 = new Hand("m2m2m2 p1p1p1");
let count = 0;
let total = 0;
count += assert(h0.toGroup()?.length === 1, "s11 has 1 group");
count += assert(h1.toGroup()?.length === 1, "m123 has 1 group");
count += assert(h2.toGroup()?.length === 2, "m222 p11 has 2 groups");
count == assert(h3.toGroup()?.length === 5, "m123 p123 s123 m999 p99 has 5 groups");
count += assert(h4.toGroup()?.length === 2, "m222 p111 has 2 groups");
total += 4;
console.log("Succès: " + count.toString() + "/" + total.toString());

View file

@ -7,11 +7,11 @@ let total = 0;
let h1 = new Hand("m1m2m3 m4m5m6 m7m8m9 p1p2p3 p5p5");
let h2 = new Hand("m1m1m1 m4m4m4 m7m7m7 p1p1p1 p5p5");
let h3 = new Hand("m1m1m1p9p9p9s1s1s1w2w2w2d1d1");
let h3 = new Hand("m1m1m1 p9p9p9 s1s1s1 w2w2w2 d1d1");
let h4 = new Hand("m2m3m4 p3p3p3 p4p5p6 s4s4 s6s7s8");
let h5 = new Hand("m1m2m3m1m2m3p7p8p9p7p8p9w3w3");
let h5 = new Hand("m1m2m3 m1m2m3 p7p8p9 p7p8p9 w3w3");
let h6 = new Hand("m1m2m3 m1m2m3 p6p7p8 p7p8p9 w3w3");
let h7 = new Hand("m1m2m3 p1p2p3 s1s2s3 m9m9m9 p9p9");
let h7 = new Hand("m1m2m3 p1p2p3 s1s2s3 m7m8m9 p9p9");
// lipeikou
count += assert(yakus.lipekou(h5, [], 0) === 1, "m123 m123 p789 p789 w33 is Lipeikou");
@ -29,7 +29,7 @@ count += assert(yakus.pinfu(h2, [], 0) === 0, "m111 m444 m777 p111 p55 is not Pi
total += 2;
// sanshoku doujun
count += assert(yakus.sanshokuDoujun(h7, [], 0) === 2, "m123 p123 s123 m999 p99 is Shanshokou Doujun");
count += assert(yakus.sanshokuDoujun(h7, [], 0) === 2, "m123 p123 s123 m789 p99 is Shanshokou Doujun");
count += assert(yakus.sanshokuDoujun(h2, [], 0) === 0, "m111 m444 m777 p111 p55 is not Shanshokou Doujun");
total += 2;

View file

@ -126,7 +126,7 @@ pinfu: function(
return 0;
},
sanshokuDoujun: function( // TODO
sanshokuDoujun: function(
/**
* triple suite
* 1/2
@ -136,7 +136,7 @@ sanshokuDoujun: function( // TODO
wind: number
): number {
let h = hand.toGroup();
let gr;
let gr = [];
if (h !== undefined) {
gr = groups.concat(h);
} else {
@ -161,7 +161,27 @@ sanshokuDoujun: function( // TODO
}
return 0;
} else {// il y a un intrus
return 1
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;
}
},