Improve readability; fix end-state handler.
Fixed end-state handler to stop taking Ball messages when end-state detected. Looking at Yahoo's results board, failing at this could result in the system looking as if I had poor win-state detection. Fixed win-state detection to enclose the card matrix. This makes the coordinate tests look like it takes coordinate pairs, which is the effect we want, improves readability, and reduces errors.
This commit is contained in:
parent
0de8d83595
commit
72dcd58784
11
bingo.coffee
11
bingo.coffee
|
@ -4,7 +4,7 @@ io = require "socket.io-client"
|
|||
|
||||
bingo = ["B", "I", "N", "G", "O"]
|
||||
coors = [0..4]
|
||||
state = "playing"
|
||||
state = ""
|
||||
|
||||
snum = (n) -> if n < 10 then " #{n}" else "#{n}"
|
||||
fnum = (j) -> if j.found then "[#{snum(j.n)}]" else " #{snum(j.n)} "
|
||||
|
@ -19,21 +19,22 @@ socket.on "connect", ->
|
|||
({n: j, found: false} for j in data.slots[i])
|
||||
|
||||
socket.on "number", (ball) ->
|
||||
return if state
|
||||
m = ball.match /([BINGO])(\d+)/
|
||||
row = bingo.indexOf(m[1])
|
||||
card[row] = for j in card[row]
|
||||
if j.found or j.n != +m[2] then j else {n: j.n, found: true}
|
||||
|
||||
may = (m, cond) -> if cond.found then m+1 else m
|
||||
may = (m, x, y) -> if card[x][y].found then m+1 else m
|
||||
|
||||
f = (->
|
||||
for i in coors
|
||||
for test in [((m, j) -> may m, card[i][j]), ((m, j) -> may m, card[j][i])]
|
||||
for test in [((m, j) -> may m, i, j), ((m, j) -> may m, j, i)]
|
||||
if 5 == coors.reduce test, 0
|
||||
return true
|
||||
|
||||
|
||||
for test in [((m, j) -> may m, card[j][j]), ((m, j) -> may m, card[j][4 - j])]
|
||||
for test in [((m, j) -> may m, j, j), ((m, j) -> may m, j, 4-j)]
|
||||
if 5 == coors.reduce test, 0
|
||||
return true
|
||||
|
||||
|
@ -50,7 +51,7 @@ socket.on "connect", ->
|
|||
socket.on "lose", -> state = "lost"
|
||||
|
||||
socket.on "disconnect", ->
|
||||
console.log "You appear to have #{state}."
|
||||
console.log "You appear to have " + if state then state else "TERMINATED UNEXPECTEDLY."
|
||||
process.exit()
|
||||
|
||||
socket.emit "register",
|
||||
|
|
Loading…
Reference in New Issue