Ashik’s IT Thoughts

February 27, 2007

Developing Simple Chess Board With Swing in Java SE 6

Filed under: Java — ashikuzzaman @ 4:44 pm

My first professional java project as a software developer was to build a client/server application using Java 2, Swing, RMI and Oracle database. Around 5 years back, it was a small team of 3 developers one project manager and one architect. At that time we used Forte For Java was facsinated how easily I could drag and drop swing components in a palette to build my GUI instead of the AWT way I learnt and taught my students during my Java Teaching career. However, immediately after finishing first few modules, we understood the problems of JFC/Swing components in Java 1.2 . They were so slow that a novice user could identify that and compare with a Visual Basic or C++ GUI application. We had hard time working with JTree and JTable components. But since then Java has crossed JDK 1.3, JDK 1.4 (a major improvement compared to other versions), Java SE 5 and now Java SE 6. While I am working with SWTand Java SE 5in one of my projects in office, I may get into a parallal project on Swing soon. So I thaught to prepare the same chess board using Swing and Java SE 6 and finally came up with this entry. You may compare this with the one that I prototypes using SWT as a practice. To my understanding while both SWT and Swing has its own places, Swing would be a better choice for my next java GUI development due to its intuitive, easy to use API. You dont any java IDE for the program I am going to show you today. However, for advanced GUI design purpose my favorite would be Netbeans 5.5 and as I want to continue using MyEclipse where most of my java projects are configured, I downloaded Matisse4MyEclipse in it.

 

Get tight and follow the steps!

  1. Make sure you have Java installed. I installed Java SE 6 in C:\programs\java\jdk_6
  2. Install Ant 1.6.5 altough you may use command prompt if you dont want to use Ant.
  3. Create project directory at c:\workspace\SwingBoard
  4. Create SwingBoard class under package name com.chess4you.board. Here is the source code for this class.
    /** SwingBoard.java **/
    package com.chess4you.board;import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.LayoutManager;
    import java.awt.Toolkit;import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    /**
    * A simple chess board using Swing
    *
    * @author Ashik Uzzaman
    * @link https://ashikuzzaman.wordpress.com
    */
    public class SwingBoard extends JFrame {

    public static final int NUMBER_OF_ROWS = 8;
    public static final int NUMBER_OF_FILES = 8;
    public static JLabel square;
    public static JPanel squarePanel = new JPanel();
    public static JPanel squaresPanel = new JPanel();

    private static void createSquares() {
    LayoutManager layout = new GridLayout(NUMBER_OF_ROWS, NUMBER_OF_FILES);
    squaresPanel.setLayout(layout);
    for(int i=NUMBER_OF_ROWS; i>0; i–) {
    for(int j=1; j<=NUMBER_OF_FILES; j++) {
    squarePanel = new JPanel();
    square = new JLabel (“r” + i + “:c” + j);
    squarePanel.add(square);
    squarePanel.setBackground(getColor(i, j));
    square.setForeground(new Color(0, 0, 250));
    squarePanel.setToolTipText(“Row ” + i + ” and Column ” + j);
    squaresPanel.add(squarePanel);
    }
    }
    }

    private static Color getColor(int x, int y)
    {
    if((x+y) % 2 == 0)
    return new Color(255, 255, 255);
    else
    return new Color(0, 0, 0);
    }
    public SwingBoard() {
    initComponents();
    }

    private void initComponents() {

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int boardSize = 0;
    int width = dim.width;
    int height = dim.height;
    if(width >= height) {
    boardSize = height / 2;
    } else {
    boardSize = width / 2;
    }
    createSquares();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle(“Swing Chess Board”);
    setIconImage(new ImageIcon(“board.jpg”).getImage());
    getContentPane().add(squaresPanel, BorderLayout.CENTER);
    setVisible(true);
    Dimension preferredSize = new Dimension();
    preferredSize.width = boardSize;
    preferredSize.height = boardSize;
    setPreferredSize(preferredSize);
    setBounds(boardSize / 4, boardSize / 4, boardSize, boardSize);
    pack();
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new SwingBoard();
    }
    });
    }
    }

  5. Create javase6.bat file inside your project directory. The content of this file actually sets path and classpath required for java.
    ## Simple batch file for Java classpath settings
    SET JAVA_HOME=C:\programs\java\jdk_6
    SET ANT_HOME=C:\programs\java\apache-ant-1.6.5
    SET PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin
    SET PROJECT_HOME=C:\workspace\SwingBoard
    SET CLASSPATH=%CLASSPATH%;.;%JAVA_HOME%\lib\tools.jar
    Title “JDK 6”
    cd %PROJECT_HOME%
    cmd
  6. If you use Ant, create build.xml file in your project directory with following contents.
    <?xml version=”1.0″ encoding=”ISO-8859-1″?>
    <project name=”SwingBoard” default=”run” basedir=”.”>
    <description>
    Swing Application build and execution file
    </description><property name=”main.class” value=”com.chess4you.board.SwingBoard”/>
    <property name=”src” location=”.”/>
    <property name=”build” location=”.”/><target name=”compile”>
    <javac srcdir=”${src}” destdir=”${build}” />
    </target>

    <target name=”run” depends=”compile”>
    <java classname=”${main.class}” fork=”true” failonerror=”true” />
    </target>
    </project>

  7. Copy a small icon for a chess board in your project directory and name it board.jpg that is used in our code. You may download the icon that I used from http://farm1.static.flickr.com/160/391341494_669254c2c6_s.jpg
  8. To compile from command prompt, double click javase6.bat file and issue the following command: javac com/chess4you/board/SwingBoard.java
  9. To run from command prompt, issue the following command: java com.chess4you.board.SwingBoard
  10. To compile using Ant, issue the following command: ant compile
  11. To run using Ant, issue the following command: ant run

February 26, 2007

Web 2.0 & Open Source

Filed under: Community, Web — ashikuzzaman @ 10:30 pm

Article on Web 2.0 & Open Source

read more | digg story

And a few more references:

http://taint.org/2006/05/29/194404a.html

http://business.newsforge.com/business/05/10/06/0132209.shtml?tid=18&tid=33&tid=13

http://radar.oreilly.com/archives/2006/11/open_source_web.html

http://www.flatworldcmpcollabnet.com/

February 21, 2007

Developing Web Site by Integrating Joomla, SMF and Community Builder

Filed under: Community, Web — ashikuzzaman @ 4:34 pm

Here I provide you the step by step instructions that I carried last night to develop a web site for an IT professionals’ association in California, USA. They need a good news/content management system, a very good forum software and some sort of community/networking features other than regular static/dynamic functionalities that might be developed later phase by phase. I know Joomla (emerged from Mambo) PHP framework or CMS has many great extensions that I can use in developing web 2.0 sites. Although it has been long since I last used PHP, joomla made my work easy by mostly limiting me in configuration and installation efforts to develop a site. So I thaught to share it with you here. I wish there would be something similar in Java with all the extensions and easy to install features!

Pre-Requisite

A domain hosting space where you want to host your site. I chose hostmonster as they have support for PHP, MySQL, Fantastico, Joomla, SMF and many more.

Steps

  1. Install Joomla! I logged into my hostmonster control panel, used Fantastico to install Joomla 1.0.12 in /cms directory. Keep the MySQL database, username and password handy with you as these will be needed in later steps.
  2. Download SMF and Unzip it in your local workspace naming it forum. I downloaded SMF 1.1.2 from http://www.simplemachines.org/download
  3. Upload the unzipped forum direcotry with all its contents to your web server’s /public_html directory.
  4. Install SMF through the following URL – http://www.yourdomainname.com/forum/install.php and follow the wizard from there onwards.
  5. Dont use the GZip compression output, uncheck that option in the wizard page.
  6. Give the same MySQL database name, user name and password that you used for joomla installation. You can find these information in configuration.php file under your domain’s /cms directory. The 3 variables to check for the values are – $mosConfig_user, $mosConfig_password, $mosConfig_db .
  7. Once you finish installation, you should get a success message and install.php file should be deleted for security reason.
  8. Download community builder distribution. I downloaded CBuilder1_0_2_unzip1st.zip from – http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,210/Itemid,35/
  9. Unzip the community builder zip file in your local hard drive. You will need cblogin.zip, comprofiler.zip, mod_comprofilermoderator.zip and mod_comprofileronline.zip files from this location in later steps.
  10. Install comprofiler component. To do so, login to Joomla administrator (http://www.yourdomainname.com/cms/administrator) and select the Installers->Components menu item. Browse for the comprofiler.zip file inside your unizipped community builder directory and press upload file & install button.
  11. Install cb login module. To do so, select the Installers->Modules menu item. Browse for the cblogin.zip file inside your unizipped community builder directory and press upload file & install button.
  12. Install cb moderation module. To do so, select the Installers->Modules menu item. Browse for the mod_comprofilermoderator.zip file inside your unizipped community builder directory and press upload file & install button.
  13. Install cb online module. To do so, select the Installers->Modules menu item. Browse for the mod_comprofileronline.zip file inside your unizipped community builder directory and press upload file & install button.
  14. Add a new user menu item named Members List as a URL pointing to: index.php?option=com_comprofiler&task=usersList
  15. Add new menu item CB Details by clicking on Menu->usermenu->New button.
  16. In New Menu Item page, select Component and press Next button.
  17. Select Community Builder from the Component List.
  18. Populate the Name field as CB Details.
  19. Select Parent Item: Top, Access Level: Registered and Published: Yes.
  20. Click on Save button to add this new menu item under user menu.
  21. Activate the CB Login module. To activate select Modules->Site Modules, check from the list that CB Login module is set for Public Access viewing and then publish this module.
  22. Deactivate mod_login module so that you can use only cb login form instead of joomla login form in your site. To deactivate, find out Modules->Site Modules->Login Form and unpublish it.
  23. Use up arrow to bring the CB Login module up in the left navigation bar. You may also re-position all the modules as you need by setting module order and position.
  24. Activate CB Workflows module. To activate, find out Modules->Site Modules->CB Workflows, check if its set to Registered access level and then publish it.
  25. Now download Joomla SMF Bridge (JSMF) from http://www.joomlahacks.com/joomla/components/Joomla-SMF_Forum
  26. Install JSMF component in Joomla. To install it, go to http://www.yourdomainname.com/cms/administrator and select the Installers->Components menu item. Browse for the com_smf_2_0_2.zip file inside your unizipped community builder directory and press upload file & install button.
  27. After installation success message for JSMF, continue for JSMF Installation Page.
  28. Provide the abosulte path for SMF directory which you can find after logging into SMF forum administration panel. An example value for this may be /home/aabeatco/public_html/forum
  29. Provide SMF tables prefix as smf_
  30. Click the Save button at the top right.
  31. Click to patch Jomla Source Files.
  32. Click to patch SMF Source Files.
  33. Click verify link to synchronize users between Joomla and SMF.
  34. Login to Joomla administrator.
  35. Select Components->Community Builder->Plugin Management.
  36. In Install New Plugin section, upload & install cb_plug_smf_2_0_3.zip file.

If you have followed the steps properly, you have enabled your site for visitors to register/login using CB Login form, roam around and give entries for the various news/polls/blogs entries, submit weblinks, do social networking with like minded community members etc. Your users should be able to roam around the joomla cms pages through the link – http://www.yourdomainname.com/cms and the forum either through http://www.yourdomainname.com/forum or from CMS home page’s Forum link.

February 15, 2007

Developing Simple Chess Board With SWT

Filed under: Chess, Community, Java — ashikuzzaman @ 1:38 pm

I have worked with AWT, Swing and SWT in different projects. I was involved last 2 years mostly on web applications and hence after joining Philips, I got a chance to work with thick clients again. Here I developed a simple prototype for SWT beginners with step by step instructions to develop a chess board using SWT and 3 different ways to setup environment, compile and run it. Hope you will enjoy!

  1. Make sure you have Java installed. I installed Java SE 5 in C:\programs\java\jdk_1.5.0.7
  2. Install Ant 1.6.5 altough you may use command prompt if you dont want to use Ant or even better if you use Eclipse which already has Ant functionalities to work with Ant. I installed Ant at C:\programs\java\apache-ant-1.6.5
  3. Create project directory at c:\workspace\SWTBoard either manually or using Eclipse New Java Project.
  4. Download SWT jar file from Eclipse web site – http://www.eclipse.org/swt . If you already have Eclipse installed in your machine then, you will find the JAR file inside $Eclipse_Install_dir$\plugins directory. I am using SWT 3.2.1 for Windows.
  5. Copy the jar file to a suitable directory for easy reference. I copied the org.eclipse.swt.win32.win32.x86_3.2.1.v3235.jar file (or swt.jar if you have downloaded from Eclipse web site) in C:\workspace\swtlibs directory.
  6. Extract swt-win32-3235.dll file inside the SWT jar file and copy it into the same directory.
  7. Create SWTBoard class under package name com.chess4you.board. Here is the source code for this class.
    /** SWTBoard.java **/
    package com.chess4you.board;
    import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Label; import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.graphics.ImageData;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.SWT;/**
    * A simple chess board developed using SWT
    *
    * @author Ashik Uzzaman
    * @link https://ashikuzzaman.wordpress.com
    */
    public class SWTBoard { public static final int NUMBER_OF_ROWS = 8;
    public static final int NUMBER_OF_FILES = 8;
    public static Display display = new Display();
    public static Shell shell = new Shell(display, SWT.SHELL_TRIM);
    public static GridLayout layout = new GridLayout();
    public static GridData data;
    public static Label square;

    private static void createSquares() {
    for(int i=NUMBER_OF_ROWS; i>0; i–) {
    for(int j=1; j<=NUMBER_OF_FILES; j++) {
    data = new GridData(GridData.FILL_BOTH);
    square = new Label(shell, SWT.CENTER);
    square.setBounds(shell.getClientArea());
    square.setBackground(getColor(i, j));
    square.setText(“r” + i + “:c” + j);
    square.setForeground(new Color(display, 0, 0, 250));
    square.setToolTipText(“Row ” + i + ” and Column ” + j);
    square.setLayoutData(data);
    }
    }
    } private static Color getColor(int x, int y)
    {
    if((x+y) % 2 == 0)
    return new Color(display, 255, 255, 255);
    else
    return new Color(display, 0, 0, 0);
    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    layout.numColumns = NUMBER_OF_FILES;
    layout.makeColumnsEqualWidth = true;
    int squareSize = 0;
    int width = display.getBounds().width;
    int height = display.getBounds().height;
    if(width >= height) {
    squareSize = height / 2;
    } else {
    squareSize = width / 2;
    }
    shell.setSize(squareSize, squareSize);
    shell.setBounds(new Rectangle(squareSize / 4, squareSize / 4, squareSize, squareSize));
    shell.setLayout(layout);
    ImageData imgData = new ImageData(“board.jpg”);
    Image img = new Image(display, imgData, imgData);
    shell.setImage(img);

    createSquares();

    // shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    display.dispose();
    }
    }

  8. Create javase5.bat file inside your project directory. The content of this file actually sets path and classpath required for java and SWT.
    ## Simple batch file for Java classpath settings
    SET JAVA_HOME=C:\programs\java\jdk_1.5.0.7
    SET ANT_HOME=C:\programs\java\apache-ant-1.6.5
    SET PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin
    SET PROJECT_HOME=C:\workspace\SWTBoard
    SET CLASSPATH=%CLASSPATH%;.;%JAVA_HOME%\lib\tools.jar;C:\workspace\swtlibs\org.eclipse.swt.win32.win32.x86_3.2.1.v3235.jar Title “JDK 5”
    cd %PROJECT_HOME%
    cmd
  9. If you use Ant or Eclipse, create build.xml file in your project directory with following contents.
    <?xml version=”1.0″ encoding=”ISO-8859-1″?>
    <project name=”GenericSwtApplication” default=”run” basedir=”.”>
    <description> SWT Application build and execution file </description> <property name=”main.class” value=”com.chess4you.board.SWTBoard”/>
    <property name=”src” location=”.”/>
    <property name=”build” location=”.”/>
    <property name=”swt.libs” value=”C:\workspace\swtlibs”/>

    <property name=”swt.jar.lib” location=”${swt.libs}”/>
    <property name=”swt.jni.lib” location=”${swt.libs}”/>

    <path id=”project.class.path”>
    <pathelement path=”${build}”/>
    <fileset dir=”${swt.jar.lib}”>
    <include name=”**/*.jar”/>
    </fileset>
    </path> <target name=”compile”>
    <javac srcdir=”${src}” destdir=”${build}”>
    <classpath refid=”project.class.path”/>
    </javac>
    </target> <target name=”run” depends=”compile”>
    <java classname=”${main.class}” fork=”true” failonerror=”true”>
    <jvmarg value=”-Djava.library.path=${swt.jni.lib}”/>
    <classpath refid=”project.class.path”/>
    </java>
    </target>
    </project>
  10. Copy a small icon for a chess board in your project directory and name it board.jpg that is used in our code. You may download the icon that I used from http://farm1.static.flickr.com/160/391341494_669254c2c6_s.jpg
  11. To compile from command prompt, double click javase5.bat file and issue the following command: javac com/chess4you/board/SWTBoard.java
  12. To run from command prompt, issue the following command: java -Djava.library.path=C:\workspace\swtlibs com.chess4you.board.SWTBoard
  13. To compile using Ant, issue the following command: ant compile
  14. To run using Ant, issue the following command: ant run
  15. To compile/build the project using Eclipse, you have to first add the SWT jar file in your project classpath. To do so, right-click on your project in package explorer and select Properties->Java Build Path->Libraries->Add External Jars… and add C:\workspace\swtlibs\org.eclipse.swt.win32.win32.x86_3.2.1.v3235.jar . Now you should be able to build the project selecting Project->Build Project .
  16. To run the project using Eclipse, select Run->Run… ->Arguments and in VM Arguments text area add the following entry: -Djava.library.path=C:/workspace/swtlibs
  17. You may also use the Ant build file (build.xml) from Eclipse by double-clicking on it and running the specific targets (compile or run) by right-click on the target and selecting Run As->Ant Build.

February 9, 2007

Khandakar Asif Hasan on “Meet the Mentors” by SQABD

Filed under: Community — ashikuzzaman @ 5:16 pm

SQA Bangladesh took an excellent initiative to interview the mentors of software industry in Bangladesh and podcast those through Meet the Mentors program. Listen to their first podcast(MP3) session at:

http://sqabdmentors.blogspot.com/2007/02/khandakar-asif-hasan-on-meet-mentors-by.html

This session is with Khandakar Asif Hasan, Director at Spectrum Engineering Consortium Ltd who shared his valuable insights on the strategies for development of software industry infrastructure. In this interview he touched the areas of software development life cycle process, proper training of human resources to build up core professionals in this field, the issue of internship, current Bangladesh Government policies in IT sector, modifications that need to apply to grab local software markets, essense of sustainable software development community, major problems of our software industry by comparing with the neighboring country India. He emphasized on collaboration between software companies and sharing knowledge, tools between each other to guide our software development community with a successful new dimension. Overall this podcast session tries to visualize the milestones and problems of software industry through the analytical portray of Khandakar Asif Hasan with his mission, vision and experiences of journey in the software industry during more than a decade.

I was lucky enough to get Asif Vai as mentor in my software engineering career when I joined Spectrum Engineering Consortium Ltd at 2001. Those who have worked with him, have the appreciation for both his architectural vision as well as engineering approach to solving any (non technical) problems. Layered architecture, design patterns, process centric software development approach, importance of good document writing, team work, knowledge sharing are only a few of what he instilled in our team. He understands the industry trends and from a bird’s eye view can tell which one is appropriate to adapt with and which one should be only studied and left in the buzz. We need more mentors like him in our software industry. I invite you to go through the whole session and share your feedbacks with me.

Directly download from:

http://www.sqabd.com/files/Mentors/Episode1-Mentors_SQABD.mp3

http://feeds.feedburner.com/~r/mentors/~5/87717612/Episode1-Mentors_SQABD.mp3

Jess & Rule Based Systems

Filed under: Java — ashikuzzaman @ 3:25 am

Recently I worked on JESS, stands for Java Expert System Shell, in Philips Motiva project which is a remote patient monitoring platform. We use Jess for decision making support in Motiva to make it an intelligent system. I can’t think of learning JESS without reading its creator Ernest Friedman-Hill‘s book JESS In Action. Ernest is also a moderator of JavaRanch. There are alternate rule engines available – Mandarax, QuickRules, Drools, ofbiz, JRules, Haley Rules Products, Common Knowledge.

While working with JESS, I have developed a sample prototype to use the basic language syntaxes of JESS. The program is as follows. It shows usage of basic Jess language sytanxes, if/then/else, while consturcts, bind, list etc. The programs gives an overview of chess borad game and its pieces.

JESS ON CHESS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Jess On Chess
;; Developed By: Ashik Uzzaman
;; Aug 22, 2006
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; this is jess
;; working on chess
;; i hope its
;; not quite a mess
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(printout t ”
=========== Start of Jess On Chess. ===========” crlf)

;; what is chess?
(printout t crlf
“**** What is Chess?
Chess is an abstract strategy board game and mental sport for two players.
The object of the game is to checkmate the opponent’s king.
This occurs when the king is under immediate attack (in check) and
there is no way to prevent it from being captured on the next move.” crlf)

;; declare squares
(printout t crlf
“**** What is Chess Borad?
Chess is played on a square board of 8 rows (called ranks) and 8 columns (called files), giving (* 8 8) = ” (* 8 8) ” squares of alternating light and dark color, which are referred to as ‘light squares’ and ‘dark squares’.” crlf crlf)

(bind ?row# 1)
(bind ?column# 1)
(bind ?maxrows 8)
(bind ?maxcolumns 8)
(bind ?files (create$ A B C D E F G H))
;; ranks in chess are 1 to 8 so not declaring any list for them

(while (<= ?column# ?maxcolumns) do
(while (<= ?row# ?maxrows) do
(printout t (nth$ ?column# ?files) ?row# ” “)
(bind ?row# (+ ?row# 1)))
(printout t crlf)
(bind ?row# 1)
(bind ?column# (+ ?column# 1)))

(printout t crlf
“**** How many light squares are there?” crlf)
(printout t “(/ (* 8 8) 2) = ” (/ (* 8 8) 2) crlf “The light squares of a chess board are….” crlf crlf)

(bind ?row# 1)
(bind ?column# 1)
(while (<= ?column# ?maxcolumns) do
(while (<= ?row# ?maxrows) do
(if (= (mod ?row# 2) 1) then
(if (= (mod ?column# 2) 0) then
(printout t (nth$ ?column# ?files) ?row# ” “))
else
(if (= (mod ?column# 2) 1) then
(printout t (nth$ ?column# ?files) ?row# ” “)))
(bind ?row# (+ ?row# 1)))
(printout t crlf)
(bind ?row# 1)
(bind ?column# (+ ?column# 1)))

(printout t crlf
“**** How many dark squares are there?” crlf)
(printout t “(- (* 8 8) (/ (* 8 8) 2)) = ” (- (* 8 8) (/ (* 8 8) 2)) crlf “The dark squares of a chess board are….” crlf crlf)

(bind ?row# 1)
(bind ?column# 1)
(while (<= ?column# ?maxcolumns) do
(while (<= ?row# ?maxrows) do
(if (= (mod ?row# 2) 0) then
(if (= (mod ?column# 2) 0) then
(printout t (nth$ ?column# ?files) ?row# ” “))
else
(if (= (mod ?column# 2) 1) then
(printout t (nth$ ?column# ?files) ?row# ” “)))
(bind ?row# (+ ?row# 1)))
(printout t crlf)
(bind ?row# 1)
(bind ?column# (+ ?column# 1)))

;; declare team
(bind ?teams (create$ white black))
(printout t crlf
“Two players represent 2 teams in a game ” ?teams ” and tries to win
by killing the opponent king which is know as “checkmate”. Depending on
success to checkmate the opponent king or saving one’s own king from
checkmate by opponent, a game may result in win, loss or draw.” crlf)

;; define there are 2 types of team represented by color – white and black
(bind ?team-members (create$ king queen rook bishop knight pawn))
(bind ?member-numbers (create$ 1 1 2 2 2 8))
(bind ?member-descriptions (create$ “the invaluable member of team” “the most powerful” “other major pieces that move straight” “minor pieces that move diagonally” “other minor pieces that have interesting movement” “the cheapest members of the team”))

(printout t crlf
“Each team has the following members ” ?team-members crlf)

(bind ?count 1)
(while (<= ?count 6) do
(printout t crlf (nth$ ?count ?member-numbers) ” ” (nth$ ?count ?team-members) ” – ” (nth$ ?count ?member-descriptions) crlf)
(bind ?count (+ ?count 1)))

;; define that there might be empty squares or occupied squares
(printout t crlf
“A square may be occupied by any one member of the 2 teams.” crlf)

;; define that no square can be occupied by more than 1 member
(printout t crlf
“But no square can be occupied by more than 1 member.” crlf)

;; define that no member can occupy more than 1 square
(printout t crlf
“Also no member can occupy more than 1 sqaure.” crlf)

(printout t crlf
“**** So what is the total number of memebrs occupying the chess board?
The total number of sqaures – (* 8 8) = ” (* 8 8) crlf)

(printout t
“The total number of white pices – (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) = ” (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) crlf)

(printout t
“The total number of black pices – (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) = ” (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) crlf)

(printout t
“The total number of pices combinedly (black and white) – (* (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) 2) = ” (* (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) 2) crlf)

(printout t
“The total number of empty squares at the start of the game – (- (* 8 8) (* (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) 2)) = ” (- (* 8 8) (* (+ (+ (+ (+ (+ 1 1) 2) 2) 2) 8) 2)) crlf)

(printout t “

=========== End of Jess On Chess. ===========

this is jess
working on chess
i hope its
not quite a mess” crlf crlf)

Blog at WordPress.com.