1.0.4 • Published 4 years ago

ulu-crossword v1.0.4

Weekly downloads
11
License
ISC
Repository
-
Last release
4 years ago

ULU Crossword Layout Generator

Description

Crossword Layout generator for playulu.com, it receives an array of objects, generates multiple crosswords layouts, chooses the best one and returns it or prints it.

Installation

Using npm:

npm i ulu-crossword

Usage

Node js
const { createCrossword } = require('ulu-crossword');
React
import { createCrossword } from 'ulu-crossword';

Example

const { createCrossword } = require('ulu-crossword');
let words = [{
    respuesta: 'perro',
    idPregunta: 10,
    pregunta: 'animal perruno'
},
{
    respuesta: 'panda',
    idPregunta: 12,
    pregunta: 'animal panduno'
},
{
    respuesta: 'mapache',
    idPregunta: 13,
    pregunta: 'animal mapachudo'
}];
const layout = createCrossword({ words, gridSize: 9, print: true, tries: 75 });
if(layout){
    console.log(layout);
    /*
        [
        {
            respuesta: 'perro',
            x: 2,
            y: 2,
            orientacion: 'vertical',
            idPregunta: 10,
            pregunta: 'animal perruno'
        },
        {
            respuesta: 'panda',
            x: 2,
            y: 2,
            orientacion: 'horizontal',
            idPregunta: 12,
            pregunta: 'animal panduno'
        },
        {
            respuesta: 'mapache',
            x: 3,
            y: 1,
            orientacion: 'vertical',
            idPregunta: 13,
            pregunta: 'animal mapachudo'
        }
        ]
    */
}
else{
    //Layout could not been created
}

Parameters

ParameterDescriptionRequiredDefault
wordsArray of objects of words, see "words array" sectionyes-
gridSizeNumber representing the size of the grid (is a squared grid)yes-
triesBoolean to print in console layout resultnofalse
printNumber of tries to generate best crosswordno75

Print Example

  0 1 2 3 4 5 6 7 8 
0 * * * * * * * * * 
1 * * * m * * * * * 
2 * * p a n d a * * 
3 * * e p * * * * * 
4 * * r a * * * * * 
5 * * r c * * * * * 
6 * * o h * * * * * 
7 * * * e * * * * * 
8 * * * * * * * * * 

Words Array

The array must have the following structure:

let words = [{
    respuesta: 'perro',
    idPregunta: 10,
    pregunta: 'animal perruno'
},
{
    respuesta: 'panda',
    idPregunta: 12,
    pregunta: 'animal panduno'
},
{
    respuesta: 'mapache',
    idPregunta: 13,
    pregunta: 'animal mapachudo'
}];
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago