aboutsummaryrefslogtreecommitdiff
path: root/examples/jarvis.js
blob: 19f9651cc3b69d0cee86d2a2c88746b90012b462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// A bot which responds to `jarvis` with a box

const Space = require('../space');
const Socket = require('../socket');
const getdims = require('../utils/getdims');

var main = new Socket();

function Sparse(){ // A "sparse" data-storage mechanism
  this.data = [];
  this.avail = [];
  this.add = function(data){
    
  }
  this.del = function(id){
    this.avail.push(id);
    this.data[id] = null;
  }
}

function equals(arg1,arg2){ // Just takes the specific case argument of each being an int pair
  return arg1[0] == arg2[0] && arg1[1] == arg2[1]
}

main.on('open', ()=>{ // Tries to identify itself with a cursor movement
  let coords = [Math.floor(Math.random()*100000+16),Math.floor(Math.random()*100000+16)];
  main.cursor(coords);
  main.on('cursor', detect);
  function detect(pos, send){
    if (equals(pos[0],coords)){
      main.off('cursor', detect);
      this.emit('identity', sender);
    }
  }
})

main.on('identity', (sender) => {
  main.on('tileUpdate', (send, source, tiles) => {
    if (send == sender) return;
    // Get dimensions somehow

  })
})