warriorjs-engine
Version:
The bowels of WarriorJS
73 lines (62 loc) • 1.32 kB
Markdown
# WarriorJS Engine
```javascript
import Engine from 'warriorjs-engine';
```
## Engine.playLevel(config, profile, maxTurns)
Plays the level defined in the passed in `config` with the passed in `profile`, allowing `maxTurns` to complete the level (1000 by default). Returning an object with the result (whether it passed the level or not), the points earned and the level trace.
```javascript
Engine.playLevel(config, profile, maxTurns) // => { passed, points, trace }
```
**Example**
```javascript
const config = {
timeBonus: 15,
floor: {
size: {
width: 8,
height: 1
},
stairs: {
x: 7,
y: 0
},
units: [
{
type: 'warrior',
x: 0,
y: 0,
facing: 'east',
abilities: {
attack: [],
feel: []
}
},
{
type: 'sludge',
x: 4,
y: 0,
facing: 'west'
}
]
}
};
const profile = {
playerCode: `
class Player {
playTurn(warrior) {
if (warrior.feel().isEnemy()) {
warrior.attack();
} else {
warrior.walk();
}
}
}
`,
warriorName: 'Spartacus',
abilities: {
walk: []
}
};
const MAX_TURNS = 120;
const { passed, points, trace } = Engine.playLevel(config, profile, MAX_TURNS);
```