A Simple Game of Life in Java

The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in
1970. It is the best-known example of a cellular automaton.

The “game” is a zero-player game, meaning that its evolution is determined by its initial state, needing no
input from human players. One interacts with the Game of Life by creating an initial configuration and
observing how it evolves.

Rules in the game of life

For a space that is ‘populated':

  • Each cell with one or no neighbors dies, as if by loneliness.
  • Each cell with four or more neighbors dies, as if by overpopulation.
  • Each cell with two or three neighbors survives.

For a space that is ‘empty’ or ‘unpopulated’

  • Each cell with three neighbors becomes populated.

You can download my simple implementation of Game of Life in Java. You can open the project in Netbeans or you can just copy the src directory and edit them in your own if you don’t have Netbeans or you don’t want to use Netbeans.

The source code consists of the following classes:

  • Cell.java -This class is responsible for representing a single cell in the game of life. The following are the states that it has to keep track of and its responsibilities: (1) Keeps track of its state (dead or alive), (2) Keeps track of its neighbors, and (3) Identifies if it will live or die in the next iteration given knowledge of its neighbors
  • CellWorld.java – This class is responsible for keeping track of the world where all cells reside. The following are the state that it has to keep track of and its responsibilities: (1) Keeps track of all cells existing in the world, (2) When the CellWorld is created, the number of rows and columns in the world are provided and a Cell is placed in each location in the world, (3) The state of a specific Cell in the world can be set. (4)  The CellWorld can be asked to take a single step of iteration which will inform all cells of their neighbors and update their states causing them to either live or die.
  • CellWorldCanvas.java – This class is a CellWorld representation in a Java Canvas.  The CellWorld knows to draw itself.
  • GameOfLife.java – This is the runner class. The main method resides here.

Here is an example screenshot of the program with 9 generations (read pictures from left to right):

Cyrus Game of Life in Java

Cyrus Game of Life in Java

Enjoy playing the Game of Life.

Finite State Transduction and Formal Machines

Finite state transducers (FST) are often used for computational analysis in natural languages processing research and applications such as morphology, phonology, text to speech, and data mining. It is simple, well understood mathematically, easy to implement and an efficient solution but not every problem has a finite state solution (Blackburn and Striegnitz, 2002).

Hancox (1996) defines transducer as a piece of software that maps one stream of symbols on to another stream of symbols. It means that the program translates one stream of symbols into another. Transducers are basically Mealy’s automata mentioned by Hopcroft and Ullman (1979) emphasized by Daciuk (1998). An FST is a finite state automaton that works on two tapes. It is a kind of translating machine that reads from one of the tapes and writes on the other. It can be used in different modes: translation, generation and recognition. In the generation mode, transducers write on both tapes and in the recognition mode they read from both tapes. Direction of the translation can be from left to right or right to left. Figure 2 shows the transducer that translates aS to bS and Table 1 list its different mode definition (Blackburn and Striegnitz, 2002)… [Download the complete article.]

Programming Languages

People can understand each other because they communicate using a common language. Language serves as their medium of communication.  The world has a ton of languages that pertains to a certain country, region or continent of the world.  For example, Filipino and English are the official languages of the Philippines and it has approximately 175 languages (Gordon, 2005).  Computer, too, has different programming languages that you can use for a specific area of computing.  Learning programming languages will develop the ability to write and translate computer programs in certain areas of computing. According to Aaby (1996), a programming language is a notation for writing programs. It includes the computational model, the syntax and semantics of programs, and the pragmatic considerations that shape the language. The first programming language predates the computer and it was only codes.  Ada Lovelace, the first computer programmer, translated Italian mathematician Luigi Menabrea’s memoir on Charles Babbage’s difference engine, the Analytical Engine during the nine-month period in 1842-1843. In her article, she appended a detailed method for calculating Bernoulli numbers with the Engine. It was recognized by historians as the world’s first computer program.  After Babbage’s difference engine, Jacquard Loom used holes in punched cards to represent sewing loom arm movements in order to generate decorative patterns automatically (Sammet, 1969).  Plankalkul, the first high level language was developed by the German scientist Konrad Zuse.  The name Plankalkul means program calculus expressing computations.  It was a project he had begun in 1943 as a proposal for his Ph. D. dissertation.  In 1945, he wrote algorithms in the language for a wide variety of problems (Sebesta, 2005).

Computer can only understand and execute a programming language that is written in its own native binary machine code, the machine language.  Machine language is the lowest possible programming language that a computer program can be written.  The other levels of programming languages are said to be high and low levels and they can be resembled to the machine language.

Machine languages are also known as the first generation language or 1GL.  Writing a program in the machine language is difficult because it is hard to find and identify an error in the lines of the program once you made a mistake.  The programs written in machine language are composed of strings of 1’s and 0’s and are stored in a binary numbers.  Low level language is the language one higher from the machine language.  This language is easier than a machine language because it is a symbolic represented language rather than 0’s and 1’s and allows symbolic resignation of memory.   Assembly language is an example of the low level language.  This language is translated into machine code using a program called assembler.  Lastly, high level languages are languages closest to human languages.  It also permits faster development of large programs.  On the other hand, high level languages are languages called fourth generation language or 4GL.  They can be converted to a machine language in two ways: compile the program using a compiler program or interpret the program using an interpreter program.  C++ and Scheme are examples of a compiled and an interpreted programming language (Bigelow, 1996).

Hasan (1997) stated that a paradigm is a fundamental of high level model of a computation – ignoring information such as what data or control structures are available, exactly how variables are passed to procedures and etc.  According to Sebesta (2005), programming languages are categorized into four: imperative, functional, logic, and object-oriented.  Imperative programming is also known as procedural programming.  Imperative programming specifies the steps the program must take to reach the desired state.  It is a programming paradigm based on a procedure call.  It is often a better alternative than unstructured programming in many situations because it is easier to maintain and it is not a complex to write than the latter (IEEE, 2008).  In contrast with the imperative programming style, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes on application of functions while imperative programming gives emphasize on the changes of state (Hudak, 1989).  The use of mathematical logic for computer programming is called logic programming. It is a rule-based language in which rules are specified in no particular order, and the language implementation system must choose an execution order that produces the desired result (Sebesta, 2005).  Object-oriented programming or OOP is a programming paradigm that uses objects and their interactions to design applications and computer programs.  An OOP language must include the features such as encapsulation, modularity, polymorphism, and inheritance. Many modern programming languages now support OOP (Kay, 2008). Studying programming languages enables the programmer to decide what is appropriate for a certain application that will work efficiently.

Computers have been applied to different areas: from controlling nuclear power plants to providing video games in mobile phones.  Programming languages are developed with different goals.  They are designed to solve a specific kind of problem.  Programming languages are associated with the areas of computer applications such as business applications, web software and applications, artificial intelligence, and systems programming. Spreadsheets systems and database systems are common applications in business applications that are widely used, in both homes and business.  They can be used on small computers and developed for business.  There are also programming languages that were designed to suit web software or applications.  To make the World Wide Web or WWW dynamic and interactive, small applications like applet in Java, audio and video are embedded in the web with the use of the scripting languages and server-side languages.  Programming languages can be also applied in artificial intelligence. Making games intelligent as humans and making an editor intelligent that suggests the correct spelling of what you are trying to type.   There are also programming languages designed and developed used to write systems software.  System software refers to the support software of an operation system.  The language for this domain must provide fast execution.  Furthermore, it must have low-level features that allow the software interfaces to external device to be written (Sebesta, 2005).

The history of programming languages has evolved from a primitive one to supporting complicated ideas to express instruction to the computers. This is also evident in the level of programming languages which starts from machine code to high level programming languages, as Bigelow (1996) classified it as machine level, low level or high level programming languages. The four bins category stated by Sebesta (2005) indicates the design of languages to specific area of computing. Sebesta (2005) also explained that programming languages are developed with different goals and these are associated to the areas of computer applications such as in business, web, artificial intelligence, and systems programming. Sebesta (2005) also explained that programming languages are developed with different goals and these are associated to the areas of computer applications such as in business, web, artificial intelligence, and systems programming. Programming languages make computer program easier to write. Its primary reason is to make it easier for people to read and understand programs. Looking through the evolution of programming languages, it is the desire to reduce errors by removing the tedious aspects of programming. Having programming languages was also the need to be able to share one’s code with peers, and to enable other people to maintain it. This meant that a coder needed to be able to express their intent in the code, as well as implement the appropriate algorithms that met the application’s requirements. Studying concepts of programming languages can also increase the ability to learn new languages.

References
Aaby, A. A. (1996). Introduction to programming languages. Retrieved August 1, 2008 from the World Wide Web:  ftp://ftp.blackcube.org/pub/burks.bton.ac.uk_burks_software/burks/
pcinfo/progdocs/plbook/index.htm.

Bigelow, K. (1996). Levels of programming languages.  Retrieved August 1, 2008 from the World Wide Web:  http://www.play-hookey.com/computers/language_levels.html.

Gordon, R. G., Jr. (2005). Ethnologue: Languages of the world (15th ed.). Retrieved August 1, 2008 from the World Wide Web:  http://www.ethnologue.com/show_country.asp?name=PH.

Hasan, H. (1997, July). Paradigms of programming languages. Retrieved August 6, 2008 from the World Wide Web:   http://www.uow.edu.au/~hasan/buss930/prog/paradigm.htm.

Hudak, P. (1989, September). Conception, evolution, and application of functional programming languages. New York:  ACM.

IEEE (2008). Use of procedural programming languages for controlling production systems. Retrieved August 13, 2008 from the World Wide Web: http://ieeexplore.ieee.org/xpl/ freeabs_all.jsp?arnumber=120848.

Kay, A. (2003). On the meaning of object-oriented programming. Retrieved August 13, 2008 from the World Wide Web:  http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/
doc_kay_oop_en

Sammet, J. E. (1969). Programming languages: History and fundamentals. Upper Saddle River,  New  Jersey:  Prentice-Hall.

Sebesta, R. W. (2005). Concepts of programming languages (7th ed.). Boston:  Pearson Education, Inc.

Hybrid theme works perfectly on my Linux Box

My Fedora 8 looks very Mac now.  I customized it with two different  Macintosh themes for Linux. I experimented and only selected some of the features that will perfectly suit on my Gnome 2.20.2.

I combined Mac4Lin by Anirudh Acharya and Leopardish. These are great themes but they get you frustrated sometimes because of its few incompatibilities.

Here are some sample screenshots:

XPath Checker Y Regular Expression Tester

XPath checker and regular expression tester are both plugins.

I know that some of you are familiar with these two things and some of you are not. For this past month I have been using these plugins and these are also my favorites. They are really useful in terms of time and efficiency.

Let me explain these things to you.

XPath Checker is a Firefox Extension for testing XPath expressions interactively written by Brian Slesinsky. It is also like a regular expressions for web pages. XPath make it easy to extract content from deeply nested markup in a web page or an XML document. This would be useful in unit-testing code that generates XML or HTML.

Here are examples of xpath expressions:

Get the title of a page:
//title/text()

List all the images on a page:
//img

List the images that are inside a link:
//a//img

List the images that have alt tags:
//img[@alt]

List the images that don’t have alt tags:
//img[not(@alt)]

Show all the alt tags:
//img/@alt

Show the href for every link:
//a/@href

Get an element with a particular CSS id:
//*[@id='mainContent']

REGULAR EXPRESSION tester is simply a tester for regular expressions on the fly. It is a plugin for your Eclipse especially you are dealing different patterns.

These two are small but powerful tools in programming. These are also my favorites and I wish you will find it useful and helpful than doing your own parsers in a weeks or in a months.

Features

  • Test and search for regular expression
  • Matches are colorized, for an easy visual clue
  • Support for pattern flags (e.g. Pattern.DOTALL)
  • LiveEval evaluates your regular expression while you are typing it, gives feedback on possible errors and shows any matches automatically
  • LiveEval is supported for changes of the regular expression, the search text and the pattern flags
  • 4 distinct match modes:
    • Find a sequence of characters
    • Match a complete text
    • Split text
    • Replace every occurence of the regex with a different string
      Replacing supports back references ($1,$2,…)
  • LiveEval for match mode changes
  • Context sensitive “Regular Expression Assist”
  • Selective evaluation of expressions
  • Bracket Matching
  • Generation of string literals based on the regexp, e.g. “\(x\)” becomes “\\(x\\)”
  • De-escape patterns in your code, e.g. \\(x\\) becomes \(x\)
  • Improved “Clear Menu”, choose which parts of the view you would like to get cleared every time you press the clear button
  • Easy movement through matches: Choose “Previous Match” or “Next Match” and cycle through all matches found.
  • Polished and accessible user interface, everything is reachable via keyboard

How to configure GWT 1.4 on Fedora 8?

Installing GWT 1.4 in Fedora 8 is very simple.

Just download GWT 1.4 for Linux from Google and extract it to your home directory. After you extracted it, you can simply test it if this will work well in your system.

Basically to create a new application without using eclipse,

applicationCreator com.sample.client.HelloWorld

After creating the application we tried to run it. There are two ways to execute the application, in the web mode and in the hosted mode.

In web mode, we compile it first and execute the code

sh HelloWorld-compile

And this should run successfully.

How about running the application in the hosted mode?

sh HelloWorld-shell

In Fedora 8 this should run with errors. It says like,

** Unable to load Mozilla for hosted mode **
java.lang.UnsatisfiedLinkError: /home/Cyrus/gwt-linux-1.4.60/mozilla-1.7.12/libxpcom.so: libstdc++.so.5: cannot open shared object file: No such file or directory

Here is the explanation,

“Fedora 8 ships and uses GCC 4.1. Some applications that were compiled with an older GCC (ex: 3.2) will require compatibility libraries. Make sure to have the following RPM’s installed.

These are NOT included with the Fedora 8 DVD and must be downloaded online (ftp, yum, etc).”

The solution is to install them in your distro.

su -c 'yum -y install compat-libstdc++-33 compat-libstdc++-296'

Good! Try to run your application again in host mode. It will smoothly run then.

Accessing Linux’s ext2 and ext3 filesystems from your Windows box

To give you an example, let’s say, I have a dual-booted PC installed with Windows and Linux operating system.  I can easily access my ntfs files on my linux distro and how could I do that in reverse on my Windows operating system either?

Explore2fs solves the problem. It is a WIN32 explorer for Linux ext2fs partitions by John Newbigin that can read ext2 and ext3 linux’s filesystems from your Windows.

Explore2fs was originally written for Windows NT and now it supports the various releases of Windows:

  • Windows 95
  • Windows 98
  • Windows 98SE
  • Windows ME
  • Windows NT 4.0
  • Windows 2000
  • Windows XP
  • Windows XP SP2
  • Windows Server 2003

The latest version also supports the following features:

  • Reads ext2
  • Reads ext3
  • Drag & Drop
  • 1.44Meg Floppy Disk Support
  • LS120 Floppy Disk Support
  • ZIP & Jazz Disk Support
  • USB & CF Disk Support
  • CDROM Support
  • Supports Windows 98 extended partition scheme
  • Export files as binary
  • Export files as text
  • Export directory
  • View/Execute file
  • Large disk support
  • Large file support
  • LVM2
  • ReiserFS Detection
  • Unicode UTF8 support
  • Preserve time stamps on export

Try and download it here.

Last Update: June 5, 2010