Increment the world state, determining which cells live, die, or appear.

    Args:
        world (list[list]): A square matrix of cells

    Returns: None
191277
def update_state(world):
    

    world_size = len(world)

    def wrap(index):
        """Wrap an index around the other end of the array"""
        return index % world_size

    for x in range(world_size):
        for y in range(world_size):
            # Decide if this node cares about the rules right now
            if not world[x][y].allow_change.get():
                continue
            live_neighbor_count = sum([
                world[wrap(x)][wrap(y + 1)].value,
                world[wrap(x + 1)][wrap(y + 1)].value,
                world[wrap(x + 1)][wrap(y)].value,
                world[wrap(x + 1)][wrap(y - 1)].value,
                world[wrap(x)][wrap(y-1)].value,
                world[wrap(x - 1)][wrap(y - 1)].value,
                world[wrap(x - 1)][wrap(y)].value,
                world[wrap(x - 1)][wrap(y + 1)].value
            ])
            if world[x][y].value:
                # Any live cell with fewer than two live neighbours dies
                # Any live cell with more than three live neighbours dies
                # Any live cell with two or three live neighbours lives
                if not (live_neighbor_count == 2 or live_neighbor_count == 3):
                    world[x][y].value = False
            else:
                # Any dead cell with exactly three live neighbours comes alive
                if live_neighbor_count == 3:
                    world[x][y].value = True
850862
function gameOfLife() {
  for (var i=0; i<grid.columns; i++) {
    buffer[i] = []; // reset row

    for (var k=0; k<grid.rows; k++) {
      var cnt = 0; // counter

      for ( var m=i-1; m<i+2; m++) { // get the states of surrounding cells
        var mm = (m<0) ? grid.columns-1 : ( (m>=grid.columns) ? m-grid.columns : m );

        for ( var n=k-1; n<k+2; n++) {
          var nn = (n<0) ? grid.rows-1 : ( (n>=grid.rows) ? n-grid.rows : n );
          if (mm===i && nn===k) continue;
          else if ( !grid.canFit(mm, nn, 1, 1) ) cnt++;
        }
      }
      buffer[i][k] = (grid.canFit(i, k, 1, 1) && cnt==3) || (!grid.canFit(i, k, 1, 1) && cnt>=2 && cnt<=3);
    }
  }
}
1272152
function World(env, cwd) {
  this.env = env || clone(process.env);
  this.cwd = cwd;
  this.timeout = null;
}
1083970
def cells_changed(self):
        
        self.total_size = sum(cell.size for cell in self.own_cells)
        self.total_mass = sum(cell.mass for cell in self.own_cells)
        self.scale = pow(min(1.0, 64.0 / self.total_size), 0.4) \
            if self.total_size > 0 else 1.0

        if self.own_ids:
            left = min(cell.pos.x for cell in self.own_cells)
            right = max(cell.pos.x for cell in self.own_cells)
            top = min(cell.pos.y for cell in self.own_cells)
            bottom = max(cell.pos.y for cell in self.own_cells)
            self.center = Vec(left + right, top + bottom) / 2
377368
def addCellScalars(self, scalars, name):
        
        poly = self.polydata(False)
        if isinstance(scalars, str):
            scalars = vtk_to_numpy(poly.GetPointData().GetArray(scalars))

        if len(scalars) != poly.GetNumberOfCells():
            colors.printc("~times Number of scalars != nr. of cells", c=1)
            exit()
        arr = numpy_to_vtk(np.ascontiguousarray(scalars), deep=True)
        arr.SetName(name)
        poly.GetCellData().AddArray(arr)
        poly.GetCellData().SetActiveScalars(name)
        self.mapper.SetScalarRange(np.min(scalars), np.max(scalars))
        self.mapper.ScalarVisibilityOn()
        return self
92550
function( world ){

            if ( this.disconnect && this._world ){
                this.disconnect( this._world );
            }

            this._world = world;

            if ( this.connect && world ){
                this.connect( world );
            }

            return this;
        }
510243
function(){
		var cell = this.getcell();
		if(cell.isnull || cell===this.mouseCell){ return;}

		if(this.cursor.modesnum && this.puzzle.playmode && !this.cursor.checksnum(this.inputPoint) && cell.noNum()){
			this.setcursorsnum(cell);
		}
		else if(cell!==this.cursor.getc()){
			this.setcursor(cell);
		}
		else{
			this.inputqnum_main(cell);
		}
		this.mouseCell = cell;
	}
835821
function isZeitWorld(ns) {
  if (!ns.length) {
    return false;
  }
  return ns.every(host => host.endsWith('.zeit.world'));
}
137181
def update(self, a, b, c, d):
        
        self.table.ravel()[:] = [a, b, c, d]
        self.N = self.table.sum()
1160878
def increment(self, counter_name, delta=1):
    
    self._shard_state.counters_map.increment(counter_name, delta)
399682
def find_water_flow(self, world, water_path):
        """"""

        # iterate through each cell
        for x in range(world.width - 1):
            for y in range(world.height - 1):
                # search around cell for a direction
                path = self.find_quick_path([x, y], world)
                if path:
                    tx, ty = path
                    flow_dir = [tx - x, ty - y]
                    key = 0
                    for direction in DIR_NEIGHBORS_CENTER:
                        if direction == flow_dir:
                            water_path[y, x] = key
                        key += 1
379737
def act(self, world_state, agent_host, current_r ):
        """"""
        
        obs_text = world_state.observations[-1].text
        obs = json.loads(obs_text) # most recent observation
        self.logger.debug(obs)
        if not u'XPos' in obs or not u'ZPos' in obs:
            self.logger.error("Incomplete observation received: %s" % obs_text)
            return 0
        current_s = "%d:%d" % (int(obs[u'XPos']), int(obs[u'ZPos']))
        self.logger.debug("State: %s (x = %.2f, z = %.2f)" % (current_s, float(obs[u'XPos']), float(obs[u'ZPos'])))
        if current_s not in self.q_table:
            self.q_table[current_s] = ([0] * len(self.actions))

        # update Q values
        if self.prev_s is not None and self.prev_a is not None:
            self.updateQTable( current_r, current_s )

        self.drawQ( curr_x = int(obs[u'XPos']), curr_y = int(obs[u'ZPos']) )

        # select the next action
        rnd = random.random()
        if rnd < self.epsilon:
            a = random.randint(0, len(self.actions) - 1)
            self.logger.info("Random action: %s" % self.actions[a])
        else:
            m = max(self.q_table[current_s])
            self.logger.debug("Current values: %s" % ",".join(str(x) for x in self.q_table[current_s]))
            l = list()
            for x in range(0, len(self.actions)):
                if self.q_table[current_s][x] == m:
                    l.append(x)
            y = random.randint(0, len(l)-1)
            a = l[y]
            self.logger.info("Taking q action: %s" % self.actions[a])

        # try to send the selected action, only update prev_s if this succeeds
        try:
            agent_host.sendCommand(self.actions[a])
            self.prev_s = current_s
            self.prev_a = a

        except RuntimeError as e:
            self.logger.error("Failed to send command: %s" % e)

        return current_r
168190
def parse_cell(line, world_size):
    
    # Remove "CELL "
    line = line[4:]

    # Extract information
    sline = [i.strip() for i in line.split(":")]
    name = sline[0]
    name = reduce_resource_name_to_task(name)
    cell_components = sline[1].split(",")
    cells = []

    # List all cells
    for i in range(len(cell_components)):
        if ".." in cell_components[i]:
            cell_range = [int(j) for j in cell_components[i].split("..")]
            for j in range(int(cell_range[0]), int(cell_range[1]+1)):
                cells.append(j)
        else:
            cells.append(int(cell_components[i]))

    if cells == [""]:
        return (name, [])

    xy_pairs = [(int(c) % world_size[0], int(c)//world_size[0]) for c in cells]

    return (name, xy_pairs)
270826
def update(self):
        
        display_data = []
        for y in range(self.height):
            for x in range(self.width):
                for color in self.matrix[x][y]:
                    display_data.append(int(color))

        checksum = bytearray([0, 0, 0, 0])
        data_as_bytes = bytearray(display_data)
        data = data_as_bytes + checksum
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(data, (self.host, self.port))
805411
def isalive (self):
        ''' '''

        if self.child_fd == -1:
            return False
        try:
            os.fstat(self.child_fd)
            return True
        except:
            return False
1189886
def clear_surroundings(self):
        
        cells_to_clear = self.grd.eight_neighbors(self.current_y, self.current_x)
        for cell in cells_to_clear:
            self.grd.set_tile(cell[0], cell[1], ' ')
667962
public void addWorldToGroup(String groupName, String world) {
        if (!groupName.equalsIgnoreCase(DEFAULT_GROUP_NAME)) {
            if (list.containsKey(groupName)) {
                list.get(groupName).addWorld(world);
            } else {
                WorldGroup group = new WorldGroup(groupName);
                group.addWorld(world);
            }
        }
    }