Everyone go ponya !
This commit is contained in:
parent
69a2cc043b
commit
1831a7ac91
3 changed files with 65 additions and 39 deletions
42
src/game.ts
42
src/game.ts
|
|
@ -122,7 +122,10 @@ export class Game {
|
||||||
} else { // nothing unusual
|
} else { // nothing unusual
|
||||||
if (this.turn === 0 && this.selectedTile !== undefined) {
|
if (this.turn === 0 && this.selectedTile !== undefined) {
|
||||||
this.discard(0, this.selectedTile as NonNullable<number>);
|
this.discard(0, this.selectedTile as NonNullable<number>);
|
||||||
this.turn++;
|
this.checkPon();
|
||||||
|
console.log("turn", this.turn, "\n");
|
||||||
|
this.turn = (this.turn + 1) % 4;
|
||||||
|
console.log("new turn", this.turn, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -157,6 +160,7 @@ export class Game {
|
||||||
if (
|
if (
|
||||||
this.turn !== 0
|
this.turn !== 0
|
||||||
) { // bot playing
|
) { // bot playing
|
||||||
|
console.log(this.turn, '\n');
|
||||||
if (!this.hasPicked) { // begin of his turn
|
if (!this.hasPicked) { // begin of his turn
|
||||||
this.lastPlayed = Date.now();
|
this.lastPlayed = Date.now();
|
||||||
this.pick(this.turn);
|
this.pick(this.turn);
|
||||||
|
|
@ -167,6 +171,7 @@ export class Game {
|
||||||
let n = Math.floor(this.hands[this.turn].length() * Math.random());
|
let n = Math.floor(this.hands[this.turn].length() * Math.random());
|
||||||
this.discard(this.turn, n);
|
this.discard(this.turn, n);
|
||||||
this.hasPlayed = true;
|
this.hasPlayed = true;
|
||||||
|
this.checkPon();
|
||||||
this.canCall = this.canDoAChii().length > 0 || this.canDoAPon();
|
this.canCall = this.canDoAChii().length > 0 || this.canDoAPon();
|
||||||
}
|
}
|
||||||
} else if (!this.canCall) { // end of his turn
|
} else if (!this.canCall) { // end of his turn
|
||||||
|
|
@ -232,28 +237,39 @@ export class Game {
|
||||||
console.log("Chii !\n");
|
console.log("Chii !\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private canDoAPon(): boolean {
|
private checkPon(): void {
|
||||||
|
for (var p = 1; p < 4; p++) {
|
||||||
|
if (this.canDoAPon(p)) {
|
||||||
|
console.log(p, '\n');
|
||||||
|
this.pon(this.lastDiscard as NonNullable<number>, p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private canDoAPon(player: number = 0): boolean {
|
||||||
if (
|
if (
|
||||||
this.lastDiscard !== undefined &&
|
this.lastDiscard !== undefined &&
|
||||||
this.lastDiscard !== 0 &&
|
this.lastDiscard !== player &&
|
||||||
this.turn !== 0
|
this.turn !== player
|
||||||
) {
|
) {
|
||||||
let t = this.discards[this.lastDiscard][this.discards[this.lastDiscard].length-1];
|
let t = this.discards[this.lastDiscard][this.discards[this.lastDiscard].length-1];
|
||||||
return this.hands[0].count(t.getFamily(), t.getValue()) >= 2;
|
return this.hands[player].count(t.getFamily(), t.getValue()) >= 2;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private pon(p: number): void {
|
private pon(p: number, thief: number = 0): void {
|
||||||
|
console.log(thief, "stole", p, '\n');
|
||||||
let t = this.discards[p].pop() as NonNullable<Tile>;
|
let t = this.discards[p].pop() as NonNullable<Tile>;
|
||||||
this.lastDiscard = undefined;
|
this.lastDiscard = undefined;
|
||||||
let t2 = this.hands[0].find(t.getFamily(), t.getValue()) as NonNullable<Tile>;
|
let t2 = this.hands[thief].find(t.getFamily(), t.getValue()) as NonNullable<Tile>;
|
||||||
let t3 = this.hands[0].find(t.getFamily(), t.getValue()) as NonNullable<Tile>;
|
let t3 = this.hands[thief].find(t.getFamily(), t.getValue()) as NonNullable<Tile>;
|
||||||
[t, t2, t3].forEach(t => t.setTilt());
|
[t, t2, t3].forEach(t => t.setTilt());
|
||||||
this.groups[0].push(new Group([t, t2, t3], p));
|
this.groups[thief].push(new Group([t, t2, t3], p, thief));
|
||||||
|
|
||||||
this.turn = 0;
|
this.turn = thief;
|
||||||
this.hasPicked = true;
|
this.hasPicked = true;
|
||||||
this.hasPlayed = false;
|
this.hasPlayed = false;
|
||||||
}
|
}
|
||||||
|
|
@ -310,7 +326,7 @@ export class Game {
|
||||||
5 * this.sizeHiddenHand,
|
5 * this.sizeHiddenHand,
|
||||||
this.sizeHiddenHand,
|
this.sizeHiddenHand,
|
||||||
undefined,
|
undefined,
|
||||||
true,
|
false,
|
||||||
- pi / 2
|
- pi / 2
|
||||||
);
|
);
|
||||||
this.hands[2].drawHand(
|
this.hands[2].drawHand(
|
||||||
|
|
@ -320,7 +336,7 @@ export class Game {
|
||||||
5 * this.sizeHiddenHand,
|
5 * this.sizeHiddenHand,
|
||||||
this.sizeHiddenHand,
|
this.sizeHiddenHand,
|
||||||
undefined,
|
undefined,
|
||||||
true,
|
false,
|
||||||
- pi
|
- pi
|
||||||
);
|
);
|
||||||
this.hands[3].drawHand(
|
this.hands[3].drawHand(
|
||||||
|
|
@ -330,7 +346,7 @@ export class Game {
|
||||||
5 * this.sizeHiddenHand,
|
5 * this.sizeHiddenHand,
|
||||||
this.sizeHiddenHand,
|
this.sizeHiddenHand,
|
||||||
undefined,
|
undefined,
|
||||||
true,
|
false,
|
||||||
pi / 2
|
pi / 2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
56
src/group.ts
56
src/group.ts
|
|
@ -2,11 +2,17 @@ import { Tile } from "./tile"
|
||||||
|
|
||||||
export class Group {
|
export class Group {
|
||||||
private tiles: Array<Tile>;
|
private tiles: Array<Tile>;
|
||||||
private stolenFrom: number|undefined;
|
private stolenFrom: number;
|
||||||
|
private belongsTo: number
|
||||||
|
|
||||||
public constructor(tiles: Array<Tile> = [], stolenFrom: number|undefined = undefined) {
|
public constructor(
|
||||||
|
tiles: Array<Tile>,
|
||||||
|
stolenFrom: number,
|
||||||
|
belongsTo: number
|
||||||
|
) {
|
||||||
this.tiles = tiles;
|
this.tiles = tiles;
|
||||||
this.stolenFrom = stolenFrom;
|
this.stolenFrom = stolenFrom;
|
||||||
|
this.belongsTo = belongsTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(tile: Tile): void {
|
public push(tile: Tile): void {
|
||||||
|
|
@ -29,21 +35,23 @@ export class Group {
|
||||||
size: number,
|
size: number,
|
||||||
rotation: number,
|
rotation: number,
|
||||||
): void {
|
): void {
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(525, 525);
|
||||||
|
ctx.rotate(rotation);
|
||||||
|
ctx.translate(-525, -525);
|
||||||
|
|
||||||
|
console.log(x, y, '\n');
|
||||||
|
|
||||||
|
rotation = 0;
|
||||||
let v = 75 * size;
|
let v = 75 * size;
|
||||||
let w = 90 * size;
|
let w = 90 * size;
|
||||||
let vx = Math.cos(rotation);
|
let osy = 25 * size / 2;
|
||||||
let vy = Math.sin(rotation);
|
let p = (this.belongsTo - this.stolenFrom - 1 + 4) % 4;
|
||||||
let osx = Math.sin(rotation) * 25 * size / 2;
|
|
||||||
let osy = Math.cos(rotation) * 25 * size / 2;
|
|
||||||
if (!this.stolenFrom) {
|
|
||||||
//TODO error
|
|
||||||
}
|
|
||||||
let p = 3 - (this.stolenFrom as NonNullable<number>);
|
|
||||||
|
|
||||||
if (p === 0) {
|
if (p === 0) {
|
||||||
this.tiles[0].drawTile(
|
this.tiles[0].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + osx,
|
x,
|
||||||
y + osy,
|
y + osy,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
|
|
@ -52,8 +60,8 @@ export class Group {
|
||||||
);
|
);
|
||||||
this.tiles[1].drawTile(
|
this.tiles[1].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + vx * w,
|
x + w,
|
||||||
y + vy * w,
|
y,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
|
|
@ -61,8 +69,8 @@ export class Group {
|
||||||
);
|
);
|
||||||
this.tiles[2].drawTile(
|
this.tiles[2].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + vx * (w + v + os * size),
|
x + w + v + os * size,
|
||||||
y + vy * (w + v + os * size),
|
y,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
|
|
@ -81,8 +89,8 @@ export class Group {
|
||||||
);
|
);
|
||||||
this.tiles[1].drawTile(
|
this.tiles[1].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + vx * w + osx,
|
x + w,
|
||||||
y + vy * w + osy,
|
y + osy,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
0 - 3.141592 / 2,
|
0 - 3.141592 / 2,
|
||||||
|
|
@ -90,8 +98,8 @@ export class Group {
|
||||||
);
|
);
|
||||||
this.tiles[2].drawTile(
|
this.tiles[2].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + vx * (w + v + 3 *os * size),
|
x + w + v + 3 *os * size,
|
||||||
y + vy * (w + v + 3 *os * size),
|
y,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
|
|
@ -110,8 +118,8 @@ export class Group {
|
||||||
);
|
);
|
||||||
this.tiles[1].drawTile(
|
this.tiles[1].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + vx * (v + os * size),
|
x + v + os * size,
|
||||||
y + vy * (v + os * size),
|
y,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
|
|
@ -119,8 +127,8 @@ export class Group {
|
||||||
);
|
);
|
||||||
this.tiles[2].drawTile(
|
this.tiles[2].drawTile(
|
||||||
ctx,
|
ctx,
|
||||||
x + vx * (w + v + os * size) + osx,
|
x + w + v + os * size,
|
||||||
y + vy * (w + v + os * size) + osy,
|
y + osy,
|
||||||
size,
|
size,
|
||||||
false,
|
false,
|
||||||
0 - 3.141592 / 2,
|
0 - 3.141592 / 2,
|
||||||
|
|
@ -130,5 +138,7 @@ export class Group {
|
||||||
} else {
|
} else {
|
||||||
//TODO error
|
//TODO error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ export class Hand {
|
||||||
if (groups !== undefined) {
|
if (groups !== undefined) {
|
||||||
this.tiles.push(t1);
|
this.tiles.push(t1);
|
||||||
this.sort();
|
this.sort();
|
||||||
groups.push(new Group([t1, t2]));
|
groups.push(new Group([t1, t2], 0, 0));
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ export class Hand {
|
||||||
this.tiles.push(t3);
|
this.tiles.push(t3);
|
||||||
this.sort();
|
this.sort();
|
||||||
if (groups !== undefined) {
|
if (groups !== undefined) {
|
||||||
groups.push(new Group([t1, t2, t3]));
|
groups.push(new Group([t1, t2, t3], 0, 0));
|
||||||
this.tiles.push(t1);
|
this.tiles.push(t1);
|
||||||
this.sort();
|
this.sort();
|
||||||
return groups;
|
return groups;
|
||||||
|
|
@ -126,7 +126,7 @@ export class Hand {
|
||||||
this.tiles.push(t3);
|
this.tiles.push(t3);
|
||||||
this.sort();
|
this.sort();
|
||||||
if (groups !== undefined) {
|
if (groups !== undefined) {
|
||||||
groups.push(new Group([t3, t2, t1]));
|
groups.push(new Group([t3, t2, t1], 0, 0));
|
||||||
this.tiles.push(t1);
|
this.tiles.push(t1);
|
||||||
this.sort();
|
this.sort();
|
||||||
return groups;
|
return groups;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue