Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rjyo/lpb-client
https://github.com/rjyo/lpb-client
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/rjyo/lpb-client
- Owner: rjyo
- Created: 2012-11-12T14:09:45.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-11-12T16:12:06.000Z (about 12 years ago)
- Last Synced: 2024-04-15T12:18:24.372Z (9 months ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## About Letterpress Battle
[Letterpress](https://itunes.apple.com/us/app/letterpress-word-game/id526619424?mt=8) is a great iPhone/iPad game by Loren Brichter.
After playing Letterpress happily for several hours, [@baotuo](http://twitter.com/baotuo) and [I](http://twitter.com/xu_lele) decided to build a cheater to get all usable words in one game. And the faster one wins.
And after the [solver project](https://github.com/rjyo/letterpress-solver), which [@baotuo's](https://github.com/baotuo/letterpress-solver) won the first round and I won the second, we decided to continue the competition with game AIs. A tool to monitor and tune the AIs is need by both of us, and that's why ‘Letterpress Battle’ (aka LPB) comes from.
The main purpose of LPB is to let the game AIs build by me and @baotuo to battle together with a common set of APIs. You can fight the AIs too if you like.
## LPB Client API
Two class is provided in this API.
One is `LPBClient`, which support the following server API
* create - Create a game with a 25-characters board
* list - List all games
* join - Join a game
* move - Take a move
* resign - Resign a game
* show - Show game statisticsThe other is `LPBConsole`, which is a interactive to play the game in console.
### Example
[An runnable example](https://github.com/rjyo/letterpress-solver/blob/master/c.js) can be found in Letterpress Solver project.
The main concept is like below:
```javascript
var program = require('commander')
, lpb = require('lpb-client');program
.version('0.0.1')
.option('-s, --server [url]', 'Base URL of the server')
.option('-p, --player [player]', 'Unique player ID')
.parse(process.argv);...
if (program.server && program.player) {
c = lpb.LPBConsole(program.server, program.player);// logic to handle the move
function takeMove() {
...
}// logic to init the game board
function prepareBoard(data) {
...
}// logic to init the game board
function applyMove(data) {
...
}c.on('join', prepareBoard);
c.on('ourmove', takeMove);
c.on('theirmove', function(move) {
applyMove();
c.emit('ourmove');
});c.start();
} else {
program.outputHelp();
}
```