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)) })