+ update_selection_display()
+ neighbors = {}
+ nneighbors = {}
+ for tile in faders
+ tile.dom.unbind('click').fadeOut fade_ms
+ tile.new_hp = tile.hp
+ for n in tile.space.neighbors
+ neighbors[n.id] = n.tile
+ for nn in n.neighbors
+ nneighbors[nn.id] = nn.tile
+ # fix overlaps of faders, neighors, nneighbors
+ for tile in faders
+ delete nneighbors[tile.space.id]
+ delete neighbors[tile.space.id]
+ for k, v of neighbors
+ delete nneighbors[k]
+ # convert to arrays so we can sort, etc
+ nneighbors = (v for k, v of nneighbors)
+ neighbors = (v for k, v of neighbors)
+ areas = {
+ neighbors: {
+ tiles: neighbors
+ up: []
+ down: []
+ }
+ neighbor_neighbors: {
+ tiles: nneighbors
+ up: []
+ down: []
+ }
+ board: {
+ tiles: (space.tile for space in spaces)
+ up: []
+ down: []
+ }
+ }
+ for k, v of areas
+ for t in v.tiles
+ if t.hp is 0
+ v.down.push t
+ else
+ v.up.push t
+ if word_length < 8
+ boom = booms[word_length]
+ else
+ boom = booms.lots
+ for area_name, effects of boom
+ area = areas[area_name]
+ if effects.flips is 'all' or effects.flips >= area.down.length
+ for t in area.down
+ unsink t
+ else
+ down_count = area.down.length
+ flips_left = effects.flips
+ while flips_left > 0 and down_count > 0
+ flips_left -= 1
+ flipper = Math.floor(Math.random() * down_count)
+ unsink area.down[flipper]
+ down_count -= 1
+ # move the last tile back into range
+ area.down[flipper] = area.down[down_count]
+ if effects.force > 0
+ for tile in area.up
+ tile.new_hp = tile.hp + effects.force
+ for s in spaces
+ s.tile.new_hp ?= s.tile.hp - 1
+ if s.tile.new_hp < 0
+ s.tile.new_hp = 0
+ else if s.tile.new_hp > HP_MAX
+ s.tile.new_hp = HP_MAX
+ if s.tile.new_hp isnt s.tile.hp
+ s.tile.dom.removeClass "hp#{s.tile.hp}"
+ s.tile.dom.addClass "hp#{s.tile.new_hp}"
+ s.tile.hp = s.tile.new_hp
+ delete s.tile.new_hp
+ timeout fade_ms + 1, ->
+ # delete old tiles, mark where tiles are moving