#  hpp
#  Copyright (C) 1994, 1995  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.

# An hpp latice gas automata.
#
# 0 indicates no particles and the values 1..15 indicate the presence of
# a particle traveling in the north (= 1), east (= 2), south (= 4), and
# west (= 8).  Add the values to get all particle directions.
#
2 dimensions of 0..15

# Identification of the neighboring cells.
#
neighbor[] for north, east, south, west := [0, 1], [1, 0], [0, -1], [-1, 0]

north := 4 when north > 11 | (north > 3 & north < 8)
      := 0 otherwise

south := 1 when south = 1 | south = 3 | south = 5 | south = 7 |
		south = 9 | south = 11 | south = 13 | south = 15
      := 0 otherwise

east := 8 when east >= 8
     := 0 otherwise

west := 2 when west = 2 | west = 3 | west = 6 | west = 7 |
		west = 10 | west = 11 | west = 14 | west = 15
     := 0 otherwise

cell := 10 when north = 4 & south = 1 & east = 0 & west = 0
     := 5 when east = 8 & west = 2 & north = 0 & south = 0
     := north + south + east + west otherwise
