Adding perquisites.

This commit is contained in:
Elf M. Sternberg 2013-12-03 23:45:49 -08:00
parent a2e22aba27
commit 32a9e90226
3 changed files with 42 additions and 10 deletions

12
README.md Normal file
View File

@ -0,0 +1,12 @@
Yahoo's running this contest. Read about it here:
http://yahoobingo.herokuapp.com/
This took me about 40 minutes, total. I was thinking about re-writing
this in Bacon, but my Bacon is pretty raw. At best, I could
propertize the cards to create a new card (i.e. a new state) every
time a ball came in, but that seemed a little overwrought.
I'm sad that it requires underscore, but Node's native reduce doesn't
support object iteration, only arrays.
It was nice to have an opportunity to hack Coffee and Node again.

View File

@ -1,22 +1,22 @@
#!/usr/bin/coffee
io = require 'socket.io-client'
util = require 'util'
socket = io.connect 'ws://yahoobingo.herokuapp.com'
_ = require 'underscore'
bingo = ['B', 'I', 'N', 'G', 'O']
state = 'lost'
fnum = (n) -> if n < 10 then " #{n}" else "#{n}"
snum = (n) -> if n < 10 then " #{n}" else "#{n}"
fnum = (j) -> if j.found then "[" + snum(j.n) + "]" else " " + snum(j.n) + " "
socket = io.connect 'ws://yahoobingo.herokuapp.com'
socket.on 'connect', ->
card = {}
socket.on 'card', (data) ->
for i in bingo
card[i] = ({num: j, found: false} for j in data.slots[i])
card[i] = ({n: j, found: false} for j in data.slots[i])
socket.on 'number', (ball) ->
m = ball.match /([BINGO])(\d+)/
@ -42,9 +42,9 @@ socket.on 'connect', ->
false)()
console.log "BALL: #{ball}"
console.log "\n\nBALL: #{ball}\n"
for i in bingo
console.log((if j.found then '[#{fnum(j.n)}]' else ' #{fnum(j.n)} ' for j in card[i]).join(' '))
console.log(card[i].map(fnum).join(" "))
if f
console.log "Looks like you won."
socket.emit 'bingo'
@ -53,10 +53,10 @@ socket.on 'connect', ->
socket.on 'lose', -> state = 'lost'
socket.on 'disconnect', ->
console.log "You appear to have #{state}"
console.log "You appear to have #{state}."
process.exit()
socket.emit 'register',
name: 'Ken Sternberg'
email: 'sternberg@mailinator.com'
url: ''
name: 'Elf M. Sternberg'
email: 'elf.sternberg@gmail.com'
url: 'https://github.com/elfsternberg/yahoobingo'

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "Bingo",
"version": "0.0.0",
"description": "Bingo client for Yahoo's Bingo server thing.",
"main": "bingo.coffee",
"dependencies": {
"socket.io-client": "~0.9.16",
"underscore": "~1.5.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"bingo",
"coffeescript"
],
"author": "Elf M. Sternberg",
"license": "BSD-2-Clause"
}