Lazarus

Programming => Packages and Libraries => Ported from Delphi/Kylix => Topic started by: typo on October 14, 2011, 07:06:17 pm

Title: Porting TChessBrd from Delphi
Post by: typo on October 14, 2011, 07:06:17 pm
I am porting TChessBrd component from Delphi. It was written on year 2000. It uses a TImageList to draw drag images, which fails completely in Lazarus. I was not able to understand what is going on with TImageList and simply canceled the corresponding code.

I have replaced the drag functionality and resources by Lazarus style ones and canceled the animation. Maybe someone could have a better idea.

Code attached.
Title: Re: Porting TChessBrd from Delphi
Post by: BigChimp on October 14, 2011, 07:12:21 pm
Sorry, no suggestions, but can I hope you're helping Felipe with his ChessFPC program?  :D
Title: Re: Porting TChessBrd from Delphi
Post by: typo on October 14, 2011, 07:18:10 pm
Well, I have improved the notation, maybe he can use on his program. Animation is better there.
Title: Re: Porting TChessBrd from Delphi
Post by: typo on October 14, 2011, 11:48:59 pm
Demo attached.
Title: Re: Porting TChessBrd from Delphi
Post by: User137 on October 14, 2011, 11:59:34 pm
It's using deprecated .lrs resource file and hangs up on close. Has to be forced to stop by Lazarus. It's also not showing anything on form.
Title: Re: Porting TChessBrd from Delphi
Post by: typo on October 15, 2011, 12:42:47 am
Bitmap attached.
Title: Re: Porting TChessBrd from Delphi
Post by: felipemdc on October 15, 2011, 09:48:46 am
Sorry, no suggestions, but can I hope you're helping Felipe with his ChessFPC program?  :D

This seams to have no relation with fpchess. In fpchess there is a chess drawing component which supports animations.
Title: Re: Porting TChessBrd from Delphi
Post by: typo on October 15, 2011, 10:32:54 am
My notation obeys the rules of FIDE and supports multi-language.
Title: Re: Porting TChessBrd from Delphi
Post by: typo on October 19, 2011, 12:29:04 pm
Fixed ChessBrd.pas attached.
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 19, 2013, 04:15:58 pm
Any ideas how to use chess engine, for example houdini with this?

I did also find critter engine http://sourceforge.net/projects/critterchess/ 

It's Delphi project, but works fine (just open dpr). Tested 1.1 & FPC2.71, Win32
Title: Re: Porting TChessBrd from Delphi
Post by: typo on July 19, 2013, 04:53:26 pm
It is necessary to adapt the code for an engine. I did not do it yet.

The board itself works very well.

If you are interested on working a bit on this, try to learn the engine protocols:

http://en.wikipedia.org/wiki/Chess_Engine_Communication_Protocol

Houdini 1.5 is freeware.

http://www.houdinichess.com/

I like to play against this chess board because it is the only I can win.
Title: Re: Porting TChessBrd from Delphi
Post by: eny on July 19, 2013, 07:54:39 pm
For a basic version it looks nice  8)
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 20, 2013, 11:13:15 am
If you are interested on working a bit on this, try to learn the engine protocols:
Was hoping for code example.

I started houdini with createprocess. But when I send commands, nothing happens. Commands do appear in console, but not work.

However, if I manually type commands to this console, then it works.
Title: Re: Porting TChessBrd from Delphi
Post by: BigChimp on July 20, 2013, 11:17:49 am
@Timewarp: likewise, it's useless to discuss code without posting it. Perhaps attaching your code could help: project menu/publish project, zip up the resulting directory with source files and attach it to a post or upload it somewhere...
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 20, 2013, 12:27:03 pm
it's useless to discuss code without posting it.
I didn't post it, because my code is no use, it doesn't work.

But now attached what was my basic idea. You need "Houdini_15a_w32.exe" in same folder. (Link was posted previously)

Not sure this is even correct idea. I can find examples how to create an engine, but not a single GUI example.
Title: Re: Porting TChessBrd from Delphi
Post by: BigChimp on July 20, 2013, 12:53:40 pm
Some random guesses:
1. Buffering
Perhaps the output to houdini is buffered and you need to explicitly clear the buffer?
see
http://www.open-aurec.com/wbforum/WinBoard/engine-intf.html#6

2. Hmmm, you're using direct win API calls it seems. Perhaps you'll have more success with TProcess?
http://wiki.lazarus.freepascal.org/Executing_External_Programs

3. You start with a go command - perhaps you need to set up houdini first (e.g. choose a side, perhaps type of game (timed, normal etc) and start the game, e.g using the new command)
http://www.open-aurec.com/wbforum/WinBoard/engine-intf.html#8
Title: Re: Porting TChessBrd from Delphi
Post by: Leledumbo on July 20, 2013, 01:31:04 pm
Quote
I didn't post it, because my code is no use, it doesn't work.
Then how we do know what's wrong and what to fix?
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 20, 2013, 02:45:42 pm
Thanks for suggestions.

1. I don't think code uses buffering. Command appears to console.
2. Changed to use TProcess, but same problem remains.
3. I have tried other commands. "go" should work, because it works when typed manually.
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 20, 2013, 05:22:22 pm
Attached working one, if anyone interrested. (atleast seems to work in WinXP)

Now when send/receive works, it's possible to merge..
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 22, 2013, 12:44:20 pm
The board itself works very well.
Do you have any plans to improve component?

It seems DragObject is leaked every move

DragObject := TChessDragObject.Create(Self, Bmp);

Quick check, something like this stops it (heaptrc)

if assigned(MyDragObject) then MyDragObject.Free;
MyDragObject := TChessDragObject.Create(Self, Bmp);
DragObject := MyDragObject;

But it's still leaked once. Ideas how to fix it properly? (Free MyDragObject on exit crashes)
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 28, 2013, 02:58:08 pm
Attached demo. It uses 3seconds/move. Houdini_15a_w32.exe needs to be in project dir. http://www.houdinichess.com/ Component doesn't have to be installed.

Few changes to chessbrd component:

- Restored original drag/drop, also animation related code.
- Added promotion functionality, property promotepiece cblAuto (Queen), cblAsk.
- Various smaller changes.

Windows only. Briefly tested component itself in Linux. It compiles, but doesn't work, because it uses thread resume/suspend. (I have no idea how to remove them)
Title: Re: Porting TChessBrd from Delphi
Post by: typo on July 28, 2013, 05:30:45 pm
Great job. Now this is my favorite chessboard.
Title: Re: Porting TChessBrd from Delphi
Post by: typo on July 30, 2013, 08:56:12 pm
Please put your name and license in some place of the code. If I use this code for a program, I would like to cite the author. Should I cite Timewarp? Should I assume the license is LGPL?
Title: Re: Porting TChessBrd from Delphi
Post by: jarto on July 30, 2013, 09:29:18 pm
Windows only. Briefly tested component itself in Linux. It compiles, but doesn't work, because it uses thread resume/suspend. (I have no idea how to remove them)
My curiosity peaked, so I had a look. It shouldn't be to difficult to let the TChessThread run continuously and to just use sleep or a TSimpleEvent inside TChessThread.Execute to wait. That would eliminate the need to suspend threads.

I tried to compile the demo program in Linux, but there the biggest problem are the pipes and the CreateProcess in Load_Engine. Can you tell me what's the idea behind using those?
Title: Re: Porting TChessBrd from Delphi
Post by: typo on July 30, 2013, 10:13:32 pm
AFAIK Houdini runs under Wine on Linux.
Title: Re: Porting TChessBrd from Delphi
Post by: BigChimp on July 31, 2013, 08:03:39 am
I tried to compile the demo program in Linux, but there the biggest problem are the pipes and the CreateProcess in Load_Engine. Can you tell me what's the idea behind using those?

Probably replace CreateProcess by TProcess so you can start the houdini engine (having this code in the Windows version may not be a bad idea - keeps it nice and crossplatform). The pipes are then used to communicate with the houdini engine (to pass the moves and receive the opponent's moves from the AI etc).
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on July 31, 2013, 08:42:14 am
Should I cite Timewarp? Should I assume the license is LGPL?

I don't care, I guess same as original.

I tried to compile the demo program in Linux, but there the biggest problem are the pipes and the CreateProcess in Load_Engine. Can you tell me what's the idea behind using those?

I mean I tested component chessbrd.pas. Afterwards I did not even try to make demo run in Linux.

If you like to test, take that and res-file and try demo from reply #3. It should easily compile in Linux, but not work.

Using pipes was first thing that worked for me.. Like mentioned above, maybe TProcess can be used, similar thread http://forum.lazarus.freepascal.org/index.php/topic,21631.0.html

AFAIK Houdini runs under Wine on Linux.

There are engines for Linux also. I tested Stockfish (in Windows). This engine requires whole position (all moves) to be sent on every move, that's ofcourse very easy to change.
Title: Re: Porting TChessBrd from Delphi
Post by: Timewarp on September 02, 2013, 02:29:23 pm
Just posting latest changes.

Demo1 uses the original engine
Demo2 uses&needs Houdini (or Stockfish)

Some of the changes, algebraic notation / basic load&save pgn. Thread suspend gone. Many bugs fixed (hopefully not created new)

Demo1 should run in Linux also, but there are bugs in Lazarus gtk2.

I'm planning to use this to watch&analyse live games. Some smaller / national tournaments, when games can't be followed in ICC/Playchess/chessbomb.com.. only on website.
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on June 23, 2018, 08:17:17 pm
I would like to add functionality to this application, e.g. highlighting the source and destination squares of the computer move. Also, instead of drag and drop i would like to do a click option.
Title: Re: Porting TChessBrd from Delphi
Post by: venus444 on August 04, 2018, 08:59:14 am
I can have your email address because there is a serious bug or upload of ambiguous moves.
Thank you
venus444@alice.it
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on August 05, 2018, 03:31:20 am
You may reach me at this forum. Can you help?
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on August 27, 2018, 01:24:58 am
TimeWarp work on this project. I would like to modify it with the help of TimeWarp. How to get hold of him?
Title: Re: Porting TChessBrd from Delphi
Post by: Thaddy on August 27, 2018, 09:09:36 am
I believe I already ported it two years ago.
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on August 27, 2018, 07:45:27 pm
I know it has been ported. I have been trying to modify it to do "click and place" instead of "drag and drop". My familiarity with the tchessbrd unit is not that good. Maybe you can direct me where to start.

Thanks,
VF
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on September 24, 2018, 09:47:29 pm
This project is a good place to start. I have been making modifications. Now I have come to this problem. Using FEN notation, I would like to have the engine make analysis based on a starting position indicated by the FEN notation. Can anyone direct me on how to do this?
Title: Re: Porting TChessBrd from Delphi
Post by: avra on September 25, 2018, 12:36:55 pm
Using FEN notation, I would like to have the engine make analysis based on a starting position indicated by the FEN notation. Can anyone direct me on how to do this?
You need to make a FEN parser. If you want to do it on your own, then one of the ways is to make a grammar and create parser based on that grammar. I have found one BNF grammar here (https://github.com/tlehman/fenparser), which you can adapt and use. Here is our wiki page (http://wiki.freepascal.org/Make_your_own_compiler,_interpreter,_parser,_or_expression_analyzer) if you want to go that path. If you don't then your best bet is to adapt other people's parser. I have found only one for Lazarus here (https://github.com/alex65536/Chess256/blob/cc41120a544c721688b6dc58e41cd17609eecdbe/Sources/ChessRules.pas) in Chess256 application. You can find many more FEN parsers for other programming languages on the net.
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on September 26, 2018, 03:45:54 am
Thanks for the reply. Actually, I have written a FEN parser and have tested it hhttp://analysis.cpuchess.com/ (http://analysis.cpuchess.com/)ere. What really needed to know is to how to input the FEN notation into TChessBrd so that the engine can be utilized to analyze the game.
Title: Re: Porting TChessBrd from Delphi
Post by: Ladywasky on October 20, 2018, 12:45:34 pm
Oh ! Nice port. I have tried to use it by the past. The inculded engine is very crappy and difficult to replace but the board is nice. I remember there was a few to change (thread access violations when moving the pieces.
I used the pieces of virtual chess II to have a better look for the board and pieces.
Anyway, thank you for the port.
Title: Re: Porting TChessBrd from Delphi
Post by: vferia on February 14, 2019, 11:59:29 pm
I have modified the app so I have a choice of engines. I run the new version 10 of stockfish and I am happy with it. I am still working on the following problems:
1. Based on FEN position, I would like the app to clear the board and place the pieces according to the FEN. How to do this in TChessbrd.
2. The next step is continuing play based on the FEN position.

Things I added to the app 1. Can communicate with electronic chessboard.
                                      2. Can email pgn file
                                      3. Can modify size of board
                                      4. Can modify color of squares
                                      5. Can select which engines to use
                                      6. Can select size of pieces.
                                      7. Can announce move made with voice.
                                      8. Can change voice gender.

Help is needed. I hope TimeWarp is listening.