How to develop a chess program from scratch (for total beginners) Ep. 2

Huo Chess (console edition)

Interested in chess programming? You are interested in philosophy too! What is thinking? Can AI be conscious? What does it mean to do something? Can the AI understand that it does play chess? Explore the AI related articles in Harmonia Philosophica and understand why you are already a philosopher!


[Previous episode]


In the previous episode we set the foundations for starting a chess program. In summary we…

  • Discussed the pre-requisites for the tutorial
  • Created the chessboard
  • Got the first input from the user

Now it is time to start the design of the chess thinking algorithm.

Step 0: Design the main steps on paper

Before making any serious programming attempt, one has to leave the computer and get a piece of paper. There, he can design the algorithm of the program. A good design is invaluable for a good program. There is no need to start writing code without having that design first!

Chess program algorithm outline

One can find above a rough outline of the major steps involved in a chess program algorithm.

Note that this algorithm is an over-simplification, but it will do for now. For example, the algorithm above does not take into account the fact that the thinking of the computer must be conducted in various depths and not only in the initial position. We will elaborate on that in next episodes; for now let us just try to analyze all possible moves in a position and choose the one that leads to the best score.

[Next episode: Scanning the chessboard for moves]

[Previous episode]

Huo Philosopher v2.0 (Commodore philosophy application for the BASIC 10Liners 2021 contest)

Huo Philosopher is a tiny open source program for Commodore. With just 10 lines of code, it is able to conduct clever conversations about philosophy with deep meaning…

Huo Philosopher by Spiros Kakos (huo)

There is a weird but very interesting programming contest happening every year.

It is the BASIC 10Liners contest, where contestants are asked to create programs in BASIC with just 10 lines of code!

You would be amazed on what things can be done with just ten (10) lines of code.

There are three categories for programming a game depending on the length of each line (80, 120 or 256 characters) and an additional fourth category (SCHAU) for programming an application in 10 lines. (check here for the rules of the BASIC 10Liners contest of 2021)

My participation in the SCHAU category was with the “Huo Philosopher v2.0” program.

This program is essentially a downgraded version of the Huo Writer application (check HUO Writer: A simple AI writer with basic Neural Network capabilities).

Short description

The program HUOPHIL1 (Huo Philosopher v2.0) is a tiny program by Spyridon Kakos that can make deep philosophical conversations about any available subject. Its deep irrational understanding of the cosmos is based on nothing more than sets of random phrases the program brilliantly combines in order to produce phrases that will make any philosopher shiver from the sheer terror of its non-knowledge of metaphysics.

How the program works

The program uses three sets of arrays that contain…

  • An initial phrase. (Table X$)
  • A middle phrase: This is the more complex one and uses three arrays that hold the start, the middle and the ending of the second phrase. (Tables Y$ + Z$ + W$)
  • An ending phrase. (Table E$)

The program initially initializes the values in the tables and asks for user input. Then it generates random numbers and combines elements from the tables mentioned above to generate the three phrases. A delay between the phrases as they appear on the screen add to the mystery and the tension…


One can download the program code and the relative documentation from the official entry page for the BASIC 10Liners 2021 here.

Alternatively, one can download the source code of the program and the relative documentation below.

Please contact us for any comments and/ or suggestions.

And remember.

Keep coding!

Keep experimenting!

Appendix I – The source code

The source code is presented below.

30Z$(1)=" DEFINES ":Z$(2)=" CREATES ":Z$(3)=" SUSTAINS ":Z$(4)=" TRANSCENDS ":Z$(5)=" DESTROYS ":Z$(6)=" ALLOWS ":Z$(7)=" MANIFESTS THROUGH ":Z$(8)=" OBSCURES ":Z$(9)=" AFFECTS ":Z$(10)=" CONTAINS ":Z$(12)=" SUPPORTS ":Z$(13)=" STEMS FROM "
40Z$(11)=" IS ":Z$(14)=" PRODUCES ":Z$(15)=" LEADS TO ":Z$(16)=" BREEDS ":Z$(17)=" NEEDS ":W$(1)="EXISTENCE":W$(2)="GOD":W$(3)="LIFE":W$(4)="THE SELF":W$(5)="BEING":W$(6)="OTHERS":W$(7)="DEATH":W$(8)="REALITY":W$(9)="THE COSMOS":W$(10)="CHANGE"
50W$(11)="PERCEPTION":W$(12)="NOTHINGNESS":W$(13)="TRUTH":W$(14)="ONE":W$(15)="FAITH":W$(16)="HUMANS":W$(17)="MEMORY":W$(18)="FAITH":E$(1)="LOGIC IS IRRATIONAL":E$(2)="STOP THINKING...":E$(3)="FEEL THE ABYSS...":E$(4)="BEING IS ME..."
60E$(5)="CLOSE YOUR EYES TO SEE":E$(6)="DO YOU SEE?":E$(7)="I ONLY KNOW WHAT I KNOW":E$(8)="ALL IS ONE":X=RND(-TI):X=INT(6*RND(1))+1:Y=INT(10*RND(1))+1:Z=INT(17*RND(1))+1:W=INT(18*RND(1))+1:E=INT(8*RND(1))+1
80IF B>10 THEN B=10

The code is free for someone to reuse it, as long as the source is properly mentioned.

Programming and Philosophy: Not so much different as they seem…

Huo Philosopher by Spiros Kakos (Huo)

What is common between programming and philosophy?

Well, at first glance… nothing!

Yet, if one scratches below the surface he or she may find some peculiar correlations.

People like philosophy.

Because they like to ask questions and seek their answers. Because they are interested in the major questions of humankind and would like to reach that holy grail we seek since we were born: Truth.

People like programming.

Because they like to create things that work. They like it because it enables them to bring life to their ideas and to an extent, even touch the idea of life itself via artificial intelligence and neural networks.

In both cases the most primitive of instincts are the cause of our actions.

Instincts that make us “do things”.

Instincts that make us “create things”.

Instincts that make us ask and then answer. And with every knew answer, seek ways to ask new questions and improve the answers even more.

That was since the dawn of civilization our best quality.

And our tragic fate.

Always on a quest.

Creating things.

Destroyers of the worlds.

Perhaps we were programmed to be like this.

And that is why we constantly try to be free…

The adventure of creating… an adventure! Episode 1: Setting up the images [Quick Basic/ QB64 Tutorial]

First Adventure (in QB64)


Programming is fun!

What does that have to do with a philosophy portal?

Well… I do not know!

But then again…

What do we know about life or death?


The goal of this series of tutorials is to show how to create a small (or big?) adventure game with Quick Basic, so as to disseminate programming knowledge. Even if you do not have prior programming knowledge you will be able to follow the series with some additional effort to clear up some programming details we will encounter along the way.

The source code of the program will always be provided at all steps of the tutorial. Reuse of the code is allowed as long as the source is mentioned properly.

Tools needed

To follow the tutorial you just need the Quick Basic in your computer. Just download the latest QB64 from the relative site here for free.


Before doing any programming one must design what he wants to do. This applies to small as well as big programs.

So what do we want to do?

To create an adventure game!

This game will utilize simple images that we will show to the users as they progress along the game. All the typical adventure game commands will be allowed: Look at, Walk to, Pick up, Use, Talk to, Give, Push, Pull.

The game scenario is something I have not yet thought in its entirety. However I know that the game will start from a room where you are and where you will need to stay alive for at least one day before the rescue team comes and saves you.

The beginning

From where to start from?

Well, from the start (welcome) screen!

To do that we use the PRINT command to print the game title on the screen.

The game will be called…

First Adventure!

Since it is our first adventure.

LOCATE 10, 32: PRINT "First Adventure!"
LOCATE 11, 30: PRINT "Greece, Athens, 2022"
LOCATE 13, 25: PRINT "Seek the moon under the sun…"

The LOCATE commands puts the cursor in a specific line and then we print what we want.

First Adventure – Start image

Setting up the images

Each game takes place in a… place.

To illustrate things we need graphics.

We will use basic graphics in our game, i.e. images we will load into the screen to show things. The first thing is to get the images, right? For the purposes of our tutorial we will use images that are 580×420 pixels in dimension. These images will be shown in a window that is 800×600 in dimensions.

Why these dimensions?

First, for no reason. Just because.

Secondly, I like to have a small window for the program to show small images. You guessed it, the program will not utilize the full screen and will not resize based on the resolution of your screen. Let’s start with the basics and build a bike and we will go to building a spaceship after that…

Images are loaded with the _LOADIMAGE command as it is shown below.

IF GameResolution = 800 THEN
    imgBgrd& = _LOADIMAGE("FA_image_Background_800.png", 32) 'Background image
ELSEIF GameResolution = 1280 THEN
    imgBgrd& = _LOADIMAGE("FA_image_Background_1280.png", 32) 'Background image

You also guessed it right: We have introduced a variable that indicates the resolution of the game. So when I told you that the game will not take into account the resolution of your computer, I lied a bit. Just a bit. We introduce a variable to indicate the resolution used and we will embed it in the code and… we will see how to use it the future.

For now, let’s set the resolution at 800×600…

CONST GameResolution = 800 'Set for resolution 800x600

We repeat the same loading of images for all images of the game. For now, we only have three images: the background image (that is loaded in the beginning and… stays there for ever) and two more images that we put on the background when he game starts.

First Adventure – Background image

The background

The image I have created for background is a black colour image with a white line. This line will be the border between the upper and the lower part of the screen.

  • In the upper part we will show images that are related to the gameplay, e.g. the photo of a room you are in.
  • In the lower part of the screen we will show to the user the possible commands allowed for the game, his inventory of objects (if and when we add one) and any messages.

Simple enough. Yet, nice and effective.

How are those images put in the screen though?

Well, with the PUTIMAGE command…

IF GameResolution = 800 THEN
    _PUTIMAGE (100, 20)-(680, 440), imgStart&, 0
ELSEIF GameResolution = 1280 THEN
    _PUTIMAGE (80, 20)-(660, 500), imgStart&, 0

With the PUTIMAGE command you can set where to place your image upper-left corner (100,20) and where the lower-right corner will be (680,440), which image to load (imgStart&) and where to show it (0 denotes the screen). In that way we can put any of the images we have loaded wherever we want.

First Adventure – Start image

Show the initial messages

When the game starts and the background image is loaded, we print the initial messages to the user. We use the LOCATE command and print the messages in the lower part of the screen, as mentioned above…

'Print text to begin the adventure...
LOCATE 33, 1: PRINT "You are in a room... Alone..."
LOCATE 34, 1: PRINT "There is a snow storm raging outside..."

'Show the trees!
_PUTIMAGE (100, 20)-(680, 440), imgTrees1&, 0

LOCATE 33, 1: PRINT "You must survive for one day..."
LOCATE 34, 1: PRINT "Until the rescue party comes to save the day!"

And as you see in the code, we can load new images whenever we want to show new things. In that case we have loaded a trees picture. After all, we are in a snow storm…

Important Notes

  • Guess what the SLEEP command does. Try to remove it and see what happens.
  • Experiment with the coordinates in the PUTIMAGE command to see how that command can be used. (seek some additional examples commented out in the source code provided)

An epilogue and a promise…

We have just set up the scenery for our game. We have the initial screens and we have understood how images are loaded. We will build on this to expand the game and take it to the next level…

APENDIX I – The source code

Please see below for the full source code of the game.

'Declare variables
DIM imgBgrd&
DIM imgStart&
CONST GameResolution = 800 'Set for resolution 800x600
'const GameResolution = 1280 'Set for resolution 1280x720

LOCATE 10, 32: PRINT "First Adventure!"
LOCATE 11, 30: PRINT "Greece, Athens, 2022"
LOCATE 13, 25: PRINT "Seek the moon under the sun..."

'Load the background from an image in a file
'Load different pictures depending on the resolution we want
'(because the image will be used to set the screen)
'imgBgrd& = _LOADIMAGE("FA_image_Background_800.png", 32) 'Background image

IF GameResolution = 800 THEN
    imgBgrd& = _LOADIMAGE("FA_image_Background_800.png", 32) 'Background image
ELSEIF GameResolution = 1280 THEN
    imgBgrd& = _LOADIMAGE("FA_image_Background_1280.png", 32) 'Background image

'imgStart& = _LOADIMAGE("FA_image_Start_800.png", 32)

'Load images of the game from files
'Images for resolution 800x600 are 580x420
'Images for resolution 1280x720 are 640x480
'Image Start
IF GameResolution = 800 THEN
    imgStart& = _LOADIMAGE("FA_image_Start_800.png", 32)
ELSEIF GameResolution = 1280 THEN
    imgStart& = _LOADIMAGE("FA_image_Start_1280.png", 32)
'Image trees
imgTrees1& = _LOADIMAGE("FA_trees1.png", 32)

'Set the image as destination
'_DEST img1&

'Set the screen mode based on the background image (800x600 png image)
'SCREEN _NEWIMAGE(800, 600, 32)
SCREEN imgBgrd&

'Set background colour to gray
'CLS , _RGB32(127, 127, 127)

'Present the first image of the game on the black screen
'(i.e. put the image2 on top of image1, which is the background loaded initially)

'_PUTIMAGE (10, 10)-(650, 490), imgStart&, 0
'_PUTIMAGE (200, 200)-(400, 400), img2&, 0, (0, 0)-(400, 400)

IF GameResolution = 800 THEN
    _PUTIMAGE (100, 20)-(680, 440), imgStart&, 0
ELSEIF GameResolution = 1280 THEN
    _PUTIMAGE (80, 20)-(660, 500), imgStart&, 0

'Set text colour
'COLOR 7, 5

'Print text to begin the adventure...
LOCATE 33, 1: PRINT "You are in a room... Alone..."
LOCATE 34, 1: PRINT "There is a snow storm raging outside..."

'Show the trees!
_PUTIMAGE (100, 20)-(680, 440), imgTrees1&, 0

LOCATE 33, 1: PRINT "You must survive for one day..."
LOCATE 34, 1: PRINT "Until the rescue party comes to save the day!"

Copy this code in your QB64 IDE and try it out.

In order to use it you must also have the images the program loads in the same folder as the QB64.exe program.

APPENDIX II – The images

Please fine here the images used by the program.

APPENDIX III – Useful resources

One can find many things in the Internet. Information about programming is one of these things. Seek help in the relative QB64 web site or in relevant programming sites to understand how various Quick Basic commands work.

Below I list some resources related to the commands we used.

Feel free to seek knowledge from where you can!

Chess Program thought process analysis article

The goal of this paper is to analyze in a simple way the thought process of a chess program, so as to facilitate understanding among chess programming enthusiasts and to bolster potential improvements in that process.

Huo Chess thinking algorithm (simple)

A new article “Chess Program thought process analysis (Simple) – The Huo Chess example” has been published.

There the thinking process of a chess program is presented in high level in order to help chess programming enthusiasts gain an initial understanding of the general way a chess program works.

One can find the relative article here at Academia.

A new article with more advanced subjects of chess programming will follow.

One can also download the file from below.

Exit mobile version