Created
September 4, 2015 23:45
-
-
Save chrislloyd/2af96d671126714304ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WebSocket = require('ws') | |
var ws = new WebSocket('ws://localhost:5000') | |
function rand(lim) { | |
return Math.floor(Math.random(lim) * lim) | |
} | |
function sample(col) { | |
return col[rand(col.length)] | |
} | |
ws.on('message', function(message) { | |
// parse the state from the server | |
var state = JSON.parse(message) | |
// print out debugging information | |
console.log('tick', state.tick) | |
console.log('me', state.me) | |
// Just move randomly | |
var dirs = ['←', '↓', '↑', '→'] | |
var cmd = ['MOVE', sample(dirs)] | |
// send the next command | |
ws.send(JSON.stringify(cmd)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment