Eschecs 1.2.1 (UCI chess GUI)

User projects written in or related to FreeBASIC.
FB_Numpty
Posts: 33
Joined: Jan 28, 2014 19:22

Re: Eschecs

Postby FB_Numpty » Mar 13, 2014 20:20

TESLACOIL wrote:Sometimes it is unable to checkmate the lone white king when it has a queen and rook


Roland Chastain wrote: Yes, that problem is well known by chess programmers, and isn't so easy to solve. I have heard of endgame tablebases, but I haven't found time to study it.



Actually, it shouldn't be too difficult and doesn't need tablebases - R or Q v K is possible to find via search and specifically adapted endgame piece square tables (PST). For example, for Numpty if it recognises R or Q v K it deploys the following PST for the King in the evaluation function:

Code: Select all


'*** Special PST for king in KvR/Q endgames
FOR X = 9 TO 2 STEP -1
    FOR Y = 1 TO 8
        READ K_r
        K_r_end_PST(X*10+Y) = K_r
    NEXT Y
NEXT X

DATA 50, 70, 100, 100, 100, 100, 70, 50
DATA 70, 40, 40, 40, 40, 40, 40, 70
DATA 100, 40, 20, 20, 20, 20, 40, 100
DATA 100, 40, 20, -20, -20, 20, 40, 100
DATA 100, 40, 20, -20, -20, 20, 40, 100
DATA 100, 40, 20, 20, 20, 20, 40, 100
DATA 70, 40, 40, 40, 40, 40, 40, 70
DATA 50, 70, 100, 100, 100, 100, 70, 50



Unlike the normal PST for King in the endgame, the values are designed to force the King towards the edge of the Board (ie bonus is higher if opponent king is on one of the outer squares) from here even quite a shallow search should find the mate.
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Mar 13, 2014 20:56

@FB_Numpty

Very interesting. Thank you for the tip.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Eschecs

Postby TESLACOIL » Mar 15, 2014 10:12

Brute Force

Its sad but true, that chess, in the final analysis is mostly about brute force. The complexities of a position cannot be tackled via a book of ' good rules and known principles' because there are a near infinite amount of exceptions to that 'best practice'.

Most high level games are won or lost when a player spots a position in which 'best practice' does not lead to 'best outcomes'

A powerful computer chess engine will often play a series of arcane moves which defy casual description. The wisdom of such moves only becomes apparent to human observers AFTER they have deeply examined the landscape...beyond a certain level of strength it gets hard for humans to judge if the computer has A) played a profoundly strong move or B) a profoundly screwy move due to the horizon effect or some weird nuance in evaluation.


Very strong computer chess programs play in a different way from human players. This means it can be quite difficult for a human coder to envisage the best way forward. Letting your chess engine play against many others and collecting statistics about freedoms of movement, swings in evaluation etc is one way forward.



The best way to improve your engine

Get the engine to spit out a list of legal moves and have a second program read that list and brute force as deep as it can given CPU and time constraints. Every ply you can brute force massively increases it playing strength even if the 'evaluation' is basic.

At a guess id would say that 80% of computing power should be set aside for brute force and 10% for basic evaluation.

The last 10% can be used for deeper evaluation, ie has the pendulum swung a large amount in the preceding couple of moves. If so then allow the brute force engine extra time.

Thus time management + simple brute force will be the next big leap.




Eg if a pawn is queened then double or quadruple the time allowed for that particular move.

Games are often one or lost on a handful of critical moves, a tiny blunder can have exponential consequences so it totally correct to apply exponential resources at key moments....the opening book saves you many seconds and minutes, you can invest that saved time in 'key' moments.

Just letting the computer stop at random every dozen moves and chew the cud for a minute or so will help your engine get out of a pickle or spot a win.

There are many ways to improve a basic engine, but brute force, while a boring approach will REALLY pack a punch and, far more importantly give a TRULY SOLID FOUNDATION to any 'fancy evaluation methods' you might wish to indulge in.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Eschecs

Postby TESLACOIL » Mar 15, 2014 10:59

Eschecs (white) vs Houdini 1.5a w32 (black), running on a quad core i5 , 5 min blitz game.

This is one of the strongest engines on the planet running on one of the more powerful desktop computers

Houdini had 3mins 11sec left on the clock, i was manually entering moves on both engines (two boards)

evaluation was level until Whites pawn to B4 changed the evaluation to 0.8 pawns in blacks favor. Whites queen was chased around while black went on a knight rampage. Houdini then crept forwards evaluation wise for a few moves and then started slinging piece exchanges in whites face. For a few moves it seemed as if the evaluation was slightly swinging back in Eschecs favor but this was Houdini merely 'tidying up'

The White bishop taking the pawn on D4 was an instant blunder that allowed Houdini to spot a forced checkmate in 22 moves, moments later Houdini saw a forced mate in 16, and in fact checkmated Eschecs within 6 moves rather than the 22 first indicated.


Code: Select all

Eschecs FreeBasic
03-15-2014
10:16:57

c2c4 book
g8f6 user
g2g3 book
g7g6 user
f1g2 book
f8g7 user
b1c3 book
d7d6 user
g1f3 book
e8g8 user
e1g1 book
e7e5 user
d2d3 book
f8e8 user
c1g5 engine
h7h6 user
g5f6 engine
d8f6 user
d1a4 engine
c7c6 user
e2e3 engine
f6e7 user
a2a3 engine
c8e6 user
h2h4 engine
b8d7 user
b2b4 engine
a7a5 user
b4a5 engine
d7c5 user
a4b4 engine
c5d3 user
b4a4 engine
d3b2 user
a4b3 engine
b2c4 user
b3b4 engine
c6c5 user
b4b5 engine
a8a5 user
b5b3 engine
c4e3 user
b3b6 engine
a5a6 user
b6a6 engine
b7a6 user
f2e3 engine
e5e4 user
c3e4 engine
g7a1 user
f1a1 engine
e6d5 user
f3d2 engine
d5e4 user
g2e4 engine
d6d5 user
e4d5 engine
e7e3 user
g1g2 engine
e3d2 user
g2g1 engine
e8e2 user
a1a2 engine
e2e1 user


Eschecs took hardly anytime at all deciding its moves, letting the engine chew the cud for 3 to 10 seconds per move in a Blitz game is perfectly acceptable. Increasing the brute force ply by 2,3 or 4 should be possible without leaving human players twiddling thier thumbs waiting.

While the outcome was a forgone conclusion i felt that Eschecs had become worthy of a true test against hardware and software which is a 'default standard' in the chess computing world. It was going up against a 10kilanode a second machine that is quite capable of beating the reigning human world champion.

Houdini does a great deal of basic brute force as a foundation but has also been highly tuned to seek deeper convoluted advantages should they appear on the search horizon. It is seldom conservative against weaker opponents and writhing worms are bait to the beast !...its named after the Famous Escape artiste but when the tide is in its favor it will tie its opponents limbs in knots long before they hit the floor !
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » May 16, 2014 10:18

Hello!

I made an animated chess set for the FreeBASIC contest.

I have to integrate it into my chess program.

Any suggestion on the code is welcome.
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » May 17, 2014 10:25

Hello! There is a new version of my program.

I haven't yet integrated animated pieces (see my previous message), but I made a lot of modifications, visible or invisible. I believe I have found why the engine froze when I increased the search depth: it seems it was an issue of memory. So I modified the data types, to avoid memory waste, and now the engine seems to work correctly with a higher search depth. But it still would need confirmation.

Image

Download Eschecs 0.8.9
BasicCoder2
Posts: 3298
Joined: Jan 01, 2009 7:03

Re: Eschecs

Postby BasicCoder2 » May 18, 2014 3:52

With your chessSet.bas program my thoughts were it allows clicking the same square twice and clicking outside the board area with funny results. I assume correct inputs are checked and generated by the chess engine so it isn't an issue? As your coding techniques are a little bit advanced for me I can't follow it to suggest any code improvements. When I read animated I at first thought your pieces actually walked and swung weapons :)

Your chess program seems to get better and better? It would be nice however to save and load games and have undo and redo move buttons.

Another nice feature would be for pieces taken being placed on the side of the board.

I wrote some code to generate your chess set pieces so it could be used on forums such as this where there is no means to store images with the text.

Code: Select all

screenres 400,400,32
dim as any ptr pieces(12)

for k as integer = 0 to 11
    pieces(k)=imagecreate(40,40,0)
next k

dim as any ptr chessBoard
chessBoard = imagecreate(400,400,0)

dim as string datum
for k as integer = 0 to 11
    for j as integer = 0 to 39
        read datum
        for i as integer = 0 to 39
            pset pieces(k),(i,j),rgb(244,244,0)
            if mid(datum,i+1,1)="." then
                pset pieces(k),(i,j),rgb(255,0,255)
            end if
            if mid(datum,i+1,1)="#" then
                pset pieces(k),(i,j),rgb(0,0,0)
            end if
            if mid(datum,i+1,1)=" " then
                pset pieces(k),(i,j),rgb(255,255,255)
            end if
        next i
    next j
next k


'draw chessboard
line chessBoard,(0,0)-(399,399),rgb(255,0,255),bf
line chessBoard,(40,40)-(363,363),rgb(255,255,255),bf
line chessBoard,(36,36)-(363,363),rgb(0,0,0),b
line chessBoard,(37,37)-(362,362),rgb(0,0,0),b
line chessBoard,(38,38)-(361,361),rgb(255,255,255),b
line chessBoard,(39,39)-(360,360),rgb(0,0,0),b
dim as integer t
for j as integer = 0 to 399-80
    for i as integer = 0 to 399-80
            if t=4 then
                pset chessBoard,(i+40,j+40),rgb(0,0,0)
            else
                pset chessBoard,(i+40,j+40),rgb(255,255,255)
            end if
            t = t + 1
            if t = 5 then t=0
    next i
    t = t + 1
    if t = 5 then t=0
next j

dim as integer flipFlag

flipFlag = 1
for j as integer = 0 to 7
    flipFlag = -flipFlag
    for i as integer = 0 to 7
        flipFlag = -flipFlag
        if flipFlag = 1 then
            line chessBoard,(i*40+40,j*40+40)-(i*40+79,j*40+79),rgb(255,255,255),bf
        end if
    next i
next j


put (0,0),chessBoard,pset
bsave "cBoard.bmp",0

sleep

for k as integer = 0 to 11
   imagedestroy(pieces(k))
next k           


data "........................................"
data "........................................"
data "........................................"
data "........................................"
data ".................######................."
data "................##    ##................"
data "...............##      ##..............."
data "...............#   ##   #..............."
data "...............#  ####  #..............."
data "...............#  ####  #..............."
data "...............#  ####  #..............."
data "..............###  ##  ###.............."
data ".............##    ##    ##............."
data ".............#    ####    #............."
data "............##  ########  ##............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............##  ########  ##............"
data ".............#    ####    #............."
data "............###    ##    ###............"
data "...........##     ####     ##..........."
data "..........##    ########    ##.........."
data ".........##   ############   ##........."
data ".........#   ##############   #........."
data "........##  ################  ##........"
data "........#   ################   #........"
data ".......##  ##################  ##......."
data ".......#   ##################   #......."
data ".......#  ####################  #......."
data ".......#  ####################  #......."
data ".......#  ####################  #......."
data ".......#                        #......."
data ".......#                        #......."
data ".......##########################......."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........#######.########.#######........"
data "........#     #.#      #.#     #........"
data "........#     ###      ###     #........"
data "........#  #       ##       #  #........"
data "........#  #       ##       #  #........"
data "........#  ##################  #........"
data "........#                      #........"
data "........#                      #........"
data "........##   ##############   ##........"
data ".........##                  ##........."
data "..........##                ##.........."
data "...........##  ##########  ##..........."
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "............#  ##########  #............"
data "...........##              ##..........."
data "..........##                ##.........."
data ".........##   ############   ##........."
data ".........#                    #........."
data ".........#                    #........."
data ".........#  ################  #........."
data "......####  ################  ####......"
data "......#                          #......"
data "......#                          #......"
data "......#  ######################  #......"
data "......#                          #......"
data "......#                          #......"
data "......############################......"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data ".........####....###...................."
data ".........#  ##..## ##..................."
data ".........#   ####   ##.................."
data ".........##    ##    #.................."
data "..........#       #  #####.............."
data "..........#  ##   ##     ###............"
data ".........##  #   ###       ###.........."
data ".........#     #####  ###    ##........."
data "........##  #  ############   ##........"
data "........#  #################   ##......."
data ".......##  #   ##############   #......."
data ".......#  #   ################  ##......"
data ".......#  #  #################   #......"
data "......##  # ##########  #######  ##....."
data "......#  #############  #######   #....."
data ".....##  ############  #########  ##...."
data ".....#  #############  #########   #...."
data "....##  ############   ##########  #...."
data "....#  ###########     ##########  ##..."
data "...##  #########    #  ###########  #..."
data "...#  #  #####    ##  ############  #..."
data "...#  #  ####   ####  ############  #..."
data "...#  ######  ###.#   ############  #..."
data "...#   #  #  ##..##  #############  ##.."
data "...##        #..##   ##############  #.."
data "....##      ##.##   ###############  #.."
data ".....####  ##.##   ################  #.."
data "........####..#   #################  #.."
data ".............##  ##################  #.."
data ".............#  ###################  #.."
data "............##  ###################  #.."
data "............#  ####################  #.."
data "............#                        #.."
data "............#                        #.."
data "............##########################.."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data ".................######................."
data "................##    ##................"
data "................#      #................"
data "................#  ##  #................"
data "................#  ##  #................"
data "................#      #................"
data "...............###    ###..............."
data "..............##        ##.............."
data ".............##   ####   ##............."
data "............##   ######   ##............"
data "...........##   ########   ##..........."
data "...........#   ####  ####   #..........."
data "..........##  #####  #####  ##.........."
data "..........#   ###      ###   #.........."
data "..........#  ####      ####  #.........."
data "..........#  ######  ######  #.........."
data "..........#  ######  ######  #.........."
data "..........##  ############  ##.........."
data "...........#  ############  #..........."
data "...........##              ##..........."
data "............##            ##............"
data ".............#  ########  #............."
data "............##  ########  ##............"
data "............#              #............"
data "...........##              ##..........."
data "...........#    ########    #..........."
data "...........###            ###..........."
data ".............###        ###............."
data "....###########   #  #   ###########...."
data "...##            ##  ##            ##..."
data "...#           ###    ###           #..."
data "...#   ##########      ##########   #..."
data "...##              ##              ##..."
data "....##           ######           ##...."
data ".....#############....#############....."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "..................#####................."
data "..........#####..##   ##..#####........."
data ".........##   ##.#     #.##   ##........"
data ".........#     #.#  #  #.#     #........"
data "...#####.#  #  #.#     #.#  #  #.#####.."
data "..##   ###     #.##   ##.#     ###   ##."
data "..#     ###   ##..#   #..##   ###     #."
data "..#  #  #.##  ##..#   #..##  ##.#  #  #."
data "..#     #..#   #..#   #..#   #..#     #."
data "..##   ##..#   #..#   #..#   #..##   ##."
data "...##   #..#   ####   ####   #..#   ##.."
data "....##  ##.#    ##  #  ##    #.##  ##..."
data ".....#   #.#    ##  #  ##    #.#   #...."
data ".....#   ###    ##  #  ##    ###   #...."
data ".....#    ##  #  #  #  #  #  ##    #...."
data ".....#    ##  #  #  #  #  #  ##    #...."
data ".....##    #  #  #  #  #  #  #    ##...."
data "......#    #  ##   ###   ##  #    #....."
data "......#  #    ##   # #   ##    #  #....."
data "......#  #   #             #   #  #....."
data "......#   #         #         #   #....."
data "......##      #############      ##....."
data ".......#   ###################   #......"
data ".......##  ##              ###  ##......"
data "........#                       #......."
data "........##    #############    ##......."
data ".........#  ##             ##  #........"
data ".........#    #############    #........"
data ".........#  ##             ##  #........"
data "........##                     ##......."
data "........#     #############     #......."
data "........#     #############     #......."
data "........##                     ##......."
data ".........#####             #####........"
data ".............###############............"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "..................####.................."
data "..................#  #.................."
data "................###  ###................"
data "................#      #................"
data "................#      #................"
data "................###  ###................"
data "..................#  #.................."
data ".................##  ##................."
data "................##    ##................"
data "...............##      ##..............."
data ".......#########   ##   #########......."
data ".....###      ##  ####  ##      ###....."
data "....##            ####            ##...."
data "....#   ######    ####    ######   #...."
data "...##  #########  ####  #########  ##..."
data "...#  ###########  ##  ###########  #..."
data "...#  ###########  ##  ###########  #..."
data "...#  ############    ############  #..."
data "...#  ############    ############  #..."
data "...#   ############  ############   #..."
data "...##  ############  ############  ##..."
data "....#   ###########  ###########   #...."
data "....##   ##########  ##########   ##...."
data ".....##   ###              ###   ##....."
data "......##                        ##......"
data ".......##     ############     ##......."
data "........#  ##################  #........"
data "........##  #              #  ##........"
data ".........#    ############    #........."
data "........##  ##            ##  ##........"
data ".......##                      ##......."
data ".......#       ##########       #......."
data ".......##      ##########      ##......."
data "........###                  ###........"
data "..........#####          #####.........."
data "..............############.............."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data ".................######................."
data "................##    ##................"
data "...............##      ##..............."
data "...............#        #..............."
data "...............#        #..............."
data "...............#        #..............."
data "...............#        #..............."
data "..............###      ###.............."
data ".............##          ##............."
data ".............#            #............."
data "............##            ##............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............##            ##............"
data ".............#            #............."
data "............###          ###............"
data "...........##              ##..........."
data "..........##                ##.........."
data ".........##                  ##........."
data ".........#                    #........."
data "........##                    ##........"
data "........#                      #........"
data ".......##                      ##......."
data ".......#                        #......."
data ".......#                        #......."
data ".......#                        #......."
data ".......#                        #......."
data ".......#                        #......."
data ".......#                        #......."
data ".......##########################......."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........#######.########.#######........"
data "........#     #.#      #.#     #........"
data "........#     ###      ###     #........"
data "........#                      #........"
data "........#                      #........"
data "........#                      #........"
data "........#                      #........"
data "........#  ##################  #........"
data "........##                    ##........"
data ".........##                  ##........."
data "..........##   ##########   ##.........."
data "...........##              ##..........."
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "............#              #............"
data "...........##              ##..........."
data "..........##   ##########   ##.........."
data ".........##                  ##........."
data ".........#                    #........."
data ".........#  ################  #........."
data ".........#                    #........."
data "......####                    ####......"
data "......#    ##################    #......"
data "......#                          #......"
data "......#                          #......"
data "......#                          #......"
data "......#                          #......"
data "......############################......"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data ".........####....###...................."
data ".........#  ##..## ##..................."
data ".........#   ####   ##.................."
data ".........##    ##    #.................."
data "..........#          #####.............."
data "..........#              ###............"
data ".........##   ##     ###   ###.........."
data ".........#   #          ##   ##........."
data "........##               ##   ##........"
data "........#                  #   ##......."
data ".......##   ###            ##   #......."
data ".......#   ###              ##  ##......"
data ".......#   ##                ##  #......"
data "......##   #          #      ##  ##....."
data "......#               #       ##  #....."
data ".....##              #        ##  ##...."
data ".....#               #         ##  #...."
data "....##                         ##  #...."
data "....#                          ##  ##..."
data "...##               #           ##  #..."
data "...#   #          ##            ##  #..."
data "...#  ##        ####            ##  #..."
data "...#  #       ###.#             ##  #..."
data "...#     #   ##..##             ##  ##.."
data "...##    #   #..##               ##  #.."
data "....##      ##.##                ##  #.."
data ".....####  ##.##                 ##  #.."
data "........####..#                  ##  #.."
data ".............##                  ##  #.."
data ".............#                   ##  #.."
data "............##                   ##  #.."
data "............#                    ##  #.."
data "............#                        #.."
data "............#                        #.."
data "............##########################.."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data ".................######................."
data "................##    ##................"
data "................#      #................"
data "................#      #................"
data "................#      #................"
data "................#      #................"
data "...............###    ###..............."
data "..............##        ##.............."
data ".............##          ##............."
data "............##            ##............"
data "...........##              ##..........."
data "...........#       ##       #..........."
data "..........##       ##       ##.........."
data "..........#      ######      #.........."
data "..........#      ######      #.........."
data "..........#        ##        #.........."
data "..........#        ##        #.........."
data "..........##                ##.........."
data "...........#                #..........."
data "...........##              ##..........."
data "............##  ########  ##............"
data ".............# #        # #............."
data "............##            ##............"
data "............#  ##########  #............"
data "...........## ##        ## ##..........."
data "...........#                #..........."
data "...........###            ###..........."
data ".............####      ####............."
data "....############        ############...."
data "...##                              ##..."
data "...#                                #..."
data "...##                              ##..."
data "....#             ####             #...."
data "....## ############..############ ##...."
data ".....###........................###....."
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "..................#####................."
data "..........#####..##   ##..#####........."
data ".........##   ##.#     #.##   ##........"
data ".........#     #.#     #.#     #........"
data "...#####.#     #.#     #.#     #.#####.."
data "..##   ###     #.##   ##.#     ###   ##."
data "..#     ###   ##..#   #..##   ###     #."
data "..#     #.##  #...#   #...#  ##.#     #."
data "..#     #..#  ##..#   #..##  #..#     #."
data "..##   ##..#   #..#   #..#   #..##   ##."
data "...##  ##..#   #.##   ##.#   #..##  ##.."
data "....##  #..#   ###     ###   #..#  ##..."
data ".....#  ##.#    ##     ##    #.##  #...."
data ".....#   #.#    ##     ##    #.#   #...."
data ".....#   ###    ##     ##    ###   #...."
data ".....#    ##     #     #     ##    #...."
data ".....##   ##     #     #     ##   ##...."
data "......#    #                 #    #....."
data "......#    #                 #    #....."
data "......#                           #....."
data "......#                           #....."
data "......##                         ##....."
data ".......#     ###############     #......"
data ".......##  ###             ###  ##......"
data "........#  #                 #  #......."
data "........##    #############    ##......."
data ".........#  ##             ##  #........"
data ".........#                     #........"
data ".........#    #############    #........"
data "........##  ##             ##  ##......."
data "........#  #                 #  #......."
data "........#                       #......."
data "........##                     ##......."
data ".........#####             #####........"
data ".............###############............"
data "........................................"
data "........................................"
data "........................................"
data "........................................"
data "..................####.................."
data "..................#  #.................."
data "................###  ###................"
data "................#      #................"
data "................#      #................"
data "................###  ###................"
data "..................#  #.................."
data ".................##  ##................."
data "................##    ##................"
data "...............##      ##..............."
data ".......#########   ##   #########......."
data ".....###      ##  #  #  ##      ###....."
data "....##            #  #            ##...."
data "....#   ######    #  #    ######   #...."
data "...##  ##    ###  #  #  ###    ##  ##..."
data "...#  ##       ##  ##  ##       ##  #..."
data "...#  #         #  ##  #         #  #..."
data "...#  #          #    #          #  #..."
data "...#  ##         #    #         ##  #..."
data "...#   #          #  #          #   #..."
data "...##  ##         #  #         ##  ##..."
data "....#   ##        #  #        ##   #...."
data "....##   ##       #  #       ##   ##...."
data ".....##   ## ######  ###### ##   ##....."
data "......##   ###            ###   ##......"
data ".......##                      ##......."
data "........#                      #........"
data "........##   ##############   ##........"
data ".........#  ##            ##  #........."
data "........##     ##########     ##........"
data ".......##   ####        ####   ##......."
data ".......#   ##              ##   #......."
data ".......##                      ##......."
data "........###                  ###........"
data "..........#####          #####.........."
data "..............############.............."
data "........................................"
data "........................................"
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » May 18, 2014 7:06

Hello John! Thank you for your interest in my project.

BasicCoder2 wrote:With your chessSet.bas program my thoughts were it allows clicking the same square twice and clicking outside the board area with funny results. I assume correct inputs are checked and generated by the chess engine so it isn't an issue?


Yes, it will be the responsibility of the calling program to call the functions with correct values. The program you tried is just like wood pieces. But I should have checked the click outside the board area! I will make the correction.

BasicCoder2 wrote:When I read animated I at first thought your pieces actually walked and swung weapons :)


As in Battle Chess ? It would be funny. I had a doubt about the meaning of the expression "animated pieces", but I didn't find a better one.

BasicCoder2 wrote:It would be nice however to save and load games and have undo and redo move buttons.

Another nice feature would be for pieces taken being placed on the side of the board.


OK, I put that in my to-do list. :)

BasicCoder2 wrote:I wrote some code to generate your chess set pieces so it could be used on forums such as this where there is no means to store images with the text.


Thank you for the bitmaps generation kit. It is useful indeed.

I made small modifications to your code.

Code: Select all

' GenerateBitmaps.bas

#define clBlack rgb(  0,   0,   0)
#define clWhite rgb(255, 255, 255)
#define clTrans rgb(255,   0, 255)

screenres 400, 400, 32
dim as any ptr pieces(11) ' 12 pieces

for k as integer = 0 to 11
  pieces(k) = imagecreate(40, 40, 0)
next k

dim as any ptr chessBoard
chessBoard = imagecreate(400, 400, 0)

dim as string datum
for k as integer = 0 to 11
  for j as integer = 0 to 39
    read datum
    for i as integer = 0 to 39
      select case mid(datum, i + 1, 1)
        case "."
          pset pieces(k), (i, j), clTrans
        case "#"
          pset pieces(k), (i, j), clWhite
        case " "
          pset pieces(k), (i, j), clBlack
      end select
    next i
  next j
next k

' draw chessboard

line chessBoard, ( 0,  0)-(399, 399), clTrans, bf
line chessBoard, (40, 40)-(359, 359), clWhite, bf
line chessBoard, (36, 36)-(363, 363), clBlack, b
line chessBoard, (37, 37)-(362, 362), clBlack, b
line chessBoard, (38, 38)-(361, 361), clWhite, b
line chessBoard, (39, 39)-(360, 360), clBlack, b

dim as integer t = 0
for j as integer = 40 to 359
  for i as integer = 40 to 359
    if (t = 4) andalso ((i \ 40 + j \ 40) mod 2 = 1) then
      pset chessBoard,(i, j), clBlack
    end if
    t = (t + 1) mod 5
  next i
  t = (t + 1) mod 5
next j

dim filename as string
read filename
bsave filename & ".bmp", chessBoard

for k as integer = 0 to 11
  read filename
  bsave filename & ".bmp", pieces(k)
next k

imagedestroy(chessBoard)
for k as integer = 0 to 11
  imagedestroy(pieces(k))
next k   

sleep

' ------------------------------------------------------------------------------
data ...
' ------------------------------------------------------------------------------

data "board"
data "wp", "wr", "wn", "wb", "wq", "wk"
data "bp", "br", "bn", "bb", "bq", "bk"
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Aug 10, 2014 9:42

Hello!

I failed to integrate my new chess pieces set in the current version of ESCHECS. I believe it will be easier to rewrite all.

For today I propose to you a little exercise: it's a function that converts an FEN string to an HTML document. If you have suggestions to improve the code I would be glad to hear them.

Code: Select all

' Converts the first field of an FEN string to an HTML document.
' The default font is Chess Alfonso-X by Armando H. Marroquin.
' If you want to use another chess font by the same author, you just have to
' change the font name, otherwise you must also change the character set,
' because each author uses a different one.
' The FEN string is assumed to be valid!

' Chess font Alfonso-X
' http://www.enpassant.dk/chess/fonteng.htm

' Forsyth-Edwards notation
' http://kirill-kryukov.com/chess/doc/fen.html

#define EOL chr(13, 10)

function HtmlDoc( _
  byval aPlacement as string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", _
  byval aCharSet as string = "!""#$%/() +pPoOnNmMbBvVrRtTqQwWkKlL", _
  byval aTitle as string = "", _
  byval aFont as string = "chess alfonso-x", _
  byval aSize as string = "40px", _
  byval aColor as string = "black", _
  byval aBkColor as string = "white" _
) as string
 
  dim as string head, body, foot
  dim as integer i, j, x, y
 
  head = _
  "<!DOCTYPE html>" & EOL & _
  "<html>" & EOL & _
  "<head>" & EOL & _
  "<title>" & aTitle & "</title>" & EOL & _
  "<style type=""text/css"">" & EOL & _
  "p {" & EOL & _
  "font-family: " & aFont & ";" & EOL & _
  "font-size: " & aSize & ";" & EOL & _
  "color: " & aColor & ";" & EOL & _
  "background-color: " & aBkColor & ";" & EOL & _
  "}" & EOL & _
  "</style>" & EOL & _
  "</head>" & EOL & _
  "<body>" & EOL
 
  body = ""
  i = 0
  x = 1
  y = 8
  do while (len(body) < 64) and (i <= len(aPlacement) - 1)
    if aPlacement[i] = asc("/") then
      x = 1
      y -= 1
      i += 1
    else
      if (aPlacement[i] >= asc("1")) and (aPlacement[i] <= asc("8")) then
        do while aPlacement[i] > asc("0")
          body &= iif((x + y) mod 2 = 1, chr(aCharSet[8]), chr(aCharSet[9]))
          x += 1
          aPlacement[i] -= 1
        loop
        i += 1
      else
        if instr("bknpqrBKNPQR", chr(aPlacement[i])) > 0 then
          select case lcase(chr(aPlacement[i]))
            case "p"
              j = 10
            case "n"
              j = 14
            case "b"
              j = 18
            case "r"
              j = 22
            case "q"
              j = 26
            case "k"
              j = 30
          end select
          ' dark square
          if (x + y) mod 2 = 0 then j += 1
          ' black piece
          if chr(aPlacement[i]) = lcase(chr(aPlacement[i])) then j += 2
          body &= chr(aCharSet[j])
          x += 1
          i += 1
        else
          exit do
        end if
      end if
    end if
  loop 
 
  body = _
  "<p>" & EOL & _
  chr(aCharSet[0]) & string(8, aCharSet[1])  & chr(aCharSet[2]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 0 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 1 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 2 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 3 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 4 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 5 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 6 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 7 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[5]) & string(8, aCharSet[6])  & chr(aCharSet[7]) & "<br>" & EOL & _
  "</p>" & EOL
 
  foot = _
  "</body>" & EOL & _
  "</html>"
 
  function = head & body & foot
 
end function

open "1.htm" for output as #1
print #1, HtmlDoc()
close #1
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Eschecs

Postby TESLACOIL » Aug 11, 2014 4:32

Chess programmers often set up their program to compete in automated tournaments vs other chess programs as a way to find bugs and generally improve the performance.

It is a bit of a hassle getting the protocols right the upside once done there are dozens if not hundreds of compatible chess engines to test yours against.

Even the best chess programs still need about 20mins per game in order to play fairly tight chess. Some positions are arcane and there is no general set of chess guidelines that apply to these positions because of the unique complexity embedded in that unique position. Here brute force is required to look far ahead in order to try and find a more obvious (good/bad) decidable path. The programmer then has the option to play safe, and via internal code biases, encourage their chess engine to play towards a position which is 'more easily decidable' using broader chess principles.

Brute force is so revealing, especially in weird positions, that it is the default method for improvement. The faster the machine the more true this becomes. Humans being a bit slow and unable to compute deeply or accurately are forced to play chess using general principles. The fact that a 'dumb but fast' brute force chess engine can beat most humans most of the time is a testament to this over arching theme.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Eschecs

Postby TESLACOIL » Aug 11, 2014 4:36

Abundant information about computer chess tournaments
http://chessprogramming.wikispaces.com/Tournaments
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Eschecs

Postby TESLACOIL » Aug 11, 2014 9:05

Even Grandmasters with computers can get it wrong :-p Classic example of where Principle says yes but Brute force says no

Lecture with GM-Elect Irina Krush
https://www.youtube.com/watch?v=tGqaixsLGt8

At 8 minutes
she correctly highlights a good principle, knight to F5 blows blacks pawn structure after the white bishops exchanges with the black knight on F5. However due to the uniqueness of the position it is actually a draw !!! even though white's king looks as though it can swing left then right again to sweep up victory.

So the GM had obviously found what she thought was a good example to demonstrate for her lecture, her deep instinct AND the initial computer evaluation both said win/big advantage for white but in reality its a draw. Both were wrong. It took almost an hour for me to figure this out. (with the aid of a computer)

The take away point here is that tweaking a chess engines code is fruitless without extensive brute force testing, 100+ games. Thus the value of automatic tournaments and some detailed method of logging 'how & why' your engine lost or won is also critical to advancement.

* If anyone can find a win with white let me (and Irina Krush) know, lol



To write a good chess program there are three essential skill sets

The ability to play chess at a certain level, the ability to code at a certain level and perhaps more importantly than this ' a deep experience' with chess engines. For this reason 'chess anything' will remain a non trivial problem for us humans even with uber fast computers to aid us.
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Aug 19, 2014 18:50

Hello !

I made some modifications to the engine of Eschecs. Now it's a DLL, with just one function exported:

Code: Select all

declare function EngineMove alias "EngineMove" ( _
  byval positionData as string = "", _
  byval logName as string = "" _
) as string


From now on, the engine and the GUI can be developed separately. The engine can even be used separately, by anyone who would want to use it. So I believe it deserves an independant release.

To use it, you just have to load the library and call the EngineMove function, with a FEN record as first parameter, and the name of the log file if you want a log file. It returns a string like "e2e4".

Code: Select all

extern "C" lib "chessengine"
  declare function EngineMove stdcall alias "EngineMove" ( _
    byval positionData as string = "", _
    byval logName as string = "" _
  ) as string
end extern

dim as string FENSample(1 to ...) = { _
  "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", _
  "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1", _
  "rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2", _
  "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2", _
  "4k3/8/8/8/8/8/4P3/4K3 w - - 5 39", _
  "7K/6q1/7b/8/8/8/8/6k1 w - - 3 41", _
  "3b4/7r/K7/8/k7/8/8/8 w - - 3 26" _
}

dim move as string = EngineMove(FENSample(1), "log.txt")


Download chess engine
Last edited by Roland Chastain on Aug 26, 2014 9:48, edited 1 time in total.
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Aug 26, 2014 9:47

Hello!

I reworked my graphical chessboard, in order to use it in the next release of Eschecs. Here it is, with a test program:

Download graphical chessboard

There is no mouse control, because it is assumed to be the job of the main program.

So now there are three programs that can be compiled and even used separately: the engine, the judge and the graphical chessboard.
Roland Chastain
Posts: 845
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Sep 13, 2014 17:45

Hello!

Here is Eschecs 0.9.0. Not really new features, but important modifications. The engine is now a DLL. The pieces glide over the board. The promotion dialog which was ugly (I had made it myself) has been replaced by radiobuttons.

Eschecs
Last edited by Roland Chastain on Sep 14, 2014 14:51, edited 2 times in total.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests