fix: onitama win con
This commit is contained in:
parent
cbf6dce237
commit
244a8bb35a
|
|
@ -176,19 +176,21 @@ const swapCard = registry.register({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查占领胜利条件:玩家的师父棋子到达对手的初始位置
|
* 检查占领胜利条件:玩家的师父棋子到达对手的初始位置
|
||||||
|
* 红色师父需要到达 (2, 4) - 黑色师父的初始位置
|
||||||
|
* 黑色师父需要到达 (2, 0) - 红色师父的初始位置
|
||||||
*/
|
*/
|
||||||
async function handleCheckConquestWin(game: OnitamaGame): Promise<PlayerType | null> {
|
async function handleCheckConquestWin(game: OnitamaGame): Promise<PlayerType | null> {
|
||||||
const state = game.value;
|
const state = game.value;
|
||||||
|
|
||||||
// 红色师父到达 y=4(黑色初始位置)
|
// 红色师父到达 (2, 4)(黑色师父的初始位置)
|
||||||
const redMaster = state.pawns['red-master'];
|
const redMaster = state.pawns['red-master'];
|
||||||
if (redMaster && redMaster.regionId === 'board' && redMaster.position[1] === 4) {
|
if (redMaster && redMaster.regionId === 'board' && redMaster.position[0] === 2 && redMaster.position[1] === 4) {
|
||||||
return 'red';
|
return 'red';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 黑色师父到达 y=0(红色初始位置)
|
// 黑色师父到达 (2, 0)(红色师父的初始位置)
|
||||||
const blackMaster = state.pawns['black-master'];
|
const blackMaster = state.pawns['black-master'];
|
||||||
if (blackMaster && blackMaster.regionId === 'board' && blackMaster.position[1] === 0) {
|
if (blackMaster && blackMaster.regionId === 'board' && blackMaster.position[0] === 2 && blackMaster.position[1] === 0) {
|
||||||
return 'black';
|
return 'black';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,10 +266,10 @@ describe('Onitama Game', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Win Conditions', () => {
|
describe('Win Conditions', () => {
|
||||||
it('should detect conquest win for red (master reaches y=4)', async () => {
|
it('should detect conquest win for red (master reaches 2,4)', async () => {
|
||||||
const { ctx } = createDeterministicContext();
|
const { ctx } = createDeterministicContext();
|
||||||
|
|
||||||
// Move red master to y=4
|
// Move red master to (2, 4) - black master's initial position
|
||||||
ctx.produce(state => {
|
ctx.produce(state => {
|
||||||
const redMaster = state.pawns['red-master'];
|
const redMaster = state.pawns['red-master'];
|
||||||
redMaster.position = [2, 4];
|
redMaster.position = [2, 4];
|
||||||
|
|
@ -282,10 +282,10 @@ describe('Onitama Game', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect conquest win for black (master reaches y=0)', async () => {
|
it('should detect conquest win for black (master reaches 2,0)', async () => {
|
||||||
const { ctx } = createDeterministicContext();
|
const { ctx } = createDeterministicContext();
|
||||||
|
|
||||||
// Move black master to y=0
|
// Move black master to (2, 0) - red master's initial position
|
||||||
ctx.produce(state => {
|
ctx.produce(state => {
|
||||||
const blackMaster = state.pawns['black-master'];
|
const blackMaster = state.pawns['black-master'];
|
||||||
blackMaster.position = [2, 0];
|
blackMaster.position = [2, 0];
|
||||||
|
|
@ -298,6 +298,38 @@ describe('Onitama Game', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should NOT detect conquest win for red if x is wrong', async () => {
|
||||||
|
const { ctx } = createDeterministicContext();
|
||||||
|
|
||||||
|
// Move red master to (1, 4) - wrong x position
|
||||||
|
ctx.produce(state => {
|
||||||
|
const redMaster = state.pawns['red-master'];
|
||||||
|
redMaster.position = [1, 4];
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await ctx.run('check-win');
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.result).toBeNull();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT detect conquest win for black if x is wrong', async () => {
|
||||||
|
const { ctx } = createDeterministicContext();
|
||||||
|
|
||||||
|
// Move black master to (3, 0) - wrong x position
|
||||||
|
ctx.produce(state => {
|
||||||
|
const blackMaster = state.pawns['black-master'];
|
||||||
|
blackMaster.position = [3, 0];
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await ctx.run('check-win');
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.result).toBeNull();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should detect capture win when red master is captured', async () => {
|
it('should detect capture win when red master is captured', async () => {
|
||||||
const { ctx } = createDeterministicContext();
|
const { ctx } = createDeterministicContext();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue