You are on page 1of 7

TITLE A Design Problem

Submitted By: Submitted To: Anil umar Avinash aur Roll no:b16 Reg no: 11002119 Sec no: 2r02

CONTENTS: 1. Problem statement Q1. Design a script for playing Game of Life. The Game of Life is implementation of cellular automata. On rectangular grids, let each cell be either living or dead. Designate a living cell with a dot, and a dead one with blan space. Begin with arbitrarily drawn dot-and-blan grid, and let this be the starting ge neration 0. Determine each successive generation by following rules: 1) Each cell has 8 neighbours, the adjoining cells left, right, top, bottom and 4 diagonals. 123 4*5 the * is the cell under consideratio n 678 2) A living cell with 2 or 3 living neighbours alive. SURVIVE=2 3) A dead cell with 3 living neighbours come alive, a birth BIRTH=3 4) All other cases result in a dead cell for the next generation

2. Prerequisite nowledge set: What is the game of life: The Game of Life (or simply Life) is not a game in the conventional sense. There are no players, and no winning or losing. Once the "pieces" are placed in the s tarting position, the rules determine everything that happens later. Nevertheles s, Life is full of surprises! In most cases, it is impossible to loo at a start ing position (or pattern) and see what will happen in the future. The only way t o find out is to follow the rules of the game. Why is Life So Interesting?:-Life is one of the simplest examples of what is sometimes called "emergent compl exity" or "self-organizing systems." This subject area has captured the attentio n of scientists and mathematicians in diverse fields. It is the study of how ela borate patterns and behaviors can emerge from very simple rules. It helps us und

erstand, for example, how the petals on a rose or the stripes on a zebra can ari se from a tissue of living cells growing together. It can even help us understan d the diversity of life that has evolved on earth. cellular automaton: Several methods are nown for defining cellular automata rules that are reversib le; these include the bloc cellular automaton method, in which each update part itions the cells into bloc s and applies an invertible function separately to ea ch bloc , and the second-order cellular automaton method, in which the update ru le combines states from two previous steps of the automaton. However, for cellul ar automata that are not defined by these methods, on arrays of two or more dime nsions, testing reversibility is undecidable. Reversible cellular automata form a natural model of reversible computing, a tec hnology that could lead to ultra-low-power computing devices. Quantum cellular a utomata, one way of performing computations using the principles of quantum mech anics, are often required to be reversible. Additionally, many problems in physi cal modeling, such as the motion of particles in an ideal gas or the Ising model of alignment of magnetic charges, are naturally reversible and can be modeled b y reversible cellular automata. 3. Designed Methodology Design Methods is a broad area that focuses on: Divergence Exploring possibilities and constraints of inherited situations by ap plying critical thin ing through qualitative and quantitative research methods t o create new understanding (problem space) toward better design solutions Transformation Redefining specifications of design solutions which can lead to b etter guidelines for traditional and contemporary design activities (architectur e, graphic, industrial, information, interaction, et al.) and/or multidisciplina ry response Convergence Prototyping possible scenarios for better design solutions that incr ementally or significantly improve the originally inherited situation Sustainability Managing the process of exploring, redefining and prototyping of design solutions continually over time Articulation - the visual relationship between the parts and the whole. 3.2. Designed Code:-startfile=gen0 // Read the starting generation from the file "gen0". Default, if no other file specified when invo ing script. // // Specify another "generation 0" file.//

if [ -n "$1" ] then if [ -e "$1" ] // Chec for existence.// then startfile="$1" fi fi ALIVE1=0 DEAD1=0 ROWS=10 COLS=10 GENERATIONS=10 NONE_ALIVE=80 TRUE=0 FALSE=1 ALIVE=0 DEAD=1

avar= 0

generation=0

let "cells = $ROWS * $COLS" declare -a initial declare -a current display () { alive=0 ro.// //How many cells "alive" at any given time Initially ze // Arrays containing "cells".//

declare -a arr arr=( echo "$1" ) element_count=${#arr[*]}

for ((i=0; i<$element_count; i++)) do # Insert newline at end of each row. let "rowchec = $i % COLS" if [ "$rowchec " -eq 0 ] then echo # Newline. echo -n " " # Indent. fi cell=${arr[i]} if [ "$cell" = . ] then let "alive += 1" fi echo -n "$cell" | sed -e s/_/ /g # Print out array and change underscores to spaces. done return } IsValid () { if [ -z "$1" -o -z "$2" ] then return $FALSE fi local local local local local row lower_limit=0 upper_limit left right # Test whether cell coordinate valid. # Mandatory arguments missing?

local i local rowchec

# Disallow negative coordinate.

let "upper_limit = $ROWS * $COLS - 1" # Total number of cells. if [ "$1" -lt "$lower_limit" -o "$1" -gt "$upper_limit" ] then return $FALSE # Out of array bounds. fi row=$2 let "left = $row * $COLS" let "right = $left + $COLS - 1" # Left limit. # Right limit.

if [ "$1" -lt "$left" -o "$1" -gt "$right" ] then return $FALSE # Beyond row boundary. fi return $TRUE } IsAlive () { GetCount "$1" $2 local nhbd=$? # Test whether cell is alive. # Ta es array, cell number, state of cell as arguments. # Get alive cell count in neighborhood. # Valid coordinate.

if [ "$nhbd" -eq "$BIRTH" ] # Alive in any case. then return $ALIVE fi if [ "$3" = "." -a "$nhbd" -eq "$SURVIVE" ] then # Alive only if previously alive. return $ALIVE fi return $DEAD } # Default.

{ local local local local local local local local local local cell_number=$2 array top center bottom r row i t_top t_cen

GetCount ()

# # # #

Count live cells in passed cell s neighborhood. Two arguments needed: $1) variable holding array $2) cell number

local t_bot local count=0 local ROW_NHBD=3

let let let let

"top = $cell_number - $COLS - 1" # Set up cell neighborhood. "center = $cell_number - 1" "bottom = $cell_number + $COLS - 1" "r = $cell_number / $COLS" # Traverse from left to right.

for ((i=0; i<$ROW_NHBD; i++)) do let "t_top = $top + $i" let "t_cen = $center + $i" let "t_bot = $bottom + $i"

let "row = $r" # Count center row of neighborhood. IsValid $t_cen $row # Valid cell position? if [ $? -eq "$TRUE" ] then if [ ${array[$t_cen]} = "$ALIVE1" ] # Is it alive? then # Yes? let "count += 1" # Increment count. fi fi let "row = $r - 1" # Count top row. IsValid $t_top $row if [ $? -eq "$TRUE" ] then if [ ${array[$t_top]} = "$ALIVE1" ] then let "count += 1" fi fi let "row = $r + 1" # Count bottom row. IsValid $t_bot $row if [ $? -eq "$TRUE" ] then if [ ${array[$t_bot]} = "$ALIVE1" ] then let "count += 1" fi fi done if [ ${array[$cell_number]} = "$ALIVE1" ] then let "count -= 1" fi return $count } next_gen ()

array=( echo "$1"

{ local array local i=0

while [ "$i" -lt "$cells" ] do IsAlive "$1" $i ${array[$i]} if [ $? -eq "$ALIVE" ] then array[$i]=. else array[$i]="_" fi let "i += 1" done

# let "generation += 1" # Increment generation count. # Why was the above line commented out? # Set variable to pass as parameter to "display" function. avar= echo ${array[@]} # Convert array bac to string variable. display "$avar" # Display it. echo; echo echo "Generation $generation - $alive alive" if [ "$alive" -eq 0 ] then echo echo "Premature exit: no more cells alive!" exit $NONE_ALIVE # No point in continuing fi #+ if no live cells. } # ========================================================= # main () # Load initial array with contents of startup file. initial=( cat "$startfile" | sed -e /#/d | tr -d \n |\ sed -e s/\./\. /g -e s/_/_ /g ) clear echo echo echo echo echo echo # Clear screen. # Title "=======================" " $GENERATIONS generations" " of" "\"Life in the Slow Lane\"" "======================="

# -------- Display first generation. -------Gen0= echo ${initial[@]}

array=( echo "$1"

# Convert passed arg to array.

# Is cell alive? # If alive, then #+ represent the cell as a period. # Otherwise underscore #+ (which will later be converted to space).

display "$Gen0" # Display only. echo; echo echo "Generation $generation - $alive alive" # ------------------------------------------let "generation += 1" echo # Increment generation count.

# ------- Display second generation. ------Cur= echo ${initial[@]} next_gen "$Cur" # Update & display. let "generation += 1" # Increment generation count. # ------ Main loop for displaying subsequent generations -----while [ "$generation" -le "$GENERATIONS" ] do Cur="$avar" next_gen "$Cur" let "generation += 1" done echoexit limitation of error: there is no limitation of error. 4. List of refrences: Searches are made from the web sites: www.wi ipedia.com www.as .com

You might also like