#  hp
#  Copyright (C) 1993  J Dana Eckart
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 1, or (at your option)
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with CELLULAR; see the file COPYING.  If not, write to the 
#  Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

2 dimensions of 
	state of 0..2
	health of 0..100
end

# Get the Moore neighborhood
#
neighbor[] for north, ne, east, se, south, sw, west, nw
	:= [0, 1].health, [1, 1].health, [1, 0].health, [1, -1].health, 
	   [0, -1].health, [-1, -1].health, [-1, 0].health, [-1, 1].health

k1 := 2
k2 := 3
g  := 23

infected := 0
ill := 0
sum := cell.health

forall i
	infected := infected + 1 when neighbor[i] > 0 & neighbor[i] < 100
	ill := ill + 1 when neighbor[i] = 100
	sum := sum + neighbor[i]
end

if cell.health = 0 then
	health := ill/k1 + infected/k2
	cell.health := health
	cell.state := 0 when health = 0
	           := 1 when health < 100
	           := 2 otherwise
elsif cell.health = 100 then
	cell.health := 0
	cell.state := 0
else
	health := sum/(infected + 1) + g
	cell.health := health when health <= 100
                    := 100 otherwise
	cell.state := 0 when health = 0
	           := 1 when health < 100
	           := 2 otherwise
end
