Skip to the content

Jirai地雷

Deal seeded minefields, prove hints from visible clues and mount square, orthogonal, hexagonal or wraparound boards.

Jirai is the Japanese word 地雷 for a land mine. About the name

Contents

How-to

Generate verified no-guess fields

Keep seed, opening and budgets explicit; generation failure is never an unproved board.

Request a proved field

import { makeBoard,isSolvable,GenerationError,type Settings } from "@johnmorrisdotca/jirai";
const settings: Settings={width:5,height:5,mines:2,grid:"square",noGuess:true,opening:"clear",seed:42};
try {
 const board=makeBoard(settings,0,{attempts:8,repair:false});
 console.log(board.attempt,isSolvable(board));
} catch(error) {
 if(!(error instanceof GenerationError)) throw error;
 console.log(error.code);
}
0 true

The seed fixes the candidate stream for the same settings and opening. Generation first tries random layouts, then can repair a promising candidate by moving mines. Both routes use the native deduction proof. attempt identifies the accepted candidate/repair stage. For a reproducible lesson, pin package version, topology, shape, dimensions, mine count, first cell and generation options as well as seed.

Handle failure as failure

GenerationError distinguishes invalid settings, an impossible protected opening and an exhausted budget. A clear opening can protect too many active cells to fit the mines, and an isolated opening may permit no useful deduction. A no-guess failure does not quietly return a guessing field. repair:false or zero repairs retains the earlier attempts-only policy. Exact enumeration is bounded by the exported frontier/node limits.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/jirai 0.5.0.