section 7 yakus implemented

This commit is contained in:
Didictateur 2025-04-29 17:05:02 +02:00
parent fed46f613d
commit c3544be414
4 changed files with 271 additions and 7 deletions

File diff suppressed because one or more lines are too long

View file

@ -16,6 +16,8 @@ class RiichiDisplay {
// Ressources du jeu // Ressources du jeu
private hands: Array<Hand> = []; private hands: Array<Hand> = [];
private handTexts: Array<string> = [];
private wind: number = Math.floor(Math.random() * 4);
// Animation et événements // Animation et événements
private animationFrameId: number | null = null; private animationFrameId: number | null = null;
@ -25,7 +27,7 @@ class RiichiDisplay {
// Constantes pour le rendu // Constantes pour le rendu
private readonly BASE_X: number = 50; private readonly BASE_X: number = 50;
private readonly BASE_Y: number = 90; private readonly BASE_Y: number = 90;
private readonly DY = 180; private readonly DY = 160;
private readonly SIZE: number = 0.75; private readonly SIZE: number = 0.75;
constructor(canvasId: string = CANVAS_ID) { constructor(canvasId: string = CANVAS_ID) {
@ -60,6 +62,11 @@ class RiichiDisplay {
*/ */
private drawHandsAndLabels(): void { private drawHandsAndLabels(): void {
for (let i = 0; i < this.hands.length; i++) { for (let i = 0; i < this.hands.length; i++) {
this.ctx.fillStyle = "#DFDFFF";
this.ctx.font = "40px serif";
this.ctx.fillText(this.handTexts[i], this.BASE_X, this.BASE_Y - 20 + i * this.DY);
this.hands[i].drawHand( this.hands[i].drawHand(
this.ctx, this.ctx,
this.BASE_X, this.BASE_X,
@ -102,9 +109,22 @@ class RiichiDisplay {
// Création des mains prédéfinies // Création des mains prédéfinies
this.hands.push( this.hands.push(
function_generator.ordinaires(), function_generator.ordinaires(),
function_generator.brelan_valeur(this.wind),
function_generator.main_pure(),
function_generator.main_semi_pure(),
function_generator.double_suite(),
function_generator.sept_pairs() function_generator.sept_pairs()
); );
this.handTexts.push(
"Tout ordinaires :",
"Brelan de valeur (" + ["Est", "Sud", "Ouest", "Nord"][this.wind] + ") :",
"Main pure :",
"Main semi-pure :",
"Double suite :",
"Sept pairs :"
);
// Préchargement parallèle des ressources // Préchargement parallèle des ressources
await Promise.all([ await Promise.all([
...this.hands.map(hand => this.preloadHand(hand)) ...this.hands.map(hand => this.preloadHand(hand))

View file

@ -4,7 +4,7 @@ import { Tile } from "../tile";
export const function_generator = { export const function_generator = {
ordinaires(): Hand { ordinaires(wind: number = 0): Hand {
let h = new Hand(); let h = new Hand();
let deck = new Deck(); let deck = new Deck();
deck.shuffle(); deck.shuffle();
@ -60,7 +60,251 @@ export const function_generator = {
return h; return h;
}, },
sept_pairs(): Hand { brelan_valeur(wind: number = 0): Hand {
let h = new Hand();
let deck = new Deck();
deck.shuffle();
// brelan
let f: number;
let v: number;
if (Math.random() < 1/3) { // dragons
f = 5;
v = Math.floor(Math.random() * 3) + 1;
} else if (Math.random() < 0.5) { // est
f = 4;
v = 1;
} else { // vent du joueur
f = 4;
v = wind + 1;
}
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
let count = 3;
// pair
f = Math.floor(Math.random() * 3) + 1;
v = Math.floor(Math.random() * 9) + 1;
while (deck.count(f, v) < 2) {
f = Math.floor(Math.random() * 3) + 1;
v = Math.floor(Math.random() * 9) + 1;
}
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
count += 2;
while (count !== 14) {
if (Math.random() < 0.5) { // pon
let t1 = deck.pop();
let f = t1.getFamily();
let v = t1.getValue();
if (
deck.count(f, v) > 1
) {
h.push(t1);
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
count += 3;
} else {
deck.push(t1);
deck.shuffle();
}
} else { // chii
let f = Math.floor(Math.random() * 3) + 1;
let v = Math.floor(Math.random() * 7) + 1;
if (
deck.count(f, v) > 1 &&
deck.count(f, v + 1) > 1 &&
deck.count(f, v + 2) > 1
) {
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v + 1) as NonNullable<Tile>);
h.push(deck.find(f, v + 2) as NonNullable<Tile>);
count += 3;
}
}
}
h.sort();
return h;
},
main_pure(wind: number = 0): Hand {
let h = new Hand();
let deck = new Deck();
deck.shuffle();
let f = Math.floor(Math.random() * 3) + 1;
let v = Math.floor(Math.random() * 9) + 1;
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
let count = 2;
while (count < 14) {
if (Math.random() < 0.5) { // pon
let v = Math.floor(Math.random() * 9) + 1;
if (deck.count(f, v) > 2) {
for (let i = 0; i < 3; i++) {
h.push(deck.find(f, v) as NonNullable<Tile>);
count++;
}
}
} else { // chii
let v = Math.floor(Math.random() * 7) + 1;
if (
deck.count(f, v) > 0 &&
deck.count(f, v+1) > 0 &&
deck.count(f, v+2) > 0
) {
for (let i = 0; i < 3; i++) {
h.push(deck.find(f, v + i) as NonNullable<Tile>);
count++;
}
}
}
}
h.sort();
return h;
},
main_semi_pure(wind: number = 0): Hand {
let h = new Hand();
let deck = new Deck();
deck.shuffle();
let f = Math.floor(Math.random() * 3) + 1;
let v = Math.floor(Math.random() * 9) + 1;
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
let count = 2;
let family = Math.floor(Math.random() * 2) + 4;
let value = Math.floor(Math.random() * 3) + 1;
h.push(deck.find(family, value) as NonNullable<Tile>);
h.push(deck.find(family, value) as NonNullable<Tile>);
h.push(deck.find(family, value) as NonNullable<Tile>);
count += 3;
while (count < 14) {
if (Math.random() < 0.5) { // pon
if (Math.random() < 0.5) { // famille
let v = Math.floor(Math.random() * 9) + 1;
if (deck.count(f, v) > 2) {
for (let i = 0; i < 3; i++) {
h.push(deck.find(f, v) as NonNullable<Tile>);
count++;
}
}
} else if (Math.random() < 0.5) { // vent
let v = Math.floor(Math.random() * 4) + 1;
if (deck.count(4, v) > 2) {
for (let i = 0; i < 3; i++) {
h.push(deck.find(4, v) as NonNullable<Tile>);
count++;
}
}
} else { // dragon
let v = Math.floor(Math.random() * 3) + 1;
if (deck.count(5, v) > 2) {
for (let i = 0; i < 3; i++) {
h.push(deck.find(5, v) as NonNullable<Tile>);
count++;
}
}
}
} else { // chii
let v = Math.floor(Math.random() * 7) + 1;
if (
deck.count(f, v) > 0 &&
deck.count(f, v+1) > 0 &&
deck.count(f, v+2) > 0
) {
for (let i = 0; i < 3; i++) {
h.push(deck.find(f, v + i) as NonNullable<Tile>);
count++;
}
}
}
}
h.sort();
return h;
},
double_suite(wind: number = 0): Hand {
let h = new Hand();
let deck = new Deck();
deck.shuffle();
// choix d'une paire
let t1 = deck.pop();
let t2 = deck.find(t1.getFamily(), t1.getValue()) as NonNullable<Tile>;
h.push(t1);
h.push(t2);
let count = 2;
// double suite
let f = Math.floor(Math.random() * 3) + 1;
let v = Math.floor(Math.random() * 7) + 1;
while (
deck.count(f, v) < 2 ||
deck.count(f, v + 1) < 2 ||
deck.count(f, v + 2 ) < 2
) {
f = Math.floor(Math.random() * 3) + 1;
v = Math.floor(Math.random() * 7) + 1;
}
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v + 1) as NonNullable<Tile>);
h.push(deck.find(f, v + 1) as NonNullable<Tile>);
h.push(deck.find(f, v + 2) as NonNullable<Tile>);
h.push(deck.find(f, v + 2) as NonNullable<Tile>);
count += 6;
while (count !== 14) {
if (Math.random() < 0.5) { // pon
let t1 = deck.pop();
let f = t1.getFamily();
let v = t1.getValue();
if (
deck.count(f, v) > 1
) {
h.push(t1);
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v) as NonNullable<Tile>);
count += 3;
} else {
deck.push(t1);
deck.shuffle();
}
} else { // chii
let f = Math.floor(Math.random() * 3) + 1;
let v = Math.floor(Math.random() * 7) + 1;
if (
deck.count(f, v) > 1 &&
deck.count(f, v + 1) > 1 &&
deck.count(f, v + 2) > 1
) {
h.push(deck.find(f, v) as NonNullable<Tile>);
h.push(deck.find(f, v + 1) as NonNullable<Tile>);
h.push(deck.find(f, v + 2) as NonNullable<Tile>);
count += 3;
}
}
}
h.sort();
return h;
},
sept_pairs(wind: number = 0): Hand {
let h = new Hand(); let h = new Hand();
let deck = new Deck(); let deck = new Deck();
deck.shuffle(); deck.shuffle();