Tic-Tac-Toe Game Programming with Perl Module Gamestictactoe

Tic Tac Toe game can be also programmed with the perl module from CPAN. Only a few line of code and the game is ready to play. How it can be done?

First assuming the perl is already installed and this is a Windows operating system type ppm from command prompt. This will open Perl Package Manager. Find Games-TicTacToe module and install it using PPM program.

Now you can create the perl script as following:

use strict;
use warnings;
use Games::TicTacToe;
my $tictactoe = Games::TicTacToe->new();
$tictactoe->addPlayer();
while (!$tictactoe->isGameOver())
{ $tictactoe->play(); }

This perl script can be used from command prompt. Here is the example of the screen:

C:\>perl ttt_cpan_console_game.cgi
Please select the player [H – Human, C – Computer]:H
Please select the symbol [X / O]: X
What is your next move [1,2,3,4,5,6,7,8,9]? 3
What is your next move [1,2,4,6,7,8,9]? 1
What is your next move [4,6,7,8,9]? 1
Please make a valid move [4,6,7,8,9]: 6
+———–+
| TicTacToe|
+—+—+—+
| X | O | X |
+—+—+—+
| 4 | O | X |
+—+—+—+
| 7 | O | 9 |
+—+—+—+
Congratulation, Computer won the game. Since it is not easy to convert numbers into 2-dimensional board here is the some modification where the board is showed after each move – so it is easy to choose the number.

use Games::TicTacToe;
my $tictactoe = Games::TicTacToe->new();
$tictactoe->addPlayer();
while (!$tictactoe->isGameOver())
{ $tictactoe->play();
print $tictactoe->{‘board’}->as_string();
}

You can also use print $tictactoe->getGameBoard(); to print the board.
Here is the example of screen:
C:\>perl ttt_cpan_console_game_simple2.cgi
Please select the player [H – Human, C – Computer]: H
Please select the symbol [X / O]: X
What is your next move [1,2,3,4,5,6,7,8,9]? 3
+———–+
| TicTacToe |
+—+—+—+
| 1 | 2 | X |
+—+—+—+
| 4 | 5 | 6 |
+—+—+—+
| 7 | 8 | 9 |
+—+—+—+
+———–+
| TicTacToe |
+—+—+—+
| 1 | 2 | X |
+—+—+—+
| 4 | O | 6 |
+—+—+—+
| 7 | 8 | 9 |
+—+—+—+
What is your next move [1,2,4,6,7,8,9]? 2
+———–+
| TicTacToe |
+—+—+—+
| 1 | X | X |
+—+—+—+
| 4 | O | 6 |
+—+—+—+
| 7 | 8 | 9 |
+—+—+—+
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| 4 | O | 6 |
+—+—+—+
| 7 | 8 | 9 |
+—+—+—+
What is your next move [4,6,7,8,9]? 9
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| 4 | O | 6 |
+—+—+—+
| 7 | 8 | X |
+—+—+—+
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| 4 | O | O |
+—+—+—+
| 7 | 8 | X |
+—+—+—+
What is your next move [4,7,8]? 4
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| X | O | O |
+—+—+—+
| 7 | 8 | X |
+—+—+—+
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| X | O | O |
+—+—+—+
| O | 8 | X |
+—+—+—+
What is your next move [8]? 8
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| X | O | O |
+—+—+—+
| O | X | X |
+—+—+—+
+———–+
| TicTacToe |
+—+—+—+
| O | X | X |
+—+—+—+
| X | O | O |
+—+—+—+
| O | X | X |
+—+—+—+
Game drawn !!!
So only a few lines are needed to create game with CPAN perl module Games::TicTacToe.
However this only 3 by 3 game. Also this is a console based game where the user is playing against computer by entering the moves through answering the questions. Any suggestions, comments and ideas how to make this game web based are welcome.

Tag Cloud with Perl Script

A tag cloud or word cloud is one more way to put navigation on web site. There are different ways to create tag cloud. [1] For example collocate cloud can be found at scottishcorpus.ac.uk website [2]. From Wikipedia “a collocate cloud provides a more focused view of a document or corpus. Instead of summarizing an entire document, the collocate cloud examines the usage of a particular word. The resulting cloud contains the words which are often used in conjunction with the search word.” [1]

The post in the blog [3] describes second generation of tag clouds and the trend for the future. Looks like tag clouds will stay here and will get more complicated, useful, powerful, dynamic and with more different features.

Having your own script to generate tag cloud provides more flexibility and power in creating tag cloud and automating posting/updating it on the web. Thus I created some perl script, online demo and service for tag cloud. In the future it will be updated with more features like different colors, automatic updates and other features. You can find it at Tag Cloud Generator Please fill free to provide any feedback or suggest features to add.

[1] From Wikipedia, the free encyclopedia

[2] Collocate cloud

[3] Second Generation Tag Clouds by Joe Lamantia.com

Artificial Intelligence

Artificial Intelligence (AI) may be the section of information technology concentrating on creating machines that may engage on actions that humans consider intelligent. It’s the cutting-fringe of information technology.This generally involves borrowing qualities from human intelligence, and using them as calculations inside a computer friendly way. A pretty much flexible or efficient approach could be taken with respect to the needs established, which influences how artificial the intelligent behavior seems.

The opportunity to create intelligent machines has intrigued humans since ancient occasions, now using the creation of the PC and half a century of research into AI programming techniques, the imagine wise machines has become a real possibility. Scientists are coming up with systems which could mimic human thought, understand speech, beat the very best human chess player, and numerous other achievements nothing you’ve seen prior possible.

Applications of Artificial Intelligence It’s the key technology in lots of present day novel programs, varying from banking systems that identify attempted charge card fraud, to telephone that understand speech, to software systems that notice when you are getting problems and provide appropriate advice. These technologies wouldn’t exist today with no sustained federal support of fundamental AI research in the last 30 years.

Today, the most popular section of artificial intelligence is neural systems, that are showing effective in many disciplines for example voice recognition and natural-language processing. In robotics, computer systems are actually broadly utilized in set up plants, but they’re capable only of limited tasks with the substitute intelligence factor. Robots have great difficulty determining objects according to appearance or feel, plus they still move and take care of objects clumsily.

Presently, no computer systems exhibit full artificial intelligence (that’s, can simulate human behavior). The finest advances have happened within the area of games playing.

Benefits of Artificial Intelligence Artificial intelligence wouldn’t need any sleep. This is a benefit because it wouldn’t be interrupted from the tasks for sleep, along with other problems that plague biological minds like bathroom breaks and eating.

Unemotional thought on problems. While a man-made mind could theoretically have feelings, it might be better for performance whether it were designed for unemotional reasoning. When individuals make choices, sometimes individuals choices derive from emotion instead of logic. This isn’t always the easiest method to make choices. Once a man-made thoughts are been trained in an activity, that mind may then be replicated effortlessly, in comparison towards the training of multiple people for the similar task. Less errors and defects, reduced time and assets.

Disadvantages of Artificial Intelligence Lacks a persons touch. Human characteristics are occasionally overlooked. The opportunity to replace an individual job. This brings about humans feeling insecure and could possess the anxiety about losing their job. Human abilities could be changed utilizing a machine and for that reason can promote feelings of inferiority among employees and staff. Artificial Intelligence can malfunction. This kind of technology could be misused to result in mass scale destruction

General Regression Neural Networks

General Regression Neural Networks (GRNN) is one of the type of neural networks with a one pass learning algorithm. The simplicity of algorithm for GRNN is one of the advantage of this neural network and many researchers use it. In one of recent paper was proposed algorithm that is using an ensemble of several General Regression Neural Networks to improve the accuracy of forecasting. [1] In another paper MOPSO algorithm was applied for improvement radial basis function (RDF) which is used also in GRNN [2]

A simple example can explain how GRNN is working. Let’s say several people decided to establish some fund. One contributed $2, another $3 and yet another $100. Now we calculate 2 numbers – one is a sum of dollar amount times the person number :
1*$2+2*$3+3*$100=$306
and another number is just the sum of $ amount:
$2+$3+$100=$105
Now divide 306 / 105 and we get ~ 3
Thus our algorithm calculated top contributor – person number 3. This is exactly what last 2 layers of GRNN are doing.
The output of GRNN is result of division of 2 numbers from 2 nodes of previous layer. Now you probably noticed that in the example above the top contributor ($100 contribution ) was a way ahead of others. The hidden layer in GRNN is responsible for this.

The pattern that is very close to training data will get big value while the other will get very small values. This is what RBF is doing. And the sigma parameter is used to adjust the RBF function output.

This is how GRNN is working. And at minimum it only requires one parameter sigma. Some researchers describe how to apply particle swarm optimization to find optimal number of hidden neurons. And we can use a several network to get even more computing power or better accuracy. Ensemble learning is very well described in [3].

You can find many different ways how to combine 2 or more neural networks. Feel free to grab perl code for GRNN so you can play with it. You can also look at few more data examples and some math. General Regression Neural Networks Thus the forecasting with GRNN is easy and new papers appear that do research on using RGNN

[1] Iffat A. Gheyas, Leslie S. Smith. A Neural Network Approach to Time Series Forecasting, Proceedings of the World Congress on Engineering 2009 Vol II , July 1 – 3, London, U.K.
[2] S.N. Qasem and S.M. Shamsuddin Generalization Improvement of Radial Basis Function Network Based on Multi-Objective Particle Swarm Optimization, Journal of Artificial Intelligence, 2009
[3] http://www.scholarpedia.org/article/Ensemble_learning#Algebraic_combiners

Making Tree Map Chart

In information visualization and computing, treemapping is a method for displaying hierarchical data by using nested rectangles.[1] Below will be discussed some ways how to create tree map chart.

1. Google Code You can create tree map with Google chart tools. The example can be found on Google Code.[2] You can even use code playground link on the same page[2] to enter your data and get tree map. The input of data should be in special format. If you have many records it is hard to change data format manually. However one of the tool from our site – Online tool for generating data string for Google Treemap Chart can convert regular excel (table) format to child – parent value value format.

2. Google DOCS Google spreadsheets support tree map. The creating this type chart is similar like creating any chart in Excel. Put data in spreadsheet, click insert, select chart and then select tree map. Before creating tree map the data also should be converted in special format.[3]

3. JuiceKit for Visual Analytics JuiceKit™ is Software Development Kit and it is available for downloading. Documentation and examples is provided also. JuiceKit is using Adobe Flex to create nice charts. [4]

4. Perl Perl has module for creating tree maps. Here are the simple code example: my $treemap = Gtk2::Ex::TreeMap->new([600,400]); my $values = [6,6,4,3,2,2,1]; $treemap->draw_map_simple($values); You can find more details at [5] There are many other ways to create tree map chart. For the list of treemapping software you can refer to Wikipedia.[6] If you know some easy way how to create tree map chart please feel free to add it here.

[1]. Treemapping Wikipedia, the free encyclopedia
[2]. Google Chart Tools – Visualization: Treemap
[3]. Tree Map
[4]. www.juicekit.org
[5]. Gtk2-Ex-TreeMap on CPAN
[6].List of treemapping software Wikipedia, the free encyclopedia