# Ideas for puzzle simulator API



## mrgabor7 (Aug 13, 2017)

I'm writing (attempting to write) a general purpose JavaScript library that will simulate twisty puzzles in a highly-configurable way.

I'm currently trying to design an easy-to-use API, but what I find is that configurability and ease-of-use are not simple to combine. (This is as much of a learning exercise as a genuine project.)

Here is an example of what I'm thinking about currently:


```
let cube = new Library.puzzles.Cuboid({ size: [3,3,3] })

// Sets the top and bottom faces of the cube to have colored cubies instead of stickers
cube.getFacelets({
    filter: cube.filters.union([
        cube.filters.topFace,
        cube.filters.bottomFace
    ])
}).each((facelet) => {
    facelet.setColor(facelet.getSticker().getColor())
    facelet.showSticker(false)
})
```

This "filter" seems overly complicated for what I'm trying to achieve. Perhaps adding a simpler option would help:


```
cube.getFacelets('face:U,face:D').each((facelet) => {
    facelet.setColor(facelet.getSticker().getColor())
    facelet.showSticker(false)
})
```

(This is much cleaner)

This is just one of probably many more design choices. (I'm anxious about trying to implement animation such as animating sticker color changes, oh boy...)
*
I would appreciate any and all suggestions regarding anything to do with the API.*


----------



## Lucas Garron (Aug 16, 2017)

I have some thoughts on this, after trying to write a good general puzzle framework for 6 years.
The main thing I would suggest is to avoid reinventing the wheel wherever possible.

For my project, I was planning to bite the bullet and work on supporting Roofpig's system: https://github.com/larspetrus/Roofpig#22-the-cube


----------

