Recent

Author Topic: Mater, mate searching program by Valentin Albillo  (Read 5146 times)

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Mater, mate searching program by Valentin Albillo
« on: February 25, 2020, 09:22:56 am »
Hello!

Some years ago, I discovered an interesting program by Valentin Albillo, a simple but efficient mate searching program, written for Turbo Pascal.

I started to study it, and made some little modifications (like turning the program into unit, removing the dependency to Dos unit).

Here you can find the original source code and its documentation (which were no longer available), and the new version.

https://gitlab.com/rchastain/mater

Problem of the day: White plays and mates in three moves:)

Regards.

Roland
« Last Edit: November 08, 2021, 04:41:15 pm by Roland57 »
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Mater, mate searching program by Valentin Albillo
« Reply #1 on: November 08, 2021, 04:58:42 pm »
Hello! A new version of the program is available.

A little but important error has been fixed (in pawn move generation).

Mater for Free Pascal
« Last Edit: November 09, 2021, 11:38:08 am by Roland57 »
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Mater, mate searching program by Valentin Albillo
« Reply #2 on: November 09, 2021, 12:51:43 pm »
The program solves 150 000 mate-in-two-moves problems in three seconds, which doesn't looks too bad.  :)

Code: Pascal  [Select][+][-]
  1. // timetest.pas
  2.  
  3. (*
  4.   Reads a large FEN file and tries to solve all the positions, without
  5.   printing the result, but only the number of positions solved and the
  6.   time elapsed.
  7. *)
  8.  
  9. uses
  10.   SysUtils, Classes, MaterCore;
  11.  
  12. const
  13.   CDefaultFile = '155078mi2.fen';
  14. {
  15.   El Arte del Mate en Dos
  16.   Eduardo Sadier
  17.   https://sites.google.com/site/edusadier/home
  18. }
  19.   CDefaultDepth = 2;
  20.  
  21. var
  22.   LLst: TStringList;
  23.   LIdx, LCnt: integer;
  24.   LTime: cardinal;
  25.   LFile: string;
  26.   LDepth: integer;
  27.  
  28. begin
  29.   LFile := CDefaultFile;
  30.   LDepth := CDefaultDepth;
  31.  
  32.   if (ParamCount > 0) and FileExists(ParamStr(1)) then LFile := ParamStr(1);
  33.   if (ParamCount > 1) then LDepth := StrToIntDef(ParamStr(2), CDefaultDepth);
  34.  
  35.   LLst := TStringList.Create;
  36.   LLst.LoadFromFile(LFile);
  37.  
  38.   LCnt := 0;
  39.   LTime := GetTickCount64;
  40.   for LIdx := 0 to Pred(LLst.Count) do
  41.     if Length(SolveMate(LLst[LIdx], LDepth, smAllMoves)) > 0 then
  42.       Inc(LCnt);
  43.  
  44.   LTime := GetTickCount64 - LTime;
  45.   WriteLn('Time elapsed ', FormatDateTime('hh:nn:ss:zzz', LTime / (1000 * SECSPERDAY)));
  46.   WriteLn('Found ', LCnt, '/', LLst.Count);
  47.  
  48.   LLst.Free;
  49. end.
  50.  

The positions in FEN format have been extracted from the PGN file available here, using the following little program.

Code: Pascal  [Select][+][-]
  1. // extractfen.pas
  2.  
  3. (*
  4.   Detects and prints all FEN strings found in standard input.
  5.   ./extractfen < "Mate en Dos.pgn" > 155078mi2.fen
  6. *)
  7.  
  8. uses
  9.   SysUtils, RegExpr;
  10.  
  11. const
  12. {
  13.   Regular expressions for the six fields of a FEN string.
  14.   https://kirill-kryukov.com/chess/doc/fen.html
  15. }
  16.   P = '[1-8BKNPQRbknpqr]+'; // Piece placement (for one rank)
  17.   A = '[wb]';               // Active color
  18.   C = '([KQkq]+|\-)';       // Castling availability
  19.   E = '([a-h][36]|\-)';     // En passant target square
  20.   H = '\d+';                // Halfmove clock
  21.   F = '[1-9]\d*';           // Fullmove number
  22.  
  23. var
  24.   LLine: string;
  25.   LExpr: TRegExpr;
  26.   LPattern: string;
  27.  
  28. begin
  29.   LPattern := Format('%s/%s/%s/%s/%s/%s/%s/%s', [P, P, P, P, P, P, P, P]);
  30.   LPattern := Format('%s %s %s %s %s %s', [LPattern, A, C, E, H, F]);
  31.   LExpr := TRegExpr.Create(LPattern);
  32.   while not Eof do
  33.   begin
  34.     ReadLn(LLine);
  35.     if (Length(LLine) > 0) and LExpr.Exec(LLine) then
  36.       WriteLn(LExpr.Match[0]);
  37.   end;
  38.   LExpr.Free;
  39. end.
  40.  

« Last Edit: November 11, 2021, 09:04:38 pm by Roland57 »
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Mater, mate searching program by Valentin Albillo
« Reply #3 on: November 11, 2021, 09:15:39 pm »
The program solves 150 000 mate-in-two-moves problems in three seconds, which doesn't looks too bad.  :)

No, absurd man. There was a horrible mistake in the test program. The program used to test always the same position.  :-[

Now the program solves the 150 000 positions in three... minutes.

By the way, I uploaded a simple GUI made with Lazarus. Please take a look at it and tell me what you think. It has been tested only under Linux. It shoud work also under Windows but maybe with something to retouch. Don't forget to compile Mater first.

« Last Edit: November 13, 2021, 08:05:02 am by Roland57 »
My projects are on Gitlab and on Codeberg.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Mater, mate searching program by Valentin Albillo
« Reply #4 on: November 12, 2021, 10:10:22 am »
I uploaded a simple GUI made with Lazarus.
I am much more familiar with your new Lazarus GUI look of chess figures, so I see it as an improvement. If you are open for suggestions, then it would be much nicer to be able to point and click to setup board problem start position - having only clipboard ASCII notation is not too friendly. I would also suggest change of current board font to something more readable (like ARIAL or similar).
« Last Edit: November 12, 2021, 10:14:37 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Mater, mate searching program by Valentin Albillo
« Reply #5 on: November 13, 2021, 08:02:10 am »
I am much more familiar with your new Lazarus GUI look of chess figures, so I see it as an improvement.

Thank you for your answer. By the way, the pictures at the beginning of the discussion were made with another program (this one).

If you are open for suggestions, then it would be much nicer to be able to point and click to setup board problem start position - having only clipboard ASCII notation is not too friendly.

Yes, it would be nice. But not so easy to do. And I am not sure that someone would really use it.  :)

I would also suggest change of current board font to something more readable (like ARIAL or similar).

There are other fonts available in images/coordinates. One can replace alagard with another font name in this line:

Code: Pascal  [Select][+][-]
  1. LCoordinates := TBGRABitmap.Create('gui/images/coordinates/alagard/coord.png');

[roland@localhost gui]$ find . -name "coord.png"
./images/coordinates/alagard/coord.png
./images/coordinates/modern-dos-8x16/coord.png
./images/coordinates/code/coord.png
./images/coordinates/free-pixel/coord.png
./images/coordinates/gothicpixels/coord.png
./images/coordinates/windows-command-prompt/coord.png
[roland@localhost gui]$


Yesterday night I remade the GUI from beginning. I hope it is a little better now.  :)

Screenshot

Regards.

Roland
« Last Edit: November 14, 2021, 05:59:13 pm by Roland57 »
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Mater, mate searching program by Valentin Albillo
« Reply #6 on: November 29, 2021, 05:12:54 pm »
The final (?) version of that project is available. Now the two search engines are called in separate threads (using two different buttons). I finished the translations (French, German) and tried to make a clean documentation. Thanks to wp and to other members for their help on translation system (and on German language).  :)

Mater r20211124
« Last Edit: December 02, 2021, 01:20:21 pm by Roland57 »
My projects are on Gitlab and on Codeberg.

 

TinyPortal © 2005-2018