ulu-crossword
v1.0.4
Published
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
Downloads
1
Readme
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
| Parameter | Description | Required | Default |
| ------------- |:-------------:| -----: | -----:
| words | Array
of objects of words, see "words array" section | yes | - |
| gridSize | Number
representing the size of the grid (is a squared grid)| yes | - |
| tries | Boolean
to print in console layout result| no | false
|
| print | Number
of tries to generate best crossword| no | 75
|
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'
}];