Click here to Skip to main content
Email Password   helpLost your password?

Huo_Chess_GUI.JPG

Huo Chess (GUI edition)

Summary

Huo Chess is a chess program of just 36 KB in size (this size refers to the 'clean' version processed with .NETZ - the C# version raw executable is initially 52.5 KB in size). Four editions currently exist: three without graphical user interface (one in C++, one in C# and one in Visual Basic) and one with Graphical User Interface (XNA based). Its current version (Huo Chess v0.82) can think up to 20 moves depth (10 half-moves for white and 10 half-moves for black pieces) and has an opening book capability. Huo Chess plays decent chess and has managed to draw Microchess, the first microchess from the Commodore era (see the Huo Chess Games Archive below). Its algorithm can be used to study the underlying logic of a chess program or as a basis for your own chess program (the source code is heavily commented and easily customized). The source code is continually improving and is distributed under The Code Project Open License. In this article, I also analyze its programming logic, with emphasis on the general flow inside the computer’s "mind," from the initial scanning of the chessboard up to the final decision on which move to play. Any comments are welcome!

Versioning

Huo Chess is intelligently designed, but it also evolves. Currently, the program is at version 0.82. The timeline of versions and the respective changes conducted in the program's code are depicted below.

Version 0.82

Changed the ComputerMove, HumanMove, CountScore, ElegxosOrthotitas functions. Increased thinking depths from 8 to 20. Reduced the size by using a template ComputerMove function for all thinking depths (instead of ComputerMove2, ComputerMove4, ComputerMove6 etc). The C++ edition is still in 0.81 version (separate ComputerMove functions still exist), for educational purposes. Size of C# edition: 52.5 KB.

Version 0.722 XNA

Huo Chess (C# edition) with Graphical User Interface based on XNA.

Version 0.722 cs

Huo Chess port in C# programming language.

Version 0.722

Fixed some issues with the HumanMove function.

Version 0.721

More thinking depth analysis capability has been added to the program. Huo Chess uses the ComputerMove2, ComputerMove4, ComputerMove6 and ComputerMove8 functions to think at a depth of 8 moves (4 half-moves for the white and 4 half-moves for the black pieces). Size: 56.5 KB

Version 0.6 (Micro edition)

It was based on version 0.6. Reduced all string/text (i.e. "White Rook" => "WR"). Reduced the length of variable names (in every variable in the program, specific strings were replaced with smaller ones). Icon was replaced with smaller one. Removed all unnecessary files (resources, assembly.cpp, stdafx, etc.). Size: 47.5 KB

Version 0.6

Removed the empty try...catch statement in line 3959 at HumanMove, which caused the bug at ElegxosNomimotitas not to show. Optimized the CountScore function. Fixed the bug at ElegxosNomimotitas in the part that checks moves of Rook-Queen-Bishop at lines 3143-32173. Added penalty in case the computer moves its pieces next to an opponent’s pawn. Made the computer eat the opponent’s queen when there is a chance. Lowered the value of the opponent’s king, so as to avoid the computer continuously going after him and sacrifice pieces for that. Optimized the CountScore_Human function. Size: 53.5 KB

Version 0.5

Fixed HumanMove function. Optimized CountScore and ComputerMove functions. Size: 51.5 KB

Version 0.4

Added random playing capability. Optimized CheckForWhiteCheck and CheckForBlackCheck functions. Size: 51.0 KB

Version 0.3

Stronger playing capabilities. Added opening book capability. Optimized ElegxosNomimotitas and ElegxosOrthotitas functions. Size: 91.5 KB

Version 0.2

Fixed some bugs due to which computer played illegal moves. Thanks to everyone who gave me feedback! Size: 99.5 KB

Version 0.1

Initial version. Known problems: the program plays some illegal moves sometimes. Not too strong at all. 49.0 KB

Introduction

What is most important when you program? Is it the program design? Yes? If "yes," then why is it that every program today is bigger than 123876 GB and requires 120987 MB of RAM to run? Why is every new project and program — by default — larger in size and slower in speed than the previous version? The answer is simple: because of the increasing speed of computers, no one actually cares about optimizing the code structure and the software design, since the new processor will definitely make the program look fine for the end user. During the time of Commodore computers, memory was rather limited. That is why programmers tried to make the code small and efficient. This resulted in Microchess, which was a very efficient, small (as the name "micro," which means "small" in Greek, implies) chess program that was able to play chess in the few KB available in computers of that time.

What I Accomplished

Driven by the above, I started developing a program in CLI C++ v8.0 (with Visual Studio 2008 Express Edition) to play chess with the intention of making a small in size (Micro)chess, even smaller than the Commodore-era Microchess. Now, one version in C# programming language and one version with Graphical User Interface also exist (you can find them here for downloading). I named it "Huo Chess" for personal reasons. The program plays decent chess, but unfortunately will probably lose if it plays with Garry Kasparov. Its size is currently 52.5 KB (in the C# edition), while the respective emulation of Microchess in C is 56 KB. However, it must be noted that the original Microchess, written in pure Assembly, was about 1 KB…something that I believe no one will ever match! In matches against Microchess, version 0.4 has managed to draw Microchess (see below the section of Huo Chess Games Archive).

How to Customize - Optimize the Program

The program has an opening book capability, which means that anyone can optimize the program by adding his/her own opening moves data in the respective folder Huo Chess Opening Book (which should be in the same directory with the executable). You can also add more thinking depth capability, by adding new ComputerMove functions (like ComputerMove2, ComputerMove4, etc.), change the value of ThinkingDepth variable and make the necessary adjustments to the HumanMove function (add another if at the point where it calls the ComputerMove functions). Moreover, you can also optimize the way Huo Chess thinks by changing the CountScore function and the way the computer values the pieces or the chessboard position. For example, if you change the score of the Queen in the CountScore function from 9 to 12, then the HY will play aggressively to attack the opponent's queen and at the same time try harder to defend its own queen. You can also — for example — give a high scoring to the existence of an opening column with a rook controlling it, so as to make the computer play more with its rooks and try to take over columns with them. Any FEEDBACK is WELCOME with better configurations of the Opening Book or the CountScore function!

I. Chess Algorithm Analysis

The algorithm used in this program for the implementation of the computer thinking is the "Brute Force Algorithm." Huo Chess plays with the material in mind, while its code has some hints of positional strategic playing embedded. More analytically: When the program starts thinking, it scans the chessboard to find where its pieces are (see ComputerMove function) and then tries all possible moves it can make. It analyzes these moves up to the thinking depth I have defined (via the ComputerMove -> HumanMove -> ComputerMove2/ ComputerMove4/ ComputerMove6/ ComputerMove8 path), measures the score (see CountScore function) of the final position reached from all possible move variants and – finally – chooses the move that leads to the most promising (from a score point of view) position (ComputerMove function).

image002.jpg

More analytically, a high-level example of the progress of the main algorithm is as follows:

  1. ComputerMove: Scans the chessboard and makes all possible moves
  2. CheckMove: Checks the legality and correctness of these possible moves
  3. (if thinking depth not reached) => call HumanMove
  4. HumanMove: Checks and finds the best answer of the human opponent
  5. ComputerMove2: Scans the chessboard and makes all possible moves at the next thinking level
  6. CheckMove: Checks the legality and correctness of these possible moves
  7. (if thinking depth not reached) => call HumanMove
  8. HumanMove: Checks and finds the best answer of the human opponent
  9. ComputerMove4 /ComputerMove6 / ComputerMove8: Scans the chessboard and makes all possible moves at the next thinking level
  10. CheckMove: Checks the legality and correctness of these possible moves
  11. (if thinking depth reached) => record the score of the final position
  12. (if score of position the best so far) => record the move as best move
  13. The algorithm continues until all possible moves are scanned

You can SET huo_debug to TRUE to see live the progress of the computer thought while the computer thinks. Just press a key to move step-by-step into the Huo Chess inner mechanism… You can also uncomment the code lines that record the time the program requires to think its move, so as to have an idea of the time required by the processor to complete the thinking process.

II. Huo Chess Thought Flow

Below, I analyze the thought flow of the chess program. I will describe only the main steps and code segments, so as to show the way the computer scans the chessboard, conducts all possible moves and finally finds the better one. The function names appear in bold, i.e. ComputerMove - Start indicates the beginning of the ComputerMove() function. Be aware that some code segments may be slightly different from the code in the distributed ZIP file since I continuously change the program. As it appears, the "constant beta" state is the trend nowadays.

ComputerMove - Start

1.       If the first time called -> store initial position.
2.       if( Move_Analyzed >Thinking_Depth)
3.           Stop_Analyzing = true;
4.
5.       if( Stop_Analyzing = false)
         {
6.       Scan the chessboard.
         for iii, jjj
7.       If a piece of the colour of HY is found, 
         call CheckMove to measure how good it is.

Call: CheckMove

CheckMove

4. Number of moves analyzed ++. 
5. Check correctness and legality of move. 
6. Check if possible mate exists. 
7. If move is legal and correct, then do it. 
8. Check if a pawn must be promoted. 
9. Store move to ***_HY variables, because after many calls of ComputerMove and
   CheckMove functions, the initial values of the move analyzed will be lost. 
10. HY_Kobei_Kommati = false;
11.
12. if((ProsorinoKommati->CompareTo("White Bishop") == 0) ||
13. (ProsorinoKommati->CompareTo("Black Bishop") == 0))
14. {
15. HY_Kobei_Kommati = true;
16. Kopsimo_Kommati_Human_value = 3;
17. }
18. elseif((ProsorinoKommati->CompareTo("White Knight") == 0) ||
19. (ProsorinoKommati->CompareTo("Black
20. Knight") == 0))
21. {
[...]
22. If this is the first move analyzed, then record it asthe correct "best" move, 
    no matter how bad it is. 
23. if((ProsorinoKommati->CompareTo("White Queen") == 0) || (
24. ProsorinoKommati->CompareTo("Black Queen") == 0))
25. this->eat_queen = true;
26. else this->eat_queen = false;
27. if(Move_Analyzed = Thinking_Depth)
28. {
29. // Measure the score of the move and record it as best move, if
30.
31. // it is larger than the score of the so-far best move score.
32.
33. }
34. if(Move_Analyzed <Thinking_Depth)
35. {
36. Human_is_in_check = false;
37.
38. WhiteKingCheck = CheckForWhiteCheck(CMSkakiera);
39. if( (this->m_PlayerColor->CompareTo("White") == 0) && (
40. WhiteKingCheck == true) )
41. Human_is_in_check = true;
42.
43. BlackKingCheck = CheckForBlackCheck(CMSkakiera);
44.
45. if( (this->m_PlayerColor->CompareTo("Black") == 0) && (
46. BlackKingCheck == true) )
47. Human_is_in_check = true;
48.
49. Move_Analyzed = Move_Analyzed + 1;
50.
51. Who_Is_Analyzed = "HY";
52.
53. for(i = 0; i <= 7; i++)
54. {
55. for(j = 0; j <= 7; j++)
56. {
57. Skakiera_Move_After[(i),(j)] = CMSkakiera[(i),(j)];
58. }
59. }
60. // Call HumanMove to find the best possible answer of
61.
62. // human opponent to the move currently analyzed
63.
64. // by the computer thought process
65.
66.
67. this->HumanMove(Skakiera_Move_After);

HumanMove

CheckHumanMove - Start

voidCheckHumanMove(array<String^, 2>^ CMSkakiera_Human_Thinking)

Measure move score (if it is legal and correct) -> record the move as "best" move if its score is larger than the so-far best possible human move.

Human_Kobei_Kommati = false;
if((m_FinishingColumnNumber == this->m_FinishingColumnNumber_HY) && (
m_FinishingRank == this->m_FinishingRank_HY))
{
if((ProsorinoKommati->CompareTo("White Bishop") == 0) || (
ProsorinoKommati->CompareTo("Black Bishop") == 0))
{
Human_Kobei_Kommati = true;
[...]

Possible_mate = false;
if( Human_is_in_check == true)
{
WhiteKingCheck = CheckForWhiteCheck(CMSkakiera_Human_Thinking);
if( (this->m_PlayerColor->CompareTo("White") == 0) && (
WhiteKingCheck == true) )
Possible_mate = true;
BlackKingCheck = CheckForBlackCheck(CMSkakiera_Human_Thinking);
if( (this->m_PlayerColor->CompareTo("Black") == 0) && (
BlackKingCheck == true) )
Possible_mate = true;
}

CheckHumanMove - End

Conduct the best human move found.

Move_Analyzed = Move_Analyzed + 1;
Who_Is_Analyzed = "HY";

for(i = 0; i <= 7;i++)
{
for(j =0; j <= 7; j++)
{
Skakiera_Move_After[(i),(j)]=Skakiera_Human_Thinking[(i),(j)];
}
}

if(Move_Analyzed == 2)
this->ComputerMove2(Skakiera_Move_After);
elseif(Move_Analyzed == 4)
this->ComputerMove4(Skakiera_Move_After);
elseif(Move_Analyzed == 6)
this->ComputerMove6(Skakiera_Move_After);
elseif(Move_Analyzed == 8)
this->ComputerMove8(Skakiera_Move_After);
// Call ComputerMove2 to find the best next move of the HY (deeper thinking

ComputerMove2 - Start

voidComputerMove2(array<STRING^, />^ Skakiera_Thinking_2)
{
// Same as…ComputerMove

if(Move_Analyzed == 0)
{
// Same as…ComputerMove
// If we haven't reached the desired level of analysis, then the
// HumanMove will be called again, then again the ComputerMove
// function etc.
}

else
{
// Return to the ComputerMove function of the 'previous' thinking
// level to continue the analysis
Move_Analyzed = Move_Analyzed - 2;
Who_Is_Analyzed = "HY";

for(i = 0; i <= 7; i++)
{
for(j = 0; j <= 7; j++)
{
Skakiera_Thinking[i,j] = Skakiera_Move_0[i,j];
}
}
}
}
ComputerMove2 - End
HumanMove - End
if( this->Move_Analyzed == 0)
{
Kommati_moved = MovingPiece_HY;
STHSIMO = false;
FirstCall_CheckStisimoMove = true;
FirstCll_CheckStisimoMove_2 = true;
eat_queen = false;
hy_eats_the_piece = false;
human_eats_the_piece = false;
Who_Is_Analyzed = "Human";
CheckStisimo(CMSkakiera);
}

CheckMove - End

// close for iii, jjj loops

// close if( Stop_Analyzing = false ) segment
13. If no legal move found, MATE! 
14.if Move_Analyzed = 0
{
15. Check if it is good to conduct castling. 
16. "Redraw" the chessboard with the move found. 
17. Move the rook next to the king, if castling occurred. 
18. Check if a pawn is promoted. 
19. Now it is the turn of the other player to play! 
20.}
21.else
22.{
23.// Return to the ComputerMove function of the 'previous' thinking
24.
25.// level to continue the analysis
26.
27.Move_Analyzed = Move_Analyzed - 2;
28.
29.Who_Is_Analyzed = "HY";
30.
31.for(i = 0; i <= 7; i++)
32.{
33.for(j = 0; j <= 7; j++)
34.{
35.Skakiera_Thinking[i,j] = Skakiera_Move_0[i,j];
36.}
37.}
}

ComputerMove – End

III. Huo Chess Thought Flow Scenario

Below, I illustrate the step-by-step process of the computer's thought for a thinking depth of 2. Let's see the "step" boxes to understand the way the program is structured.

Scenario Details

ComputerMove - Start

Step 1

START

Move_Analyzed = 0

1.       If the first time called -> store initial chessboard position.
2.       if( Move_Analyzed >Thinking_Depth )
3.       Stop_Analyzing = true;
4.       if( Stop_Analyzing = false)
5.       Scan chessboard.
         for iii, jjj
6.       Scan chessboard, find a piece of the HY , conduct move, 
         check correctness and legality of move,
         and if all is OK, then call CheckMove to measure the score of the move. 

Call: CheckMove

CheckMove - Start

  1. Number of moves analyzed ++.
  2. Check correctness and legality of move.
  3. Check if there is a mate on the chessboard.
  4. If the move is correct and legal, then do it.
  5. Check if there is a pawn to be promoted.
  6. Store move to ***_HY variables because, after many calls of ComputerMove and CheckMove functions, the initial values of the move analyzed will be lost.
  7. If this is the first move analyzed, then record it as the correct "best" move, no matter how bad it is.

Step 2

IF result: FALSE
Move_Analyzed = 0
  1. if(Move_Analyzed = Thinking_Depth)
  2. Measure the score of the move and record it as "best" move if it is larger than the score of the so-far best move score.

Step 3

IF result: TRUE
Move_Analyzed = 1
  1. if (Move_Analyzed < Thinking_Depth)

HumanMove - Start

Step 4

Find the best answer of the Human (Move_Analyzed = 1).

CheckHumanMove - Start

voidCheckHumanMove(array<String^, 2>^ CMSkakiera_Human_Thinking)

Count the score of the move and record it as "best"if its score is better than the so-far best move.

CheckHumanMove - End

Conduct the best move of the human.

Move_Analyzed = Move_Analyzed + 1;
Who_Is_Analyzed = "HY";

for(i = 0; i <= 7;i++)
{
for(j = 0; j <= 7; j++)
{
Skakiera_Move_After[(i),(j)]=Skakiera_Human_Thinking[(i),(j)];
}

Step 5

Move_Analyzed = 2

Step 6

CALL next ComputerMove function for next-level move analysis.

Move_Analyzed = 2
if(Move_Analyzed == 2)
this->ComputerMove2(Skakiera_Move_After);
elseif(Move_Analyzed == 4)
this->ComputerMove4(Skakiera_Move_After);
elseif(Move_Analyzed == 6)
this->ComputerMove6(Skakiera_Move_After);
elseif(Move_Analyzed == 8)
this->ComputerMove8(Skakiera_Move_After);

// Call ComputerMove2 to find the best next move of the HY (deeper thinking)

Step 7

Scan the chessboard and find the best move for the computer.

Move_Analyzed = 2
voidComputerMove2(array<STRING^, />^ Skakiera_Thinking_2)
{
// Same as…ComputerMove

if(Move_Analyzed has not reached thinking depth)
{
// Same as…ComputerMove: Call CheckMove -> HumanMove -> next ComputerMove etc
// (If we haven't reached the desired level of analysis, then the HumanMove
// will be called again, then again the ComputerMove function etc.)
}

Step 8

Return to a previous ComputerMove (i.e. ComputerMove4 calls ComputerMove2) function to continue the analysis.

Move_Analyzed = 2 (at the end of the analysis this variable will be equal to 0, see Step 9).

// Return to the ComputerMove function of the 'previous' thinking
// level to continue the analysis

Move_Analyzed = Move_Analyzed - 2;
Who_Is_Analyzed = "HY";

for(i = 0; i <= 7; i++)
{
for(j = 0; j <= 7; j++)
{
Skakiera_Thinking[i,j] = Skakiera_Move_0[i,j];
}
}
}

ComputerMove2 - End

HumanMove - End

CheckMove - End

// close for iii, jjj loop
// close if( Stop_Analyzing = false ) segment

If no legal move is found -> we have MATE!

Step 9

Play the move with the highest score. Now it is the Human's turn to play.

if (move_analyzed==0)
{
  1. Check if it is good to conduct castling.
  2. "Redraw" the chessboard with the best move found.
  3. Move the rook next to the king, if castling occurred.
  4. Check if a pawn is promoted (at the current version computer always promotes a pawn to queen).
  5. Now it is the turn of the other player (human) to play!
}
20. else
21. {
22. Move_Analyzed = Move_Analyzed - 2;
23. Who_Is_Analyzed = "HY";
24.
25. for(i = 0; i <= 7; i++)
26. {
27. for(j = 0; j <= 7;j++)
28. {
29. Skakiera_Thinking[i,j] = Skakiera_Move_0[i,j];
30. }
31. }
}

ComputerMove – End

IV. Flowchart Summary

ComputerMove()
{
for
{
    // First level of thought
    CheckMove()
    {
    if (Move_Analyzed < Thinking_Depth)
    {
        Move_Analyzed++;
        // Find the best possible human move-answer and continue the thinking tree
        Find Best Human Move (HumanMove function);
        Move_Analyzed++;
        Go to next thinking depth

            ComputerMove2()
            {
                for
                {
                    CheckMove();

                    // Think deeper if you have not reached the thinking depth
                    if (Move_Analyzed < Thinking_Depth)
                        [Think deeper, if necessary!];

                    // Record move analyzed as Best Move, if it has the best score
                    if (Move_Analyzed = Thinking_Depth)
                        CountScore();
                        [Record if best move];
                }

            // Return to the initial level of thinking to start
            //analyzing a new thread
            Move_Analyzed = Move_Analyzed – 2;
    }
    }
}
}

V. Huo Chess Micro Edition

I attempted to create a "Micro edition" of Huo Chess by stripping the program off every unnecessary line of code or file. In particular, in order to reduce the size, I used Huo Chess version 0.6 (programmed in C++) and did the following:

  1. Reduced all string/text in the program (i.e. "White Rook" => "WR")
  2. Reduced the length of variable names (in every variable in the program, specific strings were replaced with smaller ones). I don't really know why, but this played a role! Try it yourself to see...
  3. Icon was replaced with smaller one
  4. Removed all unnecessary files (resources, assembly.ccp, stdafx, etc.)

With the above steps implemented, the size was reduced from 53.5 KB to 47.5 KB. However, the code of the program can't be read at all! There is a price for small code...

After processing the final executable file with .NETZ (can be obtained for free from http://www.madebits.com/netz/) the size was reduced to a mere 36 KB. .NETZ is a compression tool that started in Codeproject [see http://www.codeproject.com/KB/dotnet/ReduceDotNetSize.aspx]. You can also look at http://www.jot.fm/issues/issue_2005_09/article1/ in order to see how this reduction in size of the PE (portable executable) is realized. The file is distributed as well tagged as 'Micro Edition' (see the downlodable files at the top of the article).

VI. Huo Chess GUI Edition

I created a Huo Chess edition with Graphical User interface (GUI). For the development of that edition, I used the XNA Game Studio version 3.0 (based on Microsoft Visual Studio 2008). It consists of a simple chessboard which shows the current chessboard state. It does not support mouse move at the moment, so you have to enter the moves via keyboard. More advanced GUI editions with come in the future. It must be noted that the GUI did not affect the total size of the program much. The Huo Chess XNA edition has a total size of 61 KB in the 0.82 version.

VII. Huo Chess Games Archive

That segment contains games played by Huo Chess versus other micro chess programs.

GAME 1

Date: 2007-11-11
Place: Athens, Greece
White: HuoChess v0.4 (with Opening Book) [as distributed by The Code Project]
Black: Microchess (as provided by BenLo Park)
Result: Draw by threefold repetition

1.       d4 Nc6
2.       d5 Nb4
3.       Nc3 e5
4.       Bg5 Qxg5
5.       Nh3 Qg4
6.       e4 Qh4
7.       Be2 d6
8.       Bb5+ Kd8
9.       Nf4 Qxf4
10.      h3 Nf6
11.      f3 Qe3+
12.      Be2 Bd7
13.      f4 Qg3+
14.      Kd2 Qxf4+
15.      Ke1 Qg3+
16.      Kd2 Qf4+
17.      Ke1 Qg3+
18.      Kd2 Qf4+
19.      Ke1 Qg3+
20.      Kd2 Qf4+
21.      Ke1 [draw by threefold repetition] 

GAME 2

Date: 2007-11-11
Place: Athens, Greece
White: Microchess (as provided by BenLo Park)
Black: HuoChess v0.4 (with Opening Book) [as distributed by The Code Project]
Result: Draw by threefold repetition

1.       e4 e6
2.       Qh5 d6
3.       Bb5+ Ke7
4.       Qg5+ f6
5.       Qh5 h6
6.       d4 g6
7.       Qxg6 Nd7
8.       Bf4 f5
9.       exf5 Ndf6
10.      fxe6 Bxe6
11.      a4 Bg7
12.      Qxg7+ Bf7
13.      Qxh8 Bh5
14.      Qg7+ Bf7
15.      Nc3 h5
16.      Nf3 Nh7
17.      Nd5+ Ke6
18.      c4 c6
19.      Nc7+ Qxc7
20.      d5+ cxd5
21.      Nd4+ Ke7
22.      Nf5+ Ke6
23.      Nd4+ Ke7
24.      Nf5+ Ke6
25.      Nd4+ Ke7
26.      Nf5+ Ke6
27.      Nd4+ Ke7
28.      Nf5+ [draw by threefold repetition]

GAME 3

Date: 2008-01-22
Place: Athens, Greece
White: Microchess (as provided by BenLo Park)
Black: HuoChess v0.5 (with Opening Book) [as distributed by The Code Project]
Result: Draw by threefold repetition

1.       e2-e4 e7-e6
2.       d1-h5 c7-c5
3.       f1-b5 g8-f6
4.       h5-e5 f6-g4
5.       e5-f4 g4xf2
6.       e1xf2 g7-g5
7.       f4-e5 a7-a6
8.       b5-c4 f7-f6
9.       e5-g3 d7-d6
10.      g1-h3 h7-h6
11.      h1-e1 e8-e7
12.      b1-a3 d8-b6
13.      d2-d4 b6-a5
14.      c1-d2 a5xd2+
15.      e1-e2 d2xd4+
16.      16.f2-f3 d4xb2
17.      a1-d1 b2xa3+
18.      c2-c3 a3xc3+
19.      c4-d3 a6-a5
20.      f3-g4 e7-d7
21.      d3-b5+ d7-e7
22.      g3xc3 f8-g7
23.      e2-f2 e7-f7
24.      d1xd6 a8-a7
25.      c3xc5 b8-c6
26.      f2-f3 b7-b6
27.      c5xb6 c8-d7
28.      f3-c3 e6-e5+
29.      d6xd7+ a7xd7
30.      b5-c4+ f7-e7
31.      b6-c5+ d7-d6
32.      c3-d3 c6-d4
33.      c5-c7+ d6-d7
34.      c7-c5+ d7-d6
35.      c5-c7+ d6-d7
36.      c7-c5+ d7-d6 [draw by threefold repetition]

GAME 4

Date: 2008-02-22
Place: Athens, Greece
White: Microchess (as provided by BenLo Park)
Black: HuoChess v0.6 (without Opening Book) [as distributed by The Code Project]
Result: Draw by threefold repetition

1.       Nf3 d5
2.       Nc3 Qd6
3.       Na4 Qf4
4.       c3 Bd7
5.       d4 Qe4
6.       Ng5 Qg4
7.       f3 Qh4+
8.       g3 Qh5
9.       Nc5 Bb5
10.      b3 f6
11.      Nge6 b6
12.      e3 Bc6
13.      Nd3 Bd7
14.      Nxf8 Kxf8
15.      Nf4 Qg5
16.      Ne2 Nc6
17.      f4 Qg4
18.      h3 Qf3
19.      Rh2 Nh6
20.      Kd2 Nf5
21.      Kc2 Qe4+
22.      Kb2 Qf3
23.      Kc2 Qe4+
24.      Kb2 Qf3
25.      Kc2 Qe4+

Huo Chess (even without Opening Book) managed to play a very good game, during which it played well-structured chess. It didn't conduct any wrong moves, didn't give up any pieces and had a better position than Microchess at the end of the game (when the threefold repetition resulted in a draw).

GAME 5

Date: 2009-01-25
Place: Athens, Greece
White: Microchess (as provided by BenLo Park)
Black: HuoChess v0.82 (with Opening Book) [as distributed by The Code Project]
Result: Draw by threefold repetition

1. e4   e6
2. Qh5  Qe7
3. Bc4  Kd8
4. d4   a6
5. Bf4  d5
6. exd5 f5
7. dxe6 Bxe6
8. Bxe6 g6
9. Qe2  Nd7
10. Bxc7+ Kxc7
11. Qc4+ Nc5
12. dxc5 Qg7
13. Qf4+ Kc6
14. Qf3+ Kxc5
15. Qd5+ Kb6
16. Qb3+ Kc7
17. Qc4+ Kd6
18. Qd5+ Kc7
19. Qc4+ Kd6
20. Qd5+ Kc7
21. Qc4+ Kd6
22. Qd5+  draw by threefold repetition

Huo Chess played a good game. It did not give up pieces without reason and did not lose chances to kill opponent’s pieces when possible.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralA simple optimization
zlezj
21:48 22 Apr '09  
A simple optimization would be to replace all strings by Enums. for instance comparisons will be faster. Whenever you want to display the value of the Enum, just use enumValue.ToString().
GeneralRe: A simple optimization
Palavos
2:00 23 Apr '09  
Thanks! Will do in the upcoming versions. Cool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

NewsHuo Chess AI engine possible optimizations
Palavos
5:07 4 Feb '09  
It seems that the AI engine of Huo Chess does not know when to "stop" analyzing the situation. Thus, the program may analyze in a great depth the chessboard and find out that in 4 moves (= 8 half-moves) it may win the queen of the opponent, without "seeing" that in the next move the opponent will win by mate. I am currently trying to optimize the code concerning that issue.

Please send me any comments for the program! Cool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

NewsINSTRUCTIONS for Huo Chess GUI Edition
Palavos
5:06 4 Feb '09  
How to use Huo Chess GUI Edition:
1. Start the program.
2. Select your colour by pressing "w" or "b" for white or black respectively.
3. Enter your move either via keyboard (write starting column-rank and finishing column-rank) or via mouse (click the starting and then the destination square). Cool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

GeneralMy vote of 1
AlexB47
4:06 4 Feb '09  
sedness
GeneralMy answer for the vote of 1
Palavos
4:57 4 Feb '09  
I will just repeat the answer to the vote of 1 below:
When a programmer has put effort in implementing an idea then criticism should be something more than one word. I can accept comments with specific content (about the algorithm, the article appearance, etc), but not one word statements. Cool
Thanks anyway for the vote! Cool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

GeneralMessage Automatically Removed
Tomas Rapkauskas
5:05 12 Jan '09  
Message Automatically Removed
GeneralMy answer for the vote of 1
Palavos
6:40 12 Jan '09  
So is the justification of your vote. Cool
When a programmer has put effort in implementing an idea then criticism should be something more than one word. Writting "poor" is not a comment! I can accept comments with specific content (about the algorithm, the article appearance, etc), but not one word statements.
Thanks anyway for the vote! Cool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

GeneralRe: My vote of 1
Julian Nicholls
1:28 3 Feb '09  
OK, point me to your chess-playing program article...
GeneralAlpha beta pruning
LuckyJaker
11:57 28 Jan '08  
I suggest you read about alpha beta pruning, it makes the game a lot faster,
I once wrote an Othello (some 20 years ago) in assembly using that technique...
it was able to beat the university computer!, all that with a 0.89 MHz computer,
look at that algorithm, it should be easy to implement given the method used.

Have a nice day and have fun !
GeneralRe: Alpha beta pruning
Palavos
22:32 28 Jan '08  
Thanks! I read it and future versions will be improved. Cool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

GeneralRe: Alpha beta pruning
KarstenK
23:00 28 Jan '08  
It is a pitty that the comments are not in English.Dead

Greetings from Germany

GeneralComments translation
Palavos
3:35 29 Jan '08  
Unfortunately most of them is in Greek, but I've made an effort to write the basic comments in English.
However, please tell me which comments you want translated and I will try to translate as soon as I can - at least the main points.

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

Generalspecific=)
cem oguzhan
1:28 2 Nov '07  
i am using microsoft visual c++ 6.0 introductory edition
and the errors given after compiling the source code are as follows
c:\documents and settings\cem oðuzhan\desktop\source\huochessconsole\huochessconsole\huochessconsole.cpp(5) : error C2871: 'System' : does not exist or is not a namespace

c:\documents and settings\cem oðuzhan\desktop\source\huochessconsole\huochessconsole\huochessconsole.cpp(6) : error C2653: 'System' : is not a class or namespace name

c:\documents and settings\cem oðuzhan\desktop\source\huochessconsole\huochessconsole\huochessconsole.cpp(6) : error C2871: 'IO' : does not exist or is not a namespace

c:\documents and settings\cem oðuzhan\desktop\source\huochessconsole\huochessconsole\huochessconsole.cpp(8) : error C2143: syntax error : missing ';' before ''

c:\documents and settings\cem oðuzhan\desktop\source\huochessconsole\huochessconsole\huochessconsole.cpp(8) : error C2501: 'ref' : missing storage-class or type specifiers

c:\documents and settings\cem oðuzhan\desktop\source\huochessconsole\huochessconsole\huochessconsole.cpp(8) : fatal error C1004: unexpected end of file found

thank you
GeneralSOLUTION
Palavos
3:44 2 Nov '07  
My friend,
If you look up at the web site you will see 'C++ (VC 8.0)' written there. This means that the program is developed for C++ version 8.0.
That is why your C++ v6.0 does not recognize some namespaces (=collection of classes) I use in the program.
The only way to fix that is to download the Visual Studio 2008 - Express Editions from the link I gave you in my last post and compile the source from that! Visual Studio 2008 supports C++ 8.0.
Please give me feedback on your progress on that.
See you!

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

Generalversions
cem oguzhan
0:49 2 Nov '07  
there is only one source to download and it is 37.5k. which version is that one?
Generalcompile 2
cem oguzhan
0:37 2 Nov '07  
i have used the visual c++ to compile the code if there are any errors, which i could not.
it gave 4 errors, three not very important ones, like quotatio or comma. but the first error was crutial, it said "the system does not exist or is not a namespace".
it is in the second line
GeneralInstructions on how to compile
Palavos
0:51 2 Nov '07  
Please be more specific.
> What do you mean by "visual c++"? Which version of Visual Studio? I must know that in order to help you.
> You can download the Visual C++ 2008 Express Edition for FREE from http://msdn2.microsoft.com/en-us/express/future/bb421473.aspx[^]
> You should do the following: Download the source => unzip => Open the solution with the MS Visual Studio 2008 => Hit F5.
> Please send me the errors produced analytically.

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

Generalcompile
cem oguzhan
6:49 1 Nov '07  
hi, i have downloaded the source from this page , bu t i cannot compile it. what program should i use and how could i use it. i also have tried to compile it by using "visual c++", but it also gave errors while compiling.
i would be glad if anyone who helps me.. thank you

cem
GeneralRe: compile
Palavos
23:05 1 Nov '07  
The source code compiles normally with Visual Studio 2008 (even Express Editions which can be downloaded for free).
Which IDE or tool do you use to compile it?

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

NewsHuoChess SUCCESS @ Game versus Microchess [modified]
Palavos
21:46 22 Oct '07  
Micro Chesses Tournament: HuoChess v0.3 vs. Microchess
[tournament in Athens, Greece featuring chess programs less than 100 KB in size]
************************************************************************************************

GAME I
Date: 2007-10-18
Place: Athens, Greece
White: HuoChess v0.3 (as provided by Codeproject site)
Black: Microchess (as provided by http://www.benlo.com/microchess/microchess.html[^])
Result: Black wins (mate)

1. d4 Nc6
2. d5 Nb4
3. e4 Nf6
4. a3 Nxc2+
5. QxNc2 e5
6. Bg5 Bb4+
7. axBb4 Qe7
8. Ra2 Qxb4+
9. Bd2 Qd4
10. Qxc2 Qxe4+
11. Be3 QxNb1+
12. Kd2 Ne4+
13. Ke2 QxRa2
14. Qxe5+ Kd8
15. Qxg7 Qc4+
16. Kf3 Nd2+
17. BxNd2 Qxd5+
18. Kg4 d6+
19. Kh4 Qe4+
20. f4 Qe7+
21. Qg5 f6
22. Qa5+ b6
23. Qd5 f5+
24. Kh5 Qe8+
25. Kh6 Qg6++ Cry


GAME II
Date: 2007-10-18
Place: Athens, Greece
White: Microchess (as provided by http://www.benlo.com/microchess/microchess.html[^])
Black: HuoChess v0.3 (as provided by Codeproject site)
Result: Draw by threefold repetition

1. e4 e6
2. Qh5 h6
3. d4 Bb4+
4. Kd1 d6
5. Bb5+ c6
6. Bc4 Nf6
7. Qf3 Nh7
8. Qh5 Nf6
9. Qf3 Nh7
10. Qh5 Nf6 Poke tongue

[Note: Neither program has the capability to recognize a draw by threefold repetition - they just kept playing the same moves]

Future versions of HuoChess are on the way...


-- modified at 3:01 Tuesday 23rd October, 2007

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

NewsHuoChess v0.2 vs. Microchess
Palavos
10:46 17 Oct '07  
Game played on 2007-10-17
*************************
White: Huo Chess v0.2
Black: Microchess

1. e3 e5
2. Nf3 e4
3. Nd4 Qf6
4. a3 Bc5
5. Nb3 Bd6
6. Nc3 Nc6
7. Nxe4 Qe5
8. d3 Be7
9. f3 Bh4+
10. g3 Be7
11. Na5 Qxa5+
12. c3 Qe5
13. b3 d5
14. Bh3 Bxh3
15. f4 Qf5
16. Nc5 Bxc5
17. Ra2 Nf6
18. Rb2 Bxa3
19. Ra2 Bc5
20. Ra4 b5
21. Ra2 Rb8
22. Rxa7 Nxa7
23. Ba3 Bxa3
24. d4 Qe4
25. Qc2 Qxc2
26. e4 Qxc3+
27. Ke2 Bg4+
28. Kf2 Nxe4+
29. Kg2 Qd2+
30. Kf1 Qf2#

Huo Chess lost... Cry Sigh Cool
But it'll be back! Poke tongue

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

GeneralWondering about basic design decsions ...
Stefan63
23:17 14 Oct '07  
Hi Palavos,

I didn't check all the code, only the basic structure. I noticed you used a completely different design than what I would have chosen:

You store your board as an array that may or may not contain a piece, which in turn has no behaviour of it's own. Then you write various functions that check various aspects of possible moves depending on the piece stored. Since some of the pieces are bound to have similar behaviour concerning some of these functions, don't you think code size could be reduced by an object-oriented approach?

My idea is to construct a basic class for chess pieces that contains all the functions that deal with chess piece 'behaviour'. Those that are equal for all pieces can be implemented right away, others could be implemented virtually with some kind of default behaviour, and some might be defined abstract. Different piece classes cuold be derived from that basic class and special behaviour filled in where needed.

The gain in such a concept wrt to your goal of minimizing code size would be avoiding duplicate code and maximum code reuse. You would lose some of that however due to imlpicitely generated code for the class structure and inheritance issues. These losses again are covered in part because the framework of an oo class structure will spare you many of the 'if' or 'switch' statements you currently need. I honestly don't know however if the losses would outweigh the gains. What do you think?

Even if there's no gain in size, an oo-micro chess would be even more thrilling to see as a size-minimising project: many people seem to think program bloating stems from modern program designs, but as a matter of fact, oo-designed programs do not neccessarily need more space than procedural designs - provided the designer knows his job! Wink
GeneralRe: Wondering about basic design decsions ...
Palavos
1:18 15 Oct '07  
You are RIGHT. I should do something like that. All these 'if' statements are really problematic and should be replaced with some more EFFICIENT code, like the one you describe.
You gave me some things to think... D'Oh!
I'll get back to you when I have something new. Really appreciate the time you spent seeing the code!
Talk to you soon!

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]

GeneralMicrochess vs. Huo Chess v0.2
Palavos
1:31 11 Oct '07  
You can find a copy of the Microchess at http://www.benlo.com/microchess/microchess.html[^].
I fixed some bugs in HuoChess and version 0.2 is on the way. When it is ready I will have both programs play to see what happens...
The bad news is that Huo Chess v0.2 is larger is size (99 KB). Sorry about that! I will try to reduce it back to the 49 KB of the version 0.1.
SmileBig GrinLaughWink;PSniff:(SighD'Oh!CrySleepy:->Red facedRoll eyesOMGWTFMadConfusedUnsure Hmmm Dead SuspiciousCool

Per ardua ad astra, per ignem vincimus!
http://www.kakos.com.gr[^]


Last Updated 22 Apr 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010