0.0.2 • Published 3 months ago

wasm_crossword_generator v0.0.2

Weekly downloads
-
License
(MIT OR Apache-2....
Repository
github
Last release
3 months ago

WASM Crossword Generator

WASM Crossword Generator is a TypeScript library for the generation and operation of crossword puzzles. The main functionality is written in Rust, which is compiled to WASM with TypeScript types generated from the Rust types. The end result is completely portable and well-typed.

The underlying Rust code is found in the crate directory, it's published on it's own to crates.io and documentation is available.

This directory houses the src for the NPM package wasm_crossword_generator as well as the dist which appears in the NPM package.

An example site using this library can be viewed and played online here. The source of that site is meant to act as and example / demo and is found here.

To add this library to your NPM project.

$ npm install --save wasm_crossword_generator

The most basic usage of the library would look like:

import {CrosswordClient, SolutionConf} from "wasm_crossword_generator";
const client = await CrosswordClient.initialize();

const words = [{text: "library", clue: "Not a framework"}];
const conf: SolutionConf = {
  height: 10,
  width: 10,
  max_words: 20,
  initial_placement: null,
  words,
  // A real conf would almost certainly want to pass an options object here to enable retries,
  // but because we only have one word and no acceptance criteria, we know that the puzzle will be
  // created first try.
  requirements: null,
}

// The "PerWord" puzzle only requires players to guess a word, not a word and a placement. It also
// immediately informs the user if the guess was correct.
let puzzle_container = client.generate_crossword_puzzle(conf, "PerWord");

let guess = {
  word: {
    text: "library",
    // The clue is not checked as part of a guess for any Playmode.
    clue: null,
  },
  // The placement is ignored because it is a "PerWord" puzzle, but with other Playmodes
  // this would be meaningful.
  placement { x: 0, y: 0, direction: "Horizontal" },
};

// Note the need to re-assign to puzzle_container. This technique is used to pass ownership
// back and forth with WASM.
let guess_result = null;
{puzzle_container, guess_result} = client.guess_word(puzzle, guess);

// Because there is only one word in the "puzzle", the puzzle is "Complete" after one guess.
assert(guess_result == "Complete")

The playmodes are "Classic", "PlacedWord", and "PerWord". "Classic" doesn't tell the user if the guess is correct or not and allows the user to save (and later, remove) incorrect answers. "PlacedWord" does tell the user if the guess is correct at time of the guess. "PerWord" is like placed word, but does not check the "Placement" portion of a guess.

The CrosswordClient abstraction found here contains most of the information needed to define and run puzzles. There are other functions attached to the client, like wrong_answers_and_solutions and remove_answer.

The types defined here are useful for understanding.

Full TypeScript-side documentation forthcoming, until then please reference the Rust documentation, the structures and functions are identical.

Happy puzzling!

0.0.2

3 months ago

0.0.1

3 months ago