FIX - stabilize phone game engines

This commit is contained in:
smx.pusha
2026-08-08 17:56:55 +02:00
parent d9c8fbbdbd
commit 857fa95e23
4 changed files with 32 additions and 2 deletions
@@ -20,6 +20,10 @@ describe('neon drop engine', () => {
it('starts with a valid piece and a complete seven-piece bag', () => {
const game = createNeonDropGame(() => 0.5)
expect(game.status).toBe('playing')
expect(game.board).toHaveLength(17)
expect(game.board.every((row) => row.length === NEON_DROP_COLUMNS)).toBe(
true,
)
expect(new Set([game.active.kind, ...game.queue]).size).toBe(7)
expect(canPlaceNeonDropPiece(game.board, game.active)).toBe(true)
})
@@ -8,7 +8,7 @@ import type {
} from './types'
export const NEON_DROP_COLUMNS = 10
export const NEON_DROP_ROWS = 18
export const NEON_DROP_ROWS = 17
export const NEON_DROP_LINES_PER_LEVEL = 8
const PIECE_KINDS: NeonDropPieceKind[] = ['I', 'J', 'L', 'O', 'S', 'T', 'Z']
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
import {
createSnakeGame,
SNAKE_BOARD_HEIGHT,
SNAKE_BOARD_WIDTH,
stepSnake,
turnSnake,
@@ -27,6 +28,17 @@ describe('Snake engine', () => {
expect(next.body).not.toContainEqual(next.fruit)
})
it('places fruit inside the visible play area', () => {
for (const random of [() => 0, () => 1]) {
const { fruit } = createSnakeGame(random)
expect(fruit.x).toBeGreaterThanOrEqual(0)
expect(fruit.x).toBeLessThan(SNAKE_BOARD_WIDTH)
expect(fruit.y).toBeGreaterThanOrEqual(0)
expect(fruit.y).toBeLessThan(SNAKE_BOARD_HEIGHT)
}
})
it('ignores an immediate reverse direction', () => {
const game = createSnakeGame(() => 0)
@@ -46,6 +58,20 @@ describe('Snake engine', () => {
expect(stepSnake(game).status).toBe('game-over')
})
it('ends the game at the lower edge of the visible play area', () => {
const game: SnakeGameState = {
...createSnakeGame(() => 0),
body: [
{ x: 4, y: SNAKE_BOARD_HEIGHT - 1 },
{ x: 4, y: SNAKE_BOARD_HEIGHT - 2 },
],
direction: 'down',
pendingDirection: 'down',
}
expect(stepSnake(game).status).toBe('game-over')
})
it('ends the game on body collision', () => {
const game: SnakeGameState = {
body: [
+1 -1
View File
@@ -5,7 +5,7 @@ import type {
} from './types'
export const SNAKE_BOARD_WIDTH = 16
export const SNAKE_BOARD_HEIGHT = 18
export const SNAKE_BOARD_HEIGHT = 30
const DIRECTION_VECTORS: Record<SnakeDirection, SnakePoint> = {
up: { x: 0, y: -1 },