Path: wupost!spool.mu.edu!agate!doc.ic.ac.uk!marble.uknet.ac.uk!uknet!brunel!cs89ssg From: cs89ssg@brunel.ac.uk (Sunil Gupta) Newsgroups: alt.sources Subject: cellular automata simulator Part 1/2 Message-ID: Date: 1 Apr 93 19:42:37 GMT Followup-To: alt.sources.bugs Organization: Brunel University, Uxbridge, UK Lines: 500 X-Newsreader: TIN [version 1.1 PL8] Archive-name: automata Submitted-by: cs89ssg@brunel.ac.uk CELLULAR AUTOMATA SIMULATOR ( Version 1.0A APRIL 1993) ------------------------------------------------------ INTRODUCTION This is another example of a reasonably serious application written using the "Simple User Interface Toolkit" (SUIT). It follows on from my petri-net simulator which was released Nov 1992. Please read the DISCLAIMER and SUIT sections below. ABOUT The program will not run very well (if at all) on a monochrome system. it was designed for colour. The program is operated entirely through a graphics interface: INTERFACE .---------------------------------------------------------------. | .----------------------------------------------------. | | | .----------------------------------------. | | | | STEP | | | | | | GRID | | | | | | CLEAR | | | | | | | | | | | | FILE | | | | | | | G R A P H I C S | | | | |.-------.| | | | |.-----.|| || | | | || ||| RULES || | | | || ||| LIST || | | | ||ABORT||| || | | | || ||| || | | | |`-----'|| |`----------------------------------------' | | | |`-------' | | | | rows### cols### states### RIBBON-RIBBON | | | EXIT | | | | `----------------------------------------------------' | `--------------------------------------------------------------' The graphics area contains rectangular cells which can have various states. The state is incremented by clicking with the mouse, and decremented by pressing a key when the mouse is over the cell. To operate this program all you have to do is draw something in the graphics area, click on a rule, and see what happens. STEP toggles whether the automata single steps or continues execution until the operation has been stopped. GRID toggles the state of the grid to be on or off. The grid will be drawn to the aspect ration of the Graphics widget. CLEAR sets the state of the cells in the automata to 0 and redraws the graphics. The redrawing part can appear to be a bit slow when there are a lot of rows and columns. FILE.. A menu button whose menus allows file loading and saving. Currently only files saved by the program can be loaded. This may change in the near future. RULES LIST A scrollable list of current rules. See below for details of the rules. selecting a rules executes it. An Abort widget will be brought up on the left edge of the display. If the STEP gadget is selected (DOWN) the system will do one execution of the selected rule before returning to an idle state. If the step gadget is de-selected (UP) then the system will continue to execute the selected rule until the system reaches a static state or is interrupted (by selecting the abort widget). ROWS sets the number of rows in the current automata. Will reset the contents of the automata. must be pressed to accept the new number of rows. Currently the number of rows has been arbitrarily limited to 100. COLS as above but sets columns. STATES sets the number allowable number of states the user can enter. Has no effect on the execution of the automata. Currently there are a ridiculously high number of states, but in practice only about 10 will actually ever be used. cells with higher states than the value input will be thresholded to the new maximum state. RIBBON This gadget can not be directly interacted with. It just shows the colours associated with the different states. EXIT terminates the program. RULES The notation used relies upon the neighbours of the current cell. +------+--------+------+ | | | | | NW | North | NE | | | | | +------+--------+------+ | | | | | West | Centre | East | | | | | +------+--------+------+ | | | | | SW | South | SE | | | | | +------+--------+------+ The following rules have been implemented in this release of the simulator. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- ANNEAL The behaviour of this rule is similar to thermodynamic annealing. state | old new | reason --------+---------------------------- 0 1 | 4,6,7,8,9 active neighbours 1 0 | 0,1,2,3,5 active neighbours -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- BRIANS_BRAIN state | old new | reason --------+------------------------------------ 0 1 | exactly 2 neighbours are in state 1 1 2 | always 2 0 | always -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- CODD +---+ | 1 | +---+---+---+ +---+ | 0 | 1 | 1 | -> | 0 | +---+---+---+ +---+ | 0 | +---+ +---+ | 0 | +---+---+---+ +---+ | 1 | 0 | 1 | -> | 1 | +---+---+---+ +---+ | 1 | +---+ +---+ | 1 | +---+---+---+ +---+ | 1 | 0 | 1 | -> | 1 | +---+---+---+ +---+ | 1 | +---+ -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- DIAMONDS new state = North or East or South or West -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 4 WAY FILL state | old new | reason --------+--------------------------------------------- 0 2 | if North, East, South or west are in state 2 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 8 WAY FILL state | old new | reason --------+---------------------------------------- 0 2 | if any of the neighbours are in state 2 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- GRAVITY state | old new | reason --------------+------------------------ 0 North | always Centre 0 | if south neighbour is 0 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- GROWTH state | old new | reason --------+--------------------------------- 0 1 | if the number of neighbours is 0 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- HGLASS A random-ish rule which uses this lookup table: EWSNC C' |EWSNC C' |EWSNC C' |EWSNC C' | ---------+---------+---------+---------+ 00000 0 |01000 0 |10000 1 |10000 1 | 00001 1 |01001 1 |10001 1 |10001 0 | 00010 1 |01010 0 |10010 1 |10010 0 | 00011 1 |01011 1 |10011 0 |10011 1 | 00100 1 |01100 1 |10100 0 |10100 0 | 00101 0 |01101 0 |10101 0 |10101 1 | 00110 0 |01110 1 |10110 0 |10110 0 | 00111 0 |01111 1 |10111 0 |10111 1 | where C' represents the new state of the cell. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- LICHENS state | old new | reason --------+---------------------------------------- 0 1 | if the number of neighbours is 3,7 or 8 1 0 | if the number of neighbours is 4 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- LIFE Conways classic game of life. I'm using state 2 to show that the cell has survived. state | old new | reason --------+---------------------------------------- 0 1 | if the (number of neighbours) is 3 1 2 | if the (number of neighbours) is 2 or 3 C 0 | otherwise -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- MAJORITY state | old new | reason --------+------------------------------------------ 0 1 | if the (number of neighbours)+self is > 4 1 0 | if the (number of neighbours)+self is < 5 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- PARITY new state = North xor East xor South xor West -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- SQUARES new state = North or NE or East or SE or South or SW or West or NW -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- TRIANGLES new state = North or East or West -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- TUBE_WORM state | old new | reason ------------|---------------------------------------------- 0 ALARM | if a neighbour is in alarm state. 0 ALARM | if the number of active neighbours >threshold C C-1 | otherwise -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- TUBE_WORM_2 state | old new | reason ------------|---------------------------------------------- 0 ALARM+n | if n neighbours are in alarm state. 0 ALARM | if the number of active neighbours >threshold C C-1 | otherwise Of the rules above I think that life, brains brin, lichens and anneal are the most interesting. Im sure that there are more rules and If you know of any contact me and Ill put it in. BUGS I expect there are a few lurking bugs in the program. Ive tried to remove as many as possible and have had little problems using the software. But then every author says the same. Linux users will get seg faults. Although SUIT has been ported there, Ive had lots of problems and although it compiles, it seg faults every time when using the GP_ colour routines. The system I compiled the software on was a SPARCstation IPC, running SunOS Release 4.1.1. I compiled using gcc 2.2.2 with SUIT libraries version 2.3. I've tried as much as possible to use ANSI C, I am unlikely to be able to solve any compilation problems that you may have. If you have a problem compiling SUIT then please get in contact with SUIT support. Similarly I can't guarantee to fix any bug-reports I might get. Although as a budding software engineer (so I've been told) I guess I should make sure my software is as free from bugs as possible. TODO If I had the time I would do the following things: Allow importing/exporting of cells, into the automata. Set/clear/move an area of the automata, Allow user defined automata rules, Give some online help. Provide a playback facility. Provide a "print" facility. MANIFEST In addition to this man page,You should have received the following files in this distribution src/Imakefile src/LICENSE src/abort.c src/abort.h src/assorted.c src/assorted.h src/auto.c src/auto.h src/automata.c src/automata.h src/callback.c src/callback.h src/colorbar.c src/colorbar.h src/files.c src/files.h src/main.c src/main.h src/methods.c src/methods.h src/neighbours.c src/neighbours.h src/rules.c src/rules.h doc/auto.1 examples/3statecycle.auto examples/colorful.auto examples/crash.auto examples/fred.auto examples/fred2.auto examples/glider.auto examples/life.auto examples/wierd.auto examples/brian.auto examples/brian_arrow.auto examples/codd.auto examples/fill.auto examples/fill2.auto examples/glider_gun.auto examples/glider_gun2_brian.auto examples/glider_gun_brian.auto examples/gun.auto examples/spaceship_life.auto examples/spectrum_loader.auto These files are archived using tar and compressed using GNU's gzip. You will need gzip to uncompress the tar file and can get it from most good ftp sites. FILE FORMAT The *.auto files are examples of cellular automata files that are used by this application. It uses a weird format that I dreamt up, mainly because I didn't look around for other suitable file formats. The first line in the file must start with the string "Cellular automata file" This is how the program knows that it has the right type of file Cellular automata file The next 3 lines declare the number of rows, columns and states of the automata. 5 rows 9 columns 3 states and finally an array of states in rows x cols format. DISCLAIMER The software 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 this program (LICENSE) ; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. SUIT SUIT -- The Simple User Interface Toolkit SUIT is a library of interface tools developed at the University of Virginia to help C programmers create sophisticated mouse based interfaces without the lengthy learning period associated with traditional user interface toolkits. Ease of learning and fast ramp up time is central to SUIT's design. Also central to SUIT design is portability. SUIT programs currently run without changes to the source code on the following platforms: IBM PC, Macintosh, Sun3, Sun4 (SparcStation), SGI (Silicon Graphics IRIS workstations), DECstation, HP. SUIT is available through anonymous ftp from uvacs.cs.virginia.edu (128.143.8.100). Each SUIT distribution package comes with full source code and documentation. SUIT, including all its source code, is available without charge to Universities and other non-profit institutions. For-profit organizations, and people requiring more information can send email to suit@uvacs.cs.virginia.edu SUIT (c) 1990, 1991 , 1992 Copyright Rector and Visitors of the University of Virginia automata() MISC. REFERENCE MANUAL PAGES automata() THANKS Thanks go to the people who created SUIT. Without them I probably wouldn't have bothered writing this SUIT application. Thanks also go to the Joint Network Team at the Rutherford Appleton Laboratory for teaching me C. I must thank Laser Scan Ltd, for giving me 2 excellent placements and giving me a taste of the real world. How can I not mention the people at Robert Fleming Ltd for unknowingly starting me out on the computing trail. If as a result of using this application, you feel that I have some potential, and you happen to have an opening in your company. I'll be graduating in BSc Computer Science in about August 1993 and wouldn't mind getting a job overseas. THE AUTHOR My current email address is cs89ssg@uk.ac.brunel. This certainly will not be the case after July 1993. I am likely to have an account on at least a public access unix site so I should be contactable via newsgroups after this date.