snake-ai-game
Version:
A terminal-based snake game powered by AI.
18 lines (13 loc) • 620 B
text/typescript
export const clearScreen = (): void => {
process.stdout.write('\x1B[2J\x1B[3J\x1B[H');
};
export const getPositionKey = ({x, y}: {x: number, y: number}): string => `${x},${y}`;
export const arePositionsEqual = (p1: {x: number, y: number}, p2: {x: number, y: number}): boolean =>
p1.x === p2.x && p1.y === p2.y;
export const getRandomInt = (min: number, max: number): number =>
Math.floor(Math.random() * (max - min) + min);
export const formatTime = (seconds: number): string => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${secs.toString().padStart(2, '0')}`;
};