Eschecs

User projects written in or related to FreeBASIC.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Nov 10, 2013 16:23

Thank you for your answers.

I made some modifications and updated files.

Now you can flip the board (press "f"). You can see the list of moves in the file moves.txt.

Roland Chastain wrote:3° to understand why the engine doesn't see an obvious checkmate move (see engine\test7.bas).


I have found and corrected an error. The engine doesn't play the same move sequence : the problem seems to be solved.

I increased the search depth. The engine is a little longer to play, and seems to play better (see engine\test9.bas).

I haven't much time to play chess, because I spend too much time on my program. It's hard to make both the engine and the graphical interface. Look at the best programs that you can find on the web : you will never see a same person making a good engine and a good interface. As we say in France, "on ne peut pas être à la fois au four et au moulin".
BasicCoder2
Posts: 2813
Joined: Jan 01, 2009 7:03

Re: Eschecs

Postby BasicCoder2 » Nov 10, 2013 18:27

Roland Chastain wrote:I haven't much time to play chess, because I spend too much time on my program. It's hard to make both the engine and the graphical interface. Look at the best programs that you can find on the web : you will never see a same person making a good engine and a good interface. As we say in France, "on ne peut pas être à la fois au four et au moulin".

homme à tout faire maître de rien

No I can't write French it is a google translation so I don't know how well it did.

Compared with Titan your program's moves are instant.

You say you increased the search depth but I think for most programs it is variable, probably deeper in the end game or when following a promising sequence of good moves.
Last edited by BasicCoder2 on Nov 12, 2013 7:08, edited 1 time in total.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Nov 10, 2013 22:23

Thank you, John, for your suggestions, and for the game Titan vs. Eschecs (I keep a copy of it).

I believe I will let that version as it is, and take time to play games, in order to see if there aren't hidden bugs.

Now Eschecs has its own icon ! Files updated.
VANYA
Posts: 1245
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Eschecs

Postby VANYA » Nov 11, 2013 3:28

Hi Roland!

It would be nice to be able to increase the board.

I'm also playing the game at the end of the game did not get the progress of the engine (waited 2 minutes and turned off):

e2e4
e7e6
d2d4
d7d5
e4d5
e6d5
g1f3
g8f6
c1g5
f8b4
c2c3
b4d6
b1d2
c8f5
f3e5
b8c6
d2f3
h7h6
g5h4
g7g5
h4g3
d6e5
f3e5
c6e5
g3e5
d8e7
f1e2
h8g8
e1g1
f6h7
f1e1
f7f6
e5g3
f5e4
f2f3
f6f5
f3e4
f5e4
e2h5
e8d8
d1g4
a7a6
e1f1
e7d7
f1f7
d7g4
h5g4
g8h8
a1f1
e4e3
f7h7
h8h7
f1f8
d8e7
f8a8
c7c6
a8b8
e7f6
b8e8
h6h5
g4e2
a6a5
e8e3
a5a4
g3e5
f6f7
e3f3
f7g8
f3f5
g5g4
f5g5
g8f8
e2d3
h7f7
g5f5
f7f5
d3f5
f8f7
g1f2
f7f8
f2g3
a4a3
b2b3
b7b6
g3h4
c6c5
h4h5
c5c4
b3b4
b6b5
h5g4
f8e7
h2h4
e7e8
h4h5
e8e7
h5h6
e7e8
h6h7
e8e7
h7h8
BasicCoder2
Posts: 2813
Joined: Jan 01, 2009 7:03

Re: Eschecs

Postby BasicCoder2 » Nov 11, 2013 5:28

I don't play chess myself so would be considered a beginner but gave Eschecs a go anyway only to find it seemed to freeze up?
This is the actual game. Just tap the key to see it played.

Code: Select all

#include "fbgfx.bi"
using fb
'some useful defines
Const Pi = 4 * Atn(1)
Dim Shared As Double TwoPi = 8 * Atn(1)
Dim Shared As Double RtoD = 180 / Pi   ' radians * RtoD = degrees
Dim Shared As Double DtoR = Pi / 180   ' degrees * DtoR = radians

screenres 640,480,32

'+++++++++++++++++++++  INSERT NEW CODE ++++++++++++++++++



Sub drawLine(x1 as integer,y1 as integer,x2 as integer, y2 as integer, c as uinteger)

    Dim As Integer ax, ay, d, dx, dy, x, y
 
    If x1 = x2 And y1 = y2 Then Exit Sub
 
    If x1 = x2 Then
        x = x1
        if y2>y1 then
            For y as integer  = y1 To y2
                circle (x,y),2,c,,,,f
            Next y
        else
            for y as integer = y2 to y1
                circle (x,y),2,c,,,,f
            next y
        end if
     
    Elseif y1 = y2 Then
        y = y1
        if x2>x1 then
            For x as integer = x1 To x2
                circle (x,y),2,c,,,,f
            next x
        else
            for x as integer = x2 to x1
                circle (x,y),2,c,,,,f
            next x
        end if

    Else
        dx = x2 - x1
        dy = y2 - y1
        ax = 1
        ay = 1
   
        If dx < 0 Then
            dx = -dx
            ax = -1
        End If
   
        If dy < 0 Then
            dy = -dy
            ay = -1
        End If
   
        x = x1
        y = y1
   
        dim as integer ii
   
        If dx >= dy Then
            ii = dx + 1
            dy Shl= 1
            d = dy - dx
            dx Shl= 1
     
            While ii > 0
                ii -= 1
                circle (x,y),2,c,,,,f
       
                If d >= 0 Then
                    y += ay
                    d -= dx
                 End If
       
                 d += dy
                 x += ax
              Wend
          Else
              ii = dy + 1
              dx Shl= 1
              d = dx - dy
              dy Shl= 1
              While ii > 0
                  ii -= 1
                  circle (x,y),2,c,,,,f
       
                  If d >= 0 Then
                      x += ax
                      d -= dy
                  End If
       
                  d += dx
                  y += ay
              Wend
          End If
    End If
End Sub

sub drawArrow(x1 as double,y1 as double,x2 as double,y2 as double,c as uinteger)
   
        dim as double angle,xx,yy
        drawLine(x1,y1,x2,y2,c)

        angle = atan2(y2-y1,x2-x1)
        angle = angle + 45*DtoR
        xx = cos(angle)*20+x1
        yy = sin(angle)*20+y1
        drawLine(x1,y1,xx,yy,c)
        angle = atan2(y2-y1,x2-x1)
        angle = angle - 45*DtoR
        xx = cos(angle)*20+x1
        yy = sin(angle)*20+y1
        drawLine(x1,y1,xx,yy,c)

end sub

'++++++++++++++++++++++++++++++++++++++++++++++

type chessMove
    as integer x1  'FROM coordinates
    as integer y1
    as integer x2  'TO coordinates
    as integer y2
    as integer t1  'piece type moved
    as integer t2  'any piece type taken
end type
dim shared as chessMove cm   'show last move

dim shared as integer board(8,8)


const WP =  1
const BP = -1
const WR =  2
const BR = -2
const WN =  3
const BN = -3
const WB =  4
const BB = -4
const WQ =  5
const BQ = -5
const WK =  6
const BK = -6

'initialize board
for j as integer = 0 to 7
    for i as integer = 0 to 7
        read board(i,j)
    next i
next j

data WR,WN,WB,WQ,WK,WB,WN,WR
data WP,WP,WP,WP,WP,WP,WP,WP
data  0, 0, 0, 0, 0, 0, 0, 0
data  0, 0, 0, 0, 0, 0, 0, 0
data  0, 0, 0, 0, 0, 0, 0, 0
data  0, 0, 0, 0, 0, 0, 0, 0
data BP,BP,BP,BP,BP,BP,BP,BP
data BR,BN,BB,BQ,BK,BB,BN,BR

'images of pieces
dim shared as FB.Image ptr cImage(13)  '
for i as integer = 0 to 12
    cImage(i) = imagecreate(40,40,0)
next i

'create sprites
dim as string datum
for k as integer = 1 to 12
    for j as integer = 0 to 39
        read datum
        for i as integer = 0 to 39
            if mid(datum,i+1,1)=" " then
                pset cImage(k),(i,j),rgb(255,0,255)
            end if
            if mid(datum,i+1,1)="." then
                pset cImage(k),(i,j),rgb(255,255,255)
            end if
            if mid(datum,i+1,1)="#" then
                pset cImage(k),(i,j),rgb(0,49,83)
            end if
        next i
    next j
next k

'convert string chess moves to numbers
function stringToChessMove(move as string) as chessMove
    move = UCASE(move)
    cm.x1 = asc(mid(move,1,1))-65
    cm.y1 = val(mid(move,2,1))-1
    cm.x2 = asc(mid(move,3,1))-65
    cm.y2 = val(mid(move,4,1))-1
    return cm
end function

'convert chess move numbers to string format
function chessMoveToString(cm as chessMove) as string
    return chr(cm.x1+65)+str(cm.y1+1)+chr(cm.x2+65)+str(cm.y2+1)
end function


'update screen display
sub update()
    screenlock()
    color rgb(255,255,255),rgb(100,255,100)
    cls
   
    dim as integer shade
    shade = 1
   
    for y as integer = 0 to 7
        shade = -shade
        for x as integer = 0 to 7
            if shade = -1 then
                line (x*40,y*40)-(x*40+40,y*40+40),rgb(255,255,255),bf
            else
                line (x*40,y*40)-(x*40+40,y*40+40),rgb(50,160,200),bf
            end if
            shade = -shade
        next x
    next y
   
    dim as integer v
    for j as integer = 0 to 7
        for i as integer = 0 to 7
            if board(i,j)<> 0 then
                v = board(i,j)  'get image number
                if v<0 then v = abs(v)+6
                put (i*40,(7-j)*40),cImage(v),trans
            end if
        next i
    next j
   
    screenunlock()
end sub


dim as string move

dim as integer moveCount
update()
do
   
    read move
    moveCount = moveCount + 1
    if move<>"EXIT" then
    cm = stringToChessMove(move)
    update()
    drawArrow(cm.x2*40+18,(7-cm.y2)*40+18,cm.x1*40+18,(7-cm.y1)*40+18,rgb(255,255,0)) 'thick arrow
   
    sleep  'view move to be made
    board(cm.x2,cm.y2) = board(cm.x1,cm.y1)
    board(cm.x1,cm.y1) = 0
    end if
    update()
    'show move made
    line (cm.x1*40+1,(7-cm.y1)*40+1)-(cm.x1*40+38,(7-cm.y1)*40+38),rgb(0,255,0),b
    line (cm.x2*40+1,(7-cm.y2)*40+1)-(cm.x2*40+38,(7-cm.y2)*40+38),rgb(255,0,0),b
    line (cm.x1*40+2,(7-cm.y1)*40+2)-(cm.x1*40+37,(7-cm.y1)*40+37),rgb(0,255,0),b
    line (cm.x2*40+2,(7-cm.y2)*40+2)-(cm.x2*40+37,(7-cm.y2)*40+37),rgb(255,0,0),b

    locate 50,1
    print "moveCount";moveCount
    sleep  'view moved just made
loop until move = "EXIT"
update()
sleep
'deallocate

for i as integer = 0 to 12
    imagedestroy(cImage(i))
next i


end

spriteData:
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                  ####                  "
DATA "                 ######                 "
DATA "                ###..###                "
DATA "                ##....##                "
DATA "                ##....##                "
DATA "                ##....##                "
DATA "                 ######                 "
DATA "               ##########               "
DATA "              ####....####              "
DATA "              ##........##              "
DATA "             ##..........##             "
DATA "             ##..........##             "
DATA "             ##..........##             "
DATA "             ##..........##             "
DATA "              ##........##              "
DATA "              ###......###              "
DATA "               ####..####               "
DATA "             ##############             "
DATA "            ####........####            "
DATA "           ###............###           "
DATA "          ###..............###          "
DATA "          ##................##          "
DATA "         ###................###         "
DATA "         ##..................##         "
DATA "        ###..................###        "
DATA "        ##....................##        "
DATA "        ##....................##        "
DATA "        ##....................##        "
DATA "        ########################        "
DATA "        ########################        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "          #####   ######   #####        "
DATA "          #####   ######   #####        "
DATA "          ##.#######..#######.##        "
DATA "          ##.#######..#######.##        "
DATA "          ##..................##        "
DATA "          ######################        "
DATA "          ######################        "
DATA "           ###..............###         "
DATA "            ##################          "
DATA "             ################           "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##..........##            "
DATA "              ##############            "
DATA "             ################           "
DATA "            ###............###          "
DATA "           ####################         "
DATA "           ####################         "
DATA "           ##................##         "
DATA "           ##................##         "
DATA "        ##########################      "
DATA "        ##########################      "
DATA "        ##......................##      "
DATA "        ##########################      "
DATA "        ##########################      "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "         ##      #                      "
DATA "         ###    ###                     "
DATA "          ####  ####                    "
DATA "          #######.##                    "
DATA "          ##..###..#####                "
DATA "          ##.###...#######              "
DATA "         #####.....##...####            "
DATA "         ##.##............###           "
DATA "        ##.................###          "
DATA "        ##.###..............###         "
DATA "       ##.###................##         "
DATA "       ##.##.................###        "
DATA "       ##.#..........##.......##        "
DATA "      ##.............##.......###       "
DATA "      ##............##.........##       "
DATA "     ##.............##.........###      "
DATA "     ##............###..........##      "
DATA "    ##...........#####..........##      "
DATA "    ##.........#### ##...........##     "
DATA "   ##.##.....####  ##............##     "
DATA "   ##.##....###    ##............##     "
DATA "   ##......##     ###............##     "
DATA "   ###.##.##      ##.............##     "
DATA "    ########     ###..............##    "
DATA "     ######     ###...............##    "
DATA "        ##     ###................##    "
DATA "              ###.................##    "
DATA "              ##..................##    "
DATA "             ##...................##    "
DATA "             ##...................##    "
DATA "            ##....................##    "
DATA "            ########################    "
DATA "            ########################    "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                  ####                  "
DATA "                 ######                 "
DATA "                 ##..##                 "
DATA "                 ##..##                 "
DATA "                 ######                 "
DATA "                  ####                  "
DATA "                ########                "
DATA "               ###....###               "
DATA "              ###......###              "
DATA "             ###........###             "
DATA "            ###....##....###            "
DATA "            ##.....##.....##            "
DATA "           ###...######...###           "
DATA "           ##....######....##           "
DATA "           ##......##......##           "
DATA "           ##......##......##           "
DATA "            ##............##            "
DATA "            ##............##            "
DATA "             ##############             "
DATA "              ############              "
DATA "              ##........##              "
DATA "              ##........##              "
DATA "             ##############             "
DATA "             ##############             "
DATA "            ####........####            "
DATA "              ############              "
DATA "                ########                "
DATA "               ###.##.###               "
DATA "     ############..##..############     "
DATA "    ###########...####...###########    "
DATA "    ###..........######..........###    "
DATA "     ##############  ##############     "
DATA "      ###########      ###########      "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                   ###                  "
DATA "           ###    #####    ###          "
DATA "          #####   ##.##   #####         "
DATA "          ##.##   #####   ##.##         "
DATA "    ###   #####    ###    #####   ###   "
DATA "   #####   ###     ###     ###   #####  "
DATA "   ##.##    ##     ###     ##    ##.##  "
DATA "   #####    ###    ###    ###    #####  "
DATA "    ###     ###    ###    ###     ###   "
DATA "     ###    ###    ###    ###    ###    "
DATA "      ##    ####  ##.##  ####    ##     "
DATA "      ###   ####  ##.##  ####   ###     "
DATA "      ###   ####  ##.##  ####   ###     "
DATA "      ####  ##.## ##.## ##.##  ####     "
DATA "      ####  ##.## ##.## ##.##  ####     "
DATA "       #### ##.## ##.## ##.## ####      "
DATA "       #### ##..###...###..## ####      "
DATA "       ##.####..###.#.###..####.##      "
DATA "       ##.###.#############.###.##      "
DATA "       ###.#########.#########.###      "
DATA "        ######.............######       "
DATA "        ###...................###       "
DATA "         ##################...##        "
DATA "         #######################        "
DATA "          ####.............####         "
DATA "          ##..#############..##         "
DATA "          ####.............####         "
DATA "          ##..#############..##         "
DATA "          #####################         "
DATA "         #####.............#####        "
DATA "         #####.............#####        "
DATA "          #####################         "
DATA "              #############             "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                   ##                   "
DATA "                   ##                   "
DATA "                 ######                 "
DATA "                 ######                 "
DATA "                   ##                   "
DATA "                   ##                   "
DATA "                   ##                   "
DATA "                  ####                  "
DATA "                 ######                 "
DATA "                ###..###                "
DATA "        ######  ##....##  ######        "
DATA "      ############....############      "
DATA "     ###......####....####......###     "
DATA "     ##.........##....##.........##     "
DATA "    ##...........##..##...........##    "
DATA "    ##...........##..##...........##    "
DATA "    ##............####............##    "
DATA "    ##............####............##    "
DATA "    ###............##............###    "
DATA "     ##............##............##     "
DATA "     ###...........##...........###     "
DATA "      ###..........##..........###      "
DATA "       ###...##############...###       "
DATA "        ########################        "
DATA "         #####............#####         "
DATA "         ##..................##         "
DATA "          ##.##############.##          "
DATA "          ####............####          "
DATA "          ##..############..##          "
DATA "         ######################         "
DATA "        ######............######        "
DATA "         #####............#####         "
DATA "           ##################           "
DATA "               ##########               "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                  ####                  "
DATA "                 ######                 "
DATA "                ########                "
DATA "                ########                "
DATA "                ########                "
DATA "                ########                "
DATA "                 ######                 "
DATA "               ##########               "
DATA "              ############              "
DATA "              ############              "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "              ############              "
DATA "              ############              "
DATA "               ##########               "
DATA "             ##############             "
DATA "            ################            "
DATA "           ##################           "
DATA "          ####################          "
DATA "          ####################          "
DATA "         ######################         "
DATA "         ######################         "
DATA "        ########################        "
DATA "        ########################        "
DATA "        ########################        "
DATA "        ########################        "
DATA "        ########################        "
DATA "        ########################        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "         #####   ######   #####         "
DATA "         #####   ######   #####         "
DATA "         ######################         "
DATA "         ######################         "
DATA "         ######################         "
DATA "         ######################         "
DATA "         ##..................##         "
DATA "          ####################          "
DATA "           ##################           "
DATA "            ###..........###            "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "             ##############             "
DATA "            ###..........###            "
DATA "           ##################           "
DATA "          ####################          "
DATA "          ####################          "
DATA "          ####################          "
DATA "          ####################          "
DATA "       ####..................####       "
DATA "       ##########################       "
DATA "       ##########################       "
DATA "       ##########################       "
DATA "       ##########################       "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "          ##      #                     "
DATA "          ###    ###                    "
DATA "           ####  ####                   "
DATA "           ##########                   "
DATA "           ##############               "
DATA "           ###..#####...###             "
DATA "          ###.##########..###           "
DATA "          ###############..###          "
DATA "         ##################.###         "
DATA "         ###...############..###        "
DATA "        ###...##############..##        "
DATA "        ###..################..##       "
DATA "        ###.##########.######..##       "
DATA "       ###############.#######..##      "
DATA "       ##############.########..##      "
DATA "      ###############.#########..##     "
DATA "      #########################..##     "
DATA "     ##########################..##     "
DATA "     ############### ###########..##    "
DATA "    ###.##########  ############..##    "
DATA "    ##..########    ############..##    "
DATA "    ##.#######     #############..##    "
DATA "    #####.###      #############..##    "
DATA "     ####.###     ###############..##   "
DATA "      ######     ################..##   "
DATA "         ##     #################..##   "
DATA "               ##################..##   "
DATA "               ##################..##   "
DATA "              ###################..##   "
DATA "              ###################..##   "
DATA "             ####################..##   "
DATA "             ########################   "
DATA "             ########################   "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                  ####                  "
DATA "                 ######                 "
DATA "                 ######                 "
DATA "                 ######                 "
DATA "                 ######                 "
DATA "                  ####                  "
DATA "                ########                "
DATA "               ##########               "
DATA "              ############              "
DATA "             ##############             "
DATA "            #######..#######            "
DATA "            #######..#######            "
DATA "           ######......######           "
DATA "           ######......######           "
DATA "           ########..########           "
DATA "           ########..########           "
DATA "            ################            "
DATA "            ################            "
DATA "             ##############             "
DATA "              ##........##              "
DATA "              #.########.#              "
DATA "              ############              "
DATA "             ##..........##             "
DATA "             #..########..#             "
DATA "            ################            "
DATA "              ############              "
DATA "                 ######                 "
DATA "                ########                "
DATA "     ##############################     "
DATA "    ################################    "
DATA "     ##############################     "
DATA "     #############    #############     "
DATA "      #                          #      "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                   ###                  "
DATA "           ###    #####    ###          "
DATA "          #####   #####   #####         "
DATA "          #####   #####   #####         "
DATA "    ###   #####    ###    #####   ###   "
DATA "   #####   ###     ###     ###   #####  "
DATA "   #####    ##     ###     ##    #####  "
DATA "   #####    ##     ###     ##    #####  "
DATA "    ###     ###    ###    ###     ###   "
DATA "     ##     ###    ###    ###     ##    "
DATA "      ##    ###   #####   ###    ##     "
DATA "      ##    ####  #####  ####    ##     "
DATA "      ###   ####  #####  ####   ###     "
DATA "      ###   ####  #####  ####   ###     "
DATA "      ####  ##### ##### #####  ####     "
DATA "       ###  ##### ##### #####  ###      "
DATA "       #### ################# ####      "
DATA "       #### ################# ####      "
DATA "       ###########################      "
DATA "       ###########################      "
DATA "        #########################       "
DATA "        #####...............#####       "
DATA "         ##...#############...##        "
DATA "         ##.#################.##        "
DATA "          ####.............####         "
DATA "          ##..#############..##         "
DATA "          #####################         "
DATA "          ####.............####         "
DATA "          ##..#############..##         "
DATA "         ##.#################.##        "
DATA "         #######################        "
DATA "          #####################         "
DATA "              #############             "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                   ##                   "
DATA "                   ##                   "
DATA "                 ######                 "
DATA "                 ######                 "
DATA "                   ##                   "
DATA "                   ##                   "
DATA "                   ##                   "
DATA "                  ####                  "
DATA "                 ######                 "
DATA "                ###..###                "
DATA "        ######  ##.##.##  ######        "
DATA "      ############.##.############      "
DATA "     ###......####.##.####......###     "
DATA "     ##..####...##.##.##...####..##     "
DATA "    ##..#######..##..##..#######..##    "
DATA "    ##.#########.##..##.#########.##    "
DATA "    ##.##########.####.##########.##    "
DATA "    ##..#########.####.#########..##    "
DATA "    ###.##########.##.##########.###    "
DATA "     ##..#########.##.#########..##     "
DATA "     ###..########.##.########..###     "
DATA "      ###..#######.##.#######..###      "
DATA "       ###..#......##......#..###       "
DATA "        ###...############...###        "
DATA "         ######################         "
DATA "         ######################         "
DATA "          ###..............###          "
DATA "          ##..############..##          "
DATA "          #####..........#####          "
DATA "         ###....########....###         "
DATA "        ###..##############..###        "
DATA "         ######################         "
DATA "           ##################           "
DATA "               ##########               "
DATA "                                        "
DATA "                                        "
DATA "                                        "
DATA "                                        "

'BasicCoder2 vs. ESCHECS

data "e2e4"
data "e7e6"
data "d2d4"
data "d7d5"
data "e4d5"
data "e6d5"
data "g1f3"
data "g8f6"
data "c1g5"
data "f8b4"
data "c2c3"
data "b4d6"
data "b1d2"
data "c8f5"
data "f3e5"
data "b8c6"
data "d2f3"
data "h7h6"
data "g5h4"
data "g7g5"
data "h4g3"
data "d6e5"
data "f3e5"
data "c6e5"
data "g3e5"
data "d8e7"
data "f1e2"
data "h8g8"
data "e1g1"
data "h1f1"  'castle
data "f6h7"
data "f1e1"
data "f7f6"
data "e5g3"
data "f5e4"
data "f2f3"
data "f6f5"
data "f3e4"
data "f5e4"
data "e2h5"
data "e8d8"
data "d1g4"
data "a7a6"
data "e1f1"
data "e7d7"
data "f1f7"
data "d7g4"
data "h5g4"
data "g8h8"
data "a1f1"
data "e4e3"
data "f7h7"
data "h8h7"
data "f1f8"
data "d8e7"
data "f8a8"
data "c7c6"
data "a8b8"
data "e7f6"
data "b8e8"
data "h6h5"
data "g4e2"
data "a6a5"
data "e8e3"
data "a5a4"
data "g3e5"
data "f6f7"
data "e3f3"
data "f7g8"
data "f3f5"
data "g5g4"
data "f5g5"
data "g8f8"
data "e2d3"
data "h7f7"
data "g5f5"
data "f7f5"
data "d3f5"
data "f8f7"
data "g1f2"
data "f7f8"
data "f2g3"
data "a4a3"
data "b2b3"
data "b7b6"
data "g3h4"
data "c6c5"
data "h4h5"
data "c5c4"
data "b3b4"
data "b6b5"
data "h5g4"
data "f8e7"
data "h2h4"
data "e7e8"
data "h4h5"
data "e8e7"
data "h5h6"
data "e7e8"
data "h6h7"
data "e8e7"
data "h7h8"
data "EXIT"
Last edited by BasicCoder2 on Nov 12, 2013 7:10, edited 2 times in total.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Nov 11, 2013 6:26

@VANYA
@BasicCoder2

Thank you for your tests and reports. I observed myself things like that, when I tried to make the engine play versus himself : sometimes he takes a very long time to play, and suddenly he plays several moves in a second. I have no idea of what happens.
Maybe I could add a time limitation in the computer move procedure. Maybe also I could add a log file to understand what happens. If I don't find a better solution, I will reset search depth to minimal value.

John, your game viewer is nice !
BasicCoder2
Posts: 2813
Joined: Jan 01, 2009 7:03

Re: Eschecs

Postby BasicCoder2 » Nov 11, 2013 10:21

Roland Chastain wrote:John, your game viewer is nice !


Not sure what part of the program you find nice? Unlike my full chess playing program it actually doesn't handle reverse castling, en passant moves or pawn promotions. It was just a short piece of code to give a visual view of the game I played against Eschecs as I think that is easier to follow than reading the symbols.

As a chess program must have a undo move and redo move to explore a game tree the mechanisms are there to add stepping back and forth through a list of game moves.

The online program below uses an arrow between squares so I modified the program above to draw a yellow arrow between the squares as well just for fun.

I tried to use this online chess program to play against your Eschecs but it kept freezing up. You may have more luck.

http://chessok.com/?page_id=357
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Nov 11, 2013 13:02

Thank you for the link, John. It seems to be a good program. But, honestly, I have already many chess programs in my computer, that I haven't time enough to use. I have bought Rybka 4 and Chess Partner, and I have also beautiful free programs, like Fritz 5.32 that you can find here if you are interested.

As you say that your engine isn't finished, wouldn't you interested in making a game viewer ? I thought I could modify the code that you posted, replacing built-in data with a function to read a text file (that one could drag and drop), but as you said, there would be a problem with en passant move and castling.

Maybe I will make a game viewer myself, beside my first program. For now I try to understand why my program freezes.
Last edited by Roland Chastain on Dec 03, 2013 11:23, edited 1 time in total.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Nov 11, 2013 16:59

Here is a test program. It makes JSCP.exe play versus itself : it doesn't freeze. The game stops after 200 moves, average time per move is 1400 ms on my machine. If you want to make the test, paste the code in the engine folder.

Code: Select all

#include "flag.bas"
#include "..\chess\chess.bas"

const engine = "JSCP.exe"

declare function Exists(file as string) as integer
declare function EngineMove(exe as string, param as string) as string

dim game as tChessGame
dim move as string
dim count as integer
dim as double startTime, endTime
dim as integer averageTime = 0

open "test11.txt" for output as #1

game.Initialize()
count = 0

if Exists(engine) then
  do
    count += 1
    startTime = timer
    move = EngineMove(engine, game.FEN)
    endTime = timer
    game.DoMove(move)
    print #1, str(count) & ". " & left(move, 4) & " / flag = " & right(move, 1) & " / time = " & str(fix((endTime - startTime) * 1000)) & " ms"
    print #1, ""
    print #1, game.Text
    print #1, ""
    averageTime += fix((endTime - startTime) * 1000)
  loop until (move[5] - 48 > checkFlag) or (count = 200)
  averageTime \= count
  print #1, "average time = " & str(averageTime) & " ms"
else
  print #1, "Executable not found"
end if

close #1

function Exists(file as string) as integer
  return len(dir(file)) > 0
end function

function EngineMove(exe as string, param as string) as string
  dim n as ubyte = freefile
  open pipe exe & " " & """" & param & """" for input as #n
  dim as string s
  line input #n, s
  close #n
  function = s
end function


So, why is there a problem when the same JSCP.exe is called from eschecs.exe ?
Last edited by Roland Chastain on Dec 03, 2013 11:25, edited 1 time in total.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Nov 11, 2013 21:21

I made a version of the program with the engine included in code (instead of being compiled separately and called by a pipe), but it didn't solve the problem. So I simply restored the initial depth values.

I added last move highlighting. Files updated. I stop to work on that version.
Last edited by Roland Chastain on Dec 06, 2013 12:47, edited 1 time in total.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Dec 04, 2013 14:32

Hello !

Here is an example of rebelbook.dll usage. Thanks to TJF, who gave to me the main part of the code.

Code: Select all

' rebelbook.dll usage example
' rebelbook.dll and binary files download :
' http://www.top-5000.nl/tools.htm

extern "C" lib "rebelbook"
declare function INITIALIZE(byval as zstring ptr, byval as zstring ptr) as integer
declare function FIND_OPENING(byval as zstring ptr, byval as zstring ptr, byval as zstring ptr, byval as zstring ptr, byval as zstring ptr, byval as zstring ptr, byval as zstring ptr, byval as integer) as integer
declare sub CLOSE_BOOK()
end extern

dim as zstring*200 EPD = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"
dim as zstring*10 from, to_
dim as zstring*20 from1, from2, to1, to2
dim as integer number

if INITIALIZE(@"tourbook.bin", @"mainbook.bin") = 0 then
  if FIND_OPENING(@EPD, @from, @to_, @from1, @from2, @to1, @to2, @number) = 0 then
    ' move from tournament book
    print from & to_
    ' other moves found
    for i as integer = 0 to number - 1
      print chr(from1[i]) & chr(from2[i]) & chr(to1[i]) & chr(to2[i])
    next i
  end if
  CLOSE_BOOK()
end if

sleep


Is there a way to get rid of this warning : "Passing pointer to scalar, at parameter 8 of FIND_OPENING()" ?
TJF
Posts: 3324
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: Eschecs

Postby TJF » Dec 04, 2013 14:40

Roland Chastain wrote:Is there a way to get rid of this warning : "Passing pointer to scalar, at parameter 8 of FIND_OPENING()" ?


Remove @

Code: Select all

IF FIND_OPENING(@EPD, @from, @to_, @from1, @from2, @to1, @to2, number) = 0 THEN
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Dec 04, 2013 18:13

Thank you for your answer, TJF.

When I removed the "@", the program compiled but crashed at execution. So I tried to keep the "@" and replace "integer" with "integer ptr" in the declaration of the function, and now it works.
TJF
Posts: 3324
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: Eschecs

Postby TJF » Dec 05, 2013 15:14

Roland Chastain wrote:Thank you for your answer, TJF.

When I removed the "@", the program compiled but crashed at execution. So I tried to keep the "@" and replace "integer" with "integer ptr" in the declaration of the function, and now it works.


I checked the source again (thanks for adding the link again):

The C source

Code: Select all

DllExport int FIND_OPENING(const char *EPD,char *From,char *To,char *From1,char *From2,char *To1,char *To2,int *bookmvs);

translates to

Code: Select all

EXTERN "C" LIB "rebelbook"
...
DECLARE FUNCTION FIND_OPENING( _
   BYVAL EPD AS CONST ZSTRING PTR, _
   BYVAL From AS ZSTRING PTR, _
   BYVAL To_ AS ZSTRING PTR, _
   BYVAL From1 AS ZSTRING PTR, _
   BYVAL From2 AS ZSTRING PTR, _
   BYVAL To1 AS ZSTRING PTR, _
   BYVAL To2 AS ZSTRING PTR, _
   BYVAL bookmvs AS INTEGER PTR) AS INTEGER
...
END EXTERN

(Remove the parameter names if you like.)

It seems that I missed the last PTR in the parameter list. Sorry for that. I recommend to adapt the parameter list and use your first version.

Code: Select all

dim as integer number

if INITIALIZE(@"tourbook.bin", @"mainbook.bin") = 0 then
  if FIND_OPENING(@EPD, @from, @to_, @from1, @from2, @to1, @to2, @number) = 0 then
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Dec 05, 2013 19:11

Thank you very much, TJF. Now the code is perfect.

Return to “Projects”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest