C#, C# programming, Chess, chess algorithm, chess source code in Java, free chess, how to create a chess program, how to program, Huo Chess, Java source code, open source, open source chess, open source chess in Java, programming
Huo Chess News
- 2021-04-07: Re-optimization of CountScore (evaluation of position) function for endgames regarding the pawns evaluation.
- 2021-04-03: Optimized the CountScore (evaluation of position) function for endgames. Huo Chess v0.9921 beat bot at Chess.com with 1100 ELO rating.
- 2021-03-20: Added the castling capability also for the computer (up to now, the program only recognize and allowed the castling move for the human opponent).
- 2021-03-14: Thinking in level 4 and 5 is conducted only if the moves entail the capturing of a piece. Removed redundant code. Improved CountScore function with positional elements for the ending of the game. Introduced the elements of mate and stalemate in the thinking process.
- 2021-01-06: Fixed initialization of nodes 3 and 4.
- 2020-09-03: Minor updates.
- 2020-08-10: Updated the countScore function that evaluates positions to include also qualitative criteria for the position.
- 2020-08-03: Minor updates to the v0.992 Developers Edition. The trimming rules have been updated to enable deeper thinking.
- 2019-02-21: The v0.992 has received initial operational capability. The algorithm now works for thinking depth of 5 half-moves, with thinking tree trimming applied.
- 2019-02-12: Huo Chess version 0.991 published. Now the algorithm performs as planned. Thinking depth limited to 3 half-moves.
Huo Chess Overview
The Huo Chess is one of the smallest open source chess programs in C# (the latest console version is only 44 KB is size). It has heavily commented source code so that it can be used for teaching purposes on how to develop a chess program (or a program in general). It can be easily reused in other applications, e.g. to use it as a chess engine for a robot playing chess (see here).
Feel free to re-use it as you see fit (including changing it or selling it), as long as the source is cited properly. The goal is to spread the knowledge on the basics of chess programming, so sharing is important. Feel free also to contribute to the project, by contacting Harmonia Philosophica with ideas or code that can be used.
Huo Chess sites
You can download the latest files via the relative sites:
Alternatively you can download it below.
Important Notes: The latest version of Huo Chess that is still in development is available only in this site and in GitHub repository. The CodeProject and the MSDN sites have only the latest stable version, which currently is v0.992.
Huo Chess-based tutorials
Over the years I have written several tutorials on how to develop a chess program based on the Huo Chess.
Tutorials on how to develop a chess program include:
- How to develop a chess program for dummies series
- How to code a chess program in one day (C# and Java examples)
- Programming for kids: Developing a chess program in BASIC
- Programming a chess application in QBasic (QB64)
Version 0.9921 highlights
The new version of Huo Chess (v0.9921) is even smaller in size than all the previous ones and yet much more capable. This was made possible by optimizing code and removing redundant code as well. The official edition with Windows Forms user interface is 77 KB in size (as opposed to 78 KB of the previous version), the Console application with a chessboard User Interface (UI) edition is 45 KB (as opposed to the 46 KB of version v0.992) and the Console application with text-based chessboard UI edition is 44 KB in size (whereas the previous version was 46 KB in size).
The new version has an updated evaluation function (CountScore) for the endgame, it has improved code for the castling move and also has an optimized deep thinking mechanism.
Huo Chess v0.9921 editions
- Huo Chess 0.9921 with GUI: This version is the main version with a Windows Forms chessboard User Interface.
- Huo Chess 0.9921 cs: Console application (text only).
- Huo Chess 0.9921 cs with graphics: Console application, with minimum text-graphics to depict the chessboard.
- Huo Chess 0.9921 Developers version: Full developers version with Windows Forms chessboard and logs to show the thinking mechanism. (Attention: Remember to delete the logs when needed, since their size can increase significantly)
Version 0.992 highlights
The v0.992 version of Huo Chess is small in size (as all the previous ones) and much more capable. The official edition with Windows Forms user interface is 78 KB in size, the Console application with a chessboard User Interface (UI) edition is 46 KB and the Console application with text-based chessboard UI edition is 46 KB in size.
Issues with the MiniMax thinking algorithm are fixed and now the computer makes logical moves in every circumstance (at least for the depth of 5 half-moves in which it thinks). Capability of thinking at depth of more half-moves will be added in the future. The program also features an Opening book capability (must have positions in the “Opening Book” folder to use it).
Additional to the above, a Developers Edition has been created, which includes analytic logs of the thinking mechanism for debugging (for teaching purposes). The logs can be easily activated or deactivated. This edition also takes a small step towards showing the variant which the computer thinks to the user interface.
The Opening Book editor is distributed separately. Along with the editor, a library of some sample opening book positions is also included in the distribution files.
Huo Chess editions
There are various Huo Chess editions, each one with slightly different User Interface, plus one for developing purposes.
The table above summarizes the features and the differences between the various v0.992 (also applies for the latest version v0.9921) Huo Chess available editions.
Future versions candidate improvements
There is already a list of potential improvements for the next version of Huo Chess (0.9922), which can be found below:
- Add castling capability for the computer to also be able to castle. Also castling should be embedded in the CountScore function.
- Reduce size by improving ‘peripheral’ functions (like CheckForBlackMate, ElegxosNomimotitas et cetera).
- Increase efficiency of MiniMax algorithm, by taking into account the average score of each branch. (code already in place, but commented out)
- Add neural network capability: This will be achieved at a very primitive level by having key points of the MiniMax algorithm (the inequalities at each node level analysis in ComputerMove) being dependent of values stored in external configuration files and by updating those files every time a game is played (increase ‘score’ if the game is a win, decrease if it resulted in defeat). This is still in preliminary stage, but I will try to have a relative Developer edition ready in the next version (without compromising the size).
- Improve CountScore function, to take into account the position of the chessboard, whether you move the same piece twice in the opening et cetera.
Huo Chess v0.9921 distribution files
The version 0.9921 of Huo Chess is currently in development. Take a look at the progress of the project exclusively here at Harmonia Philosophica or directly in the GitHub repository. The code is updated frequently.
Note that this is a draft version which is still under development. Also please remember to delete the logs after some moves, or disable them completely if you want to play a full game. The size of the logs of the Developers edition can increase significantly after only some moves.
Di mi se mai fu fatta alcuna cosa
(Tell me if anything was ever done to completion)
~ Leonardo da Vinci
Huo Chess v0.992 distribution files
The version 0.992 of Huo Chess is in development. Take a look at the progress of the project exclusively here at Harmonia Philosophica! The code is updated frequently.
All the files of the v0.992 can be found below. Make sure you download the latest one. The previous versions are kept for historical reference purposes. Also at the end feel free to download the latest v0.9921 version that is still in development
This version is the officially stable version that can also be found in the GitHub repository and the official sites (like CodeProject) which host the Huo Chess code.
Huo Chess v0.991 distribution files
Distribution files for the Huo Chess v0.991 version include the following:
- Huo Chess 0.992 with GUI
- Huo Chess 0.992 cs
- Huo Chess 0.992 cs with graphics
- Huo Chess 0.992 Developers version
- Opening Book editor
- Opening Book
Feel free to contact me for anything regarding the code or the project in general. Remember that the goal is not only to create the smallest chess program but also to create a good basis for educational purposes.
Huo Chess Opening Editor
From the beginning of the Huo Chess project (well, almost from the beginning), an opening functionality was developed. The opening book of Huo Chess is edited with the help of a dedicated tool: the Huo Chess Opening Editor. Simply run the tool, play the moves by selecting “Opening mode” and all the moves will be stored as suggested moves for the computer in its opening book.
There is a C++ (cpp) and a C# (cs) version of the tool, which can be both downloaded below.
The tools generate txt files which hold the positions of the opening book, along with the suggested moves for each position. Note that there must exist a ‘Huo Chess Opening Book‘ folder in the same folder as the application for the latter to store the opening book files.
Make sure you keep checking back in this page for more updates.
Huo Chess Java edition
The Java edition of Huo Chess is also developed in parallel with the C# versions. Currently, only the core engine with text interface with the user is developed in Java. Anyone willing to provide a GUI is more than welcome to do so. (I will try to do that as soon as I have time)
This code can be the basis for an Android Huo Chess application. I am currently working with Visual Studio and Xamarin framework to build it.
Huo Chess QBasic edition
The Huo Chess has been written in QBasic as well. Yes, you read it right! The old friend from the past, BASIC, is still alive and kicking!
You can find the code below. Along with the games’ source code, an opening editor is also distributed. Both work in the same way the C# edition works.
Feel free to write to me for any comments or suggestions.
Instead of epilogue…
The ultimate goal is to go back to where I begun programming and fulfill my child dream: to create a chess program for Commodore 128. The porting of the current Huo Chess version to QBasic is currently in progress and then the road to porting to Commodore BASIC v7.0 is open…
And remember: Huo Chess was not made to be completed. But exactly the opposite: It is here to remind us all the constant struggle to perfection. A struggle so vain as any other human struggle and yet, a struggle so familiar and lovely.
Huo Chess will constantly be upgraded…
By me… By you… By everyone…
And year by year it will constantly be better and smaller…
Until there is nothing left…
Because at the end, the best chess game I will ever play will be that game I played as a child, with my father, trying to learn how to play…
APPENDIX – Huo Chess games
This appendix contains various games played by Huo Chess over the years.
Game 1: Huo Chess v0.9921 vs. Jimmy bot (600 ELO rated) at Chess.com
1. g4 g5 2. Nc3 d5 3. Bh3 Nc6 4. Nf3 h6 5. d4 Qd6 6. Be3 b6 7. Bd2 Nb4 8. Nb5 Qd7 9. Nxa7 Rxa7 10. Bxb4 Nf6 11. Ba3 Ba6 12. c3 Bc4 13. Ne5 Qb5 14. Bg2 Ra4 15. e3 Qa5 16. b4 Ba6 17. bxa5 Rxa5 18. Bb2 Bg7 19. Qf3 Bb7 20. c4 h5 21. gxh5 Ra7 cxd5 Ra6 23. e4 Bh6 24. Bc1 Ra4 25. Be3 O-O 26. Kd1 Ba6 27. Nc6 Kh7 28. Nxe7 Ra5 29. Qxf6 Bd3 30. Nf5 Kg8 31. Nxh6+ Kh7 32. Bxg5 Raa8 33. Nxf7 Rxf7 34. Qxf7+ Kh8 35. Bf6# 1-0
The game resulted in Huo Chess easily beating the bot within 35 moves.
Game 2: Huo Chess v0.9921 vs. Jimmy bot (600 ELO rated) at Chess.com
[Event “vs Computer”]
1. g4 g5 2. Nc3 e5 3. e4 Ne7 4. Nf3 f6 5. Bb5 Ng8 6. Ba4 Nh6 7. d4 a6 8. dxe5 c6 9. exf6 Kf7 10. Nxg5+ Kg6 11. Ne6 Rg8 12. Nxd8 d6 13. Bxh6 Kxh6 14. Nf7+ Kg6 15. Nxd6 b5 16. Bb3 Bxd6 17. Bxg8 Bc5 18. Qf3 h6 19. Ne2 Bb6 20. Nc1 Bd8 21. c4 Bxf6 22. cxb5 cxb5 23. e5 Bxg4 24. Qxa8 Bxe5 25. Qe4+ Kf6 26. Qxg4 Ke7 27. Qe6+ Kd8 28. Qxe5 Nd7 29. Qd6 h5 30. Be6 Kc8 31. Qxd7+ Kb8 32. Qe8+ Kc7 33. Qxh5 Kb7 34. Bd5+ Ka7 35. Nb3 Kb8 36. Rd1 Kc7 37. Qg6 a5 38. Nxa5 b4 39. Qg4 Kb6 40. Qxb4+ Ka6 41. Nb3 Ka7 42. Qb7# 1-0
Game 3: Huo Chess v0.9921 vs Sven bot @ Chess.com (1100 ELO rated)
[Event “vs Computer”]
1. g4 g6 2. Nc3 d5 3. Bh3 c6 4. d4 Nf6 5. Be3 h6 6. Bd2 Na6 7. Nf3 Nb8 8. Bf4 Nxg4 9. Rg1 h5 10. e4 Be6 11. exd5 cxd5 12. Ng5 Bh6 13. Nxe6 fxe6 14. Bxb8 Rxb8 15. Rh1 Bg7 16. Rb1 Qb6 17. Qd3 Rh6 18. Qd2 Ra8 19. Na4 Qd6 20. Nc5 b5 21. Nb7 Qa6 22. Nc5 Qd6 23. Nb7 Qa6 24. Nc5 Qxa2 25.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 28. Bc7 Rb7 29. Ra8+ Kf7 30. Rxg8 Rxc7 31. Rh8 Rxc2 32. Rxh7+ Bg7 33. Rf1 Rc6 34. Nc3 Rb6 35. Na4 Re6 36. g5 Rc6 37. Rg1 Nf3+ 38. Kf1 f5 39. Rg2 Kg8 40. Rg3 Nd4 41. Rh4 Rc2 42. b4 Be5 43. Re3 Rc1+ 44. Kg2 Nc6 45. Rh6 Bg7 46. Rxg6 Kh8 47. b5 f4 48. Re4 Nd4 49. b6 e5 50. Nb2 Kh7 51. Rd6 Nb3 52. Nc4 Ra1 53. Bf5+ Kg8 54. Nxe5 Nc5 55. Rd8+ Bf8 56. Rxf4 Kg7 57. Ng6 Ra4 58. Rf3 Be7 59. Nxe7 Rh4 60. Rd5 Ne4 61. Rd4 Nxg5 62. Rxh4 Kf7 63. Re3 Kf8 64. Re5 Kf7 65. b7 Nf3 66. Kxf3 Kf8 67. b8=Q+ Kg7 68. Qa8 Kf6 69. Qh8+ Kf7 70. Rh7# 1-0
More games to be uploaded soon with stronger opponents!