Eschecs 1.2.1 (UCI chess GUI)

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

Re: Eschecs

Postby Roland Chastain » Apr 02, 2018 8:43

Hello Paul!

Thank you for your message. Yes, there is many things to do or to improve, and I can't spend all my time on that project. :)

If I had time, I would like to break the program into two pieces: on one hand a GUI using UCI protocol, on the other hand a standalone chess engine. I would also like to change the way the user move pieces with mouse.

This morning I cleaned this UCI demo. Comments welcome.

Code: Select all

' ucidemo1.bas
' Communication with a UCI chess engine under Windows.
' http://free-basic.ru/chess_fruit.html
' http://www.freebasic-portal.de/porticula/fbporticula1668.bas

#include "windows.bi"

declare sub Connect(aUciEngine as const string)
declare sub SendCommand(aUciCommand as const string)
declare function TryGetAnswer() as string
declare function WaitForAnswer(aKeyword as const string, aSleepValue as const integer = 10, aMaxLoop as const integer = 1000) as string

Screen 19
dim as integer breit, hoch
ScreenInfo breit, hoch
Width breit\8, hoch\14

dim answer as string

if ChDir("C:\Chess\Pharaon") = 0 then
  Connect("Pharaon.exe")
  SendCommand("uci")
  answer = WaitForAnswer("uciok")
  print(answer)
  SendCommand("ucinewgame")
  SendCommand("isready")
  answer = WaitForAnswer("readyok")
  print(answer)
  SendCommand("position startpos moves e2e4")
  SendCommand("go movetime 1000")
  answer = WaitForAnswer("bestmove")
  print(answer)
  SendCommand("quit")
end if

sleep

dim shared as HANDLE rh1, wh1

sub Connect(aUciEngine as const string)
  dim as HANDLE rh2, wh2
  dim as STARTUPINFO vInfo
  dim as PROCESS_INFORMATION vPrInfo
  dim as SECURITY_ATTRIBUTES vAttr

  vAttr.nLength = SizeOf(SECURITY_ATTRIBUTES)
  vAttr.lpSecurityDescriptor = NULL
  vAttr.bInheritHandle = TRUE

  CreatePipe(@rh2, @wh1, @vAttr, 0)
  CreatePipe(@rh1, @wh2, @vAttr, 0)

  SetHandleInformation(wh1, HANDLE_FLAG_INHERIT, 0)
  SetHandleInformation(rh1, HANDLE_FLAG_INHERIT, 0)

  GetStartupInfo(@vInfo)
  with vInfo
    .dwFlags     = STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW
    .wShowWindow = SW_HIDE
    .hStdOutput  = wh2
    .hStdError   = wh2
    .hStdInput   = rh2
  end with

  CreateProcess(0, aUciEngine, 0, 0, TRUE, 0, 0, 0, @vInfo, @vPrInfo)

  CloseHandle(wh2)
  CloseHandle(rh2)
end sub

sub SendCommand(aUciCommand as const string)
  dim as integer vWritten
  dim as string vBuffer = aUciCommand & Chr(10)

  WriteFile(wh1, StrPtr(vBuffer), Len(vBuffer), @vWritten, NULL)
end sub

function TryGetAnswer() as string
  const MAX_BUFFER_SIZE = 4096

  dim as integer vCount, vCountRead
  dim as string vBuffer
  dim as string vResult = ""

  do
    Sleep(1)

    PeekNamedPipe(rh1, NULL, NULL, NULL, @vCount, NULL)

    if vCount > 0 then
      if vCount > MAX_BUFFER_SIZE then
        vCount = MAX_BUFFER_SIZE
      end if
      vBuffer = String(vCount, Chr(0))
      ReadFile(rh1, StrPtr(vBuffer), vCount, @vCountRead, NULL)
      vResult &= vBuffer
    else
      exit do
    end if
  loop

  return vResult
end function

function WaitForAnswer(aKeyword as const string, aSleepValue as const integer, aMaxLoop as const integer) as string
  dim vResult as string
  dim vCount as integer = 0
  do
    Sleep(10)
    vResult = TryGetAnswer()
    vCount += 1
  loop until (InStrRev(vResult, aKeyword) > 0) or (vCount = aMaxLoop)
  return Trim(vResult, any Chr(13, 10))
end function
Last edited by Roland Chastain on Apr 20, 2018 17:28, edited 1 time in total.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Apr 03, 2018 18:38

Hello! Here is a new version of the Warlord chess pieces. Now for the same price you have a custom cursor. :)

Code: Select all

' chessboard.bas

#include "fbgfx.bi"

#include "colors.bi"
#include "pieces.bi"
#include "cursor.bi"

const BRDX = 0
const BRDY = 0
const SQRW = 48
const BRDW = 8 * SQRW
const BUFW = 10 * SQRW
const LSC = colors.MEDIUMSLATEBLUE
const DSC = colors.SLATEBLUE
const A = 1
const H = 8
const EMPTY = 0
const PAWN = 1
const KING = 6
const BLACK = -1
const BACKGROUND = 0
const DARKSQUARE = 7
const GRAB = 1
const GRABBING = 2
const CURW = 32
const SLASHFILL = true
const UPSIDEDOWN = false

PiecePlacement:

data -2,-3,-4,-5,-6,-4,-3,-2
data -1,-1,-1,-1,-1,-1,-1,-1
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  1, 1, 1, 1, 1, 1, 1, 1
data  2, 3, 4, 5, 6, 4, 3, 2

ScreenRes(BRDW, BRDW, 32,, fb.GFX_NULL)

dim shared as integer board(A to H, 1 to 8)
dim shared as fb.image ptr images(BLACK * KING to DARKSQUARE)
dim shared as fb.image ptr cursor(BACKGROUND to GRABBING)
dim shared as integer mx, my, mb, ox = 0, oy = 0, cur = GRAB
dim buffer as fb.image ptr = ImageCreate(BUFW, BUFW, LSC)

declare sub CreateImages()
declare sub DestroyImages()
declare sub DrawImages()
declare sub LoadBoard()
declare sub Redraw(aBuffer as fb.image ptr)
declare sub BufferToScreen(aBuffer as fb.image ptr)
declare sub RedrawBackgroundImage(aX as const integer, aY as const integer)
declare function XToBoard() as integer
declare function YToBoard() as integer
declare function XYToName(aX as const integer, aY as const integer) as string
declare sub PreventCursorExit()

CreateImages()
DrawImages()
LoadBoard()

ScreenRes(BRDW, BRDW, 32)
WindowTitle("Warlord Chessboard")
SetMouse ,, 0
Redraw(buffer)
BufferToScreen(buffer)

dim as integer dx, dy, brd, px, py
dim key as string
dim forceRedraw as boolean = false

do
  Sleep(1)
  if GetMouse(mx, my,, mb) = 0 then
    PreventCursorExit()
    if (cur = GRAB) andalso (mb = 1) andalso (board(XToBoard(), YToBoard()) <> EMPTY) then
      cur = GRABBING
      dx = SQRW * (mx \ SQRW) - mx
      dy = SQRW * (my \ SQRW) - my
      px = XToBoard()
      py = YToBoard()
      brd = board(px, py)
      RedrawBackgroundImage(px, py)
      forceRedraw = true
    elseif (cur = GRABBING) andalso (mb = 0) then
      cur = GRAB
      board(px, py) = EMPTY
      px = XToBoard()
      py = YToBoard()
      board(px, py) = brd
      Redraw(buffer)
      BufferToScreen(buffer)
    end if
    if cbool((mx <> ox) or (my <> oy)) or forceRedraw then
      if cbool(cur = GRABBING) and not forceRedraw then
        Put buffer, (ox + dx + SQRW, oy + dy + SQRW), images(BACKGROUND), PSET
        Get buffer, (mx + dx + SQRW, my + dy + SQRW)-(mx + dx + 2 * SQRW - 1, my + dy + 2 * SQRW - 1), images(BACKGROUND)
        Put buffer, (mx + dx + SQRW, my + dy + SQRW), images(brd), TRANS
      else
        forceRedraw = false
        if (ox <> 0) and (oy <> 0) then
          Put buffer, (ox + SQRW - 16, oy + SQRW - 16), cursor(BACKGROUND), PSET
        end if
      end if
      Get buffer, (mx + SQRW - 16, my + SQRW - 16)-(mx + SQRW + 15, my + SQRW + 15), cursor(BACKGROUND)
      Put buffer, (mx + SQRW - 16, my + SQRW - 16), cursor(cur), TRANS
      BufferToScreen(buffer)
      ox = mx
      oy = my
    end if
  end if
  key = InKey
loop until (key = Chr(255) & "k") or (key = Chr(27))

SetMouse ,, 1

DestroyImages()

sub CreateImages()
  for i as integer = BLACK * KING to DARKSQUARE
    images(i) = ImageCreate(SQRW, SQRW)
  next i
  for i as integer = BACKGROUND to GRABBING
    cursor(i) = ImageCreate(CURW, CURW)
  next i
end sub

sub DestroyImages()
  for i as integer = BLACK * KING to DARKSQUARE
    ImageDestroy(images(i))
  next i

  for i as integer = BACKGROUND to GRABBING
    ImageDestroy(cursor(i))
  next i
end sub

sub DrawImages()
  const SYMBOLS = "prnbqk"
 
  dim datum as string
  dim as uinteger c1, c2
 
  Restore WarlordChessPieces
  for i as integer = PAWN to KING
    for y as integer = 0 to SQRW - 1
      Read(datum)
      for x as integer = 0 to SQRW - 1
        select case as const datum[x]
          case asc("0")
            c1 = colors.MAGENTA
            c2 = colors.MAGENTA
          case asc("1")
            c1 = colors.GRAY
            c2 = colors.GRAY
          case asc("2")
            c1 = colors.IVORY
            c2 = colors.BLACK
        end select
        PSet images( i), (x, y), c1
        PSet images(-i), (x, y), c2
      next x
    next y
  next i

  if SLASHFILL then
    for i as integer = BLACK * KING to KING
      if i = BACKGROUND then
        continue for
      end if
      for x as integer = 1 to SQRW - 2
        for y as integer = 1 to SQRW - 2
          if Point(x, y, images(i)) = colors.MAGENTA then
            if (Point(x,     y - 1, images(i)) = colors.GRAY) _
            or (Point(x + 1, y - 1, images(i)) = colors.GRAY) _
            or (Point(x + 1, y,     images(i)) = colors.GRAY) _
            or (Point(x + 1, y + 1, images(i)) = colors.GRAY) _
            or (Point(x,     y + 1, images(i)) = colors.GRAY) _
            or (Point(x - 1, y + 1, images(i)) = colors.GRAY) _
            or (Point(x - 1, y,     images(i)) = colors.GRAY) _
            or (Point(x - 1, y - 1, images(i)) = colors.GRAY) then
              PSet images(i), (x, y), LSC
            end if
          end if
        next y
      next x
    next i
    for x as integer = 0 to SQRW - 1
      for y as integer = 0 to SQRW - 1
        PSet images(DARKSQUARE), (x, y), iif((x + y) mod 5 = 2, colors.BLACK, colors.MAGENTA)
      next y
    next x
  else
    Line images(DARKSQUARE), (0, 0)-(SQRW - 1, SQRW - 1), DSC, BF
  end if

  Restore HandCursor:
  for i as integer = GRAB to GRABBING
    for y as integer = 0 to CURW - 1
      Read datum
      for x as integer = 0 to CURW - 1
        select case as const datum[x]
          case asc("0")
            PSet cursor(i), (x, y), colors.MAGENTA
          case asc("1")
            PSet cursor(i), (x, y), colors.BLACK
          case asc("2")
            PSet cursor(i), (x, y), &hFFEFFF
        end select
      next x
    next y
  next i

  if false then
    for i as integer = PAWN to KING
      BSave "w" & mid(SYMBOLS, i, 1) & ".bmp", images(i)
      BSave "b" & mid(SYMBOLS, i, 1) & ".bmp", images(-i)
    next i
    BSave "darksquare.bmp", images(DARKSQUARE)
    BSave "grab.bmp", cursor(GRAB)
    BSave "grabbing.bmp", cursor(GRABBING)
  end if
end sub

sub LoadBoard()
  Restore PiecePlacement:
  for y as integer = 8 to 1 step -1
    for x as integer = A to H
      Read(board(x, y))
    next x
  next y
end sub

sub Redraw(aBuffer as fb.image ptr)
  dim as integer xToBuf, yToBuf
  Line aBuffer, (0, 0)-(BUFW, BUFW), LSC, BF
  for y as integer = 1 to 8
    for x as integer = A to H
      xToBuf = x * SQRW
      yToBuf = IIf(UPSIDEDOWN, y, 9 - y) * SQRW
      if (x + y) mod 2 = 0 then
        Put aBuffer, (xToBuf, yToBuf), images(DARKSQUARE), TRANS
      end if
      if board(x, y) <> EMPTY then
        Put aBuffer, (xToBuf, yToBuf), images(board(x, y)), TRANS
      end if
    next x
  next y
  if (mx <> 0) or (my <> 0) then
    Get aBuffer, (mx + SQRW - 16, my + SQRW - 16)-(mx + SQRW + 15, my + SQRW + 15), cursor(BACKGROUND)
    Put aBuffer, (mx + SQRW - 16, my + SQRW - 16), cursor(cur), TRANS
  end if
end sub

sub BufferToScreen(aBuffer as fb.image ptr)
  Put (BRDX, BRDY), aBuffer, (SQRW, SQRW)-(9 * SQRW - 1, 9 * SQRW - 1), PSET
end sub

sub RedrawBackgroundImage(aX as const integer, aY as const integer)
  if SLASHFILL then
    Line images(BACKGROUND), (0, 0)-(SQRW - 1, SQRW - 1), LSC, BF
    if (aX + aY) mod 2 = 0 then
      Put images(BACKGROUND), (0, 0), images(DARKSQUARE), (0, 0)-(SQRW - 1, SQRW - 1), TRANS
    end if
  else
    Line images(BACKGROUND), (0, 0)-(SQRW - 1, SQRW - 1), iif((aX + aY) mod 2 = 1, LSC, DSC), BF
  end if
end sub

function XToBoard() as integer
  return mx \ SQRW + 1
end function

function YToBoard() as integer
  return IIf(UPSIDEDOWN, my \ SQRW + 1, 8 - my \ SQRW)
end function

function XYToName(aX as const integer, aY as const integer) as string
  return Chr(Asc("a") - 1 + aX, Asc("1") - 1 + aY)
end function

sub PreventCursorExit()
  const BORDER = 12
  if mx < BORDER then
    mx = BORDER
  elseif mx > BRDW - 1 - BORDER then
    mx = BRDW - 1 - BORDER
  end if
  if my < BORDER then
    my = BORDER
  elseif my > BRDW - 1 - BORDER then
    my = BRDW - 1 - BORDER
  end if
end sub


Code: Select all

' colors.bi

namespace colors

const AliceBlue = &hF0F8FF
const AlizarinCrimson = &hE32636
const Amber = &hFFBF00
const Amethyst = &h9966CC
const AntiqueWhite = &hFAEBD7
const Aquamarine = &h7FFFD4
const Asparagus = &h7BA05B
const Azure = &hF0FFFF
const Beige = &hF5F5DC
const Bisque = &hFFE4C4
const Bistre = &h3D2B1F
const BitterLemon = &hCAE00D
const Black = &h000000
const BlanchedAlmond = &hFFEBCD
const BlazeOrange = &hFF9900
const Blue = &h0000FF
const BlueViolet = &h8A2BE2
const BondiBlue = &h0095B6
const Brass = &hB5A642
const BrightGreen = &h66FF00
const BrightTurquoise = &h08E8DE
const BrightViolet = &hCD00CD
const Bronze = &hCD7F32
const Brown = &hA52A2A
const Buff = &hF0DC82
const Burgundy = &h900020
const BurlyWood = &hDEB887
const BurntOrange = &hCC5500
const BurntSienna = &hE97451
const BurntUmber = &h8A3324
const CadetBlue = &h5F9EA0
const CamouflageGreen = &h78866B
const Cardinal = &hC41E3A
const Carmine = &h960018
const Carrot = &hED9121
const Casper = &hADBED1
const Celadon = &hACE1AF
const Cerise = &hDE3163
const Cerulean = &h007BA7
const CeruleanBlue = &h2A52BE
const Chartreuse = &h7FFF00
const Chocolate = &hD2691E
const Cinnamon = &h7B3F00
const Cobalt = &h0047AB
const Copper = &hB87333
const Coral = &hFF7F50
const Corn = &hFBEC5D
const CornflowerBlue = &h6495ED
const Cornsilk = &hFFF8DC
const Cream = &hFFFDD0
const Crimson = &hDC143C
const Cyan = &h00FFFF
const DarkBlue = &h00008B
const DarkBrown = &h654321
const DarkCerulean = &h08457E
const DarkChestnut = &h986960
const DarkCoral = &hCD5B45
const DarkCyan = &h008B8B
const DarkGoldenrod = &hB8860B
const DarkGray = &h545454
const DarkGreen = &h006400
const DarkIndigo = &h310062
const DarkKhaki = &hBDB76B
const DarkMagenta = &h8B008B
const DarkOlive = &h556832
const DarkOliveGreen = &h556B2F
const DarkOrange = &hFF8C00
const DarkOrchid = &h9932CC
const DarkPastelGreen = &h03C03C
const DarkPink = &hE75480
const DarkRed = &h8B0000
const DarkSalmon = &hE9967A
const DarkScarlet = &h560319
const DarkSeaGreen = &h8FBC8F
const DarkSlateBlue = &h483D8B
const DarkSlateGray = &h2F4F4F
const DarkSpringGreen = &h177245
const DarkTan = &h918151
const DarkTangerine = &hFFA812
const DarkTeaGreen = &hBADBAD
const DarkTerraCotta = &hCC4E5C
const DarkTurquoise = &h00CED1
const DarkViolet = &h9400D3
const DeepPink = &hFF1493
const DeepSkyBlue = &h00BFFF
const Denim = &h1560BD
const DimGray = &h696969
const DodgerBlue = &h1E90FF
const Emerald = &h50C878
const Eggplant = &h990066
const FernGreen = &h4F7942
const FireBrick = &hB22222
const Flax = &hEEDC82
const FloralWhite = &hFFFAF0
const ForestGreen = &h228B22
const Fractal = &h808080
const Fuchsia = &hF400A1
const Gainsboro = &hDCDCDC
const Gamboge = &hE49B0F
const GhostWhite = &hF8F8FF
const Gold = &hFFD700
const Goldenrod = &hDAA520
const Gray = &h7E7E7E
const GrayAsparagus = &h465945
const GrayTeaGreen = &hCADABA
const Green = &h008000
const GreenYellow = &hADFF2F
const Heliotrope = &hDF73FF
const Honeydew = &hF0FFF0
const HotPink = &hFF69B4
const IndianRed = &hCD5C5C
const Indigo = &h4B0082
const InternationalKleinBlue = &h002FA7
const InternationalOrange = &hFF4F00
const Ivory = &hFFFFF0
const Jade = &h00A86B
const Khaki = &hF0E68C
const Lavender = &hE6E6FA
const LavenderBlush = &hFFF0F5
const LawnGreen = &h7CFC00
const Lemon = &hFDE910
const LemonChiffon = &hFFFACD
const LightBlue = &hADD8E6
const LightBrown = &hD2B48C
const LightCoral = &hF08080
const LightCyan = &hE0FFFF
const LightGoldenrodYellow = &hFAFAD2
const LightGray = &hA8A8A8
const LightGreen = &h90EE90
const LightMagenta = &hFF80FF
const LightPink = &hFFB6C1
const LightRed = &hFF8080
const LightSalmon = &hFFA07A
const LightSeaGreen = &h20B2AA
const LightSkyBlue = &h87CEFA
const LightSlateGray = &h778899
const LightSteelBlue = &hB0C4DE
const LightYellow = &hFFFFE0
const Lilac = &hC8A2C8
const Lime = &h00FF00
const LimeGreen = &h32CD32
const Linen = &hFAF0E6
const Magenta = &hFF00FF
const Malachite = &h0BDA51
const Maroon = &h800000
const Mauve = &hE0B0FF
const MediumAquamarine = &h66CDAA
const MediumBlue = &h0000CD
const MediumOrchid = &hBA55D3
const MediumPurple = &h9370DB
const MediumSeaGreen = &h3CB371
const MediumSlateBlue = &h7B68EE
const MediumSpringGreen = &h00FA9A
const MediumTurquoise = &h48D1CC
const MediumVioletRed = &hC71585
const MidnightBlue = &h191970
const MintCream = &hF5FFFA
const MistyRose = &hFFE4E1
const Moccasin = &hFFE4B5
const MoneyGreen = &hC0DCC0
const Monza = &hC7031E
const MossGreen = &hADDFAD
const MountbattenPink = &h997A8D
const Mustard = &hFFDB58
const NavajoWhite = &hFFDEAD
const Navy = &h000080
const Ochre = &hCC7722
const OldGold = &hCFB53B
const OldLace = &hFDF5E6
const Olive = &h808000
const OliveDrab = &h6B8E23
const Orange = &hFFA500
const OrangeRed = &hFF4500
const Orchid = &hDA70D6
const PaleBrown = &h987654
const PaleCarmine = &hAF4035
const PaleChestnut = &hDDADAF
const PaleCornflowerBlue = &hABCDEF
const PaleGoldenrod = &hEEE8AA
const PaleGreen = &h98FB98
const PaleMagenta = &hF984E5
const PaleMauve = &h996666
const PalePink = &hFADADD
const PaleSandyBrown = &hDABDAB
const PaleTurquoise = &hAFEEEE
const PaleVioletRed = &hDB7093
const PapayaWhip = &hFFEFD5
const PastelGreen = &h77DD77
const PastelPink = &hFFD1DC
const Peach = &hFFE5B4
const PeachOrange = &hFFCC99
const PeachPuff = &hFFDAB9
const PeachYellow = &hFADFAD
const Pear = &hD1E231
const Periwinkle = &hCCCCFF
const PersianBlue = &h6600FF
const Peru = &hCD853F
const PineGreen = &h01796F
const Pink = &hFFC0CB
const PinkOrange = &hFF9966
const Plum = &hDDA0DD
const PowderBlue = &hB0E0E6
const PrussianBlue = &h003153
const Puce = &hCC8899
const Pumpkin = &hFF7518
const Purple = &h800080
const RawUmber = &h734A12
const Red = &hFF0000
const Reef = &hC9FFA2
const RobinEggBlue = &h00CCCC
const RosyBrown = &hBC8F8F
const RoyalBlue = &h4169E1
const Russet = &h80461B
const Rust = &hB7410E
const SaddleBrown = &h8B4513
const Saffron = &hF4C430
const Salmon = &hFA8072
const SandyBrown = &hF4A460
const Sangria = &h92000A
const Sapphire = &h082567
const Scarlet = &hFF2400
const SchoolBusYellow = &hFFD800
const SeaGreen = &h2E8B57
const SeaShell = &hFFF5EE
const SelectiveYellow = &hFFBA00
const Sepia = &h704214
const Sienna = &hA0522D
const Silver = &hC0C0C0
const SkyBlue = &h87CEEB
const SlateBlue = &h6A5ACD
const SlateGray = &h708090
const Snow = &hFFFAFA
const SpringGreen = &h00FF7F
const SteelBlue = &h4682B4
const SwampGreen = &hACB78E
const Taupe = &hBC987E
const Tangerine = &hFFCC00
const Teal = &h008080
const TeaGreen = &hD0F0C0
const Tenne = &hCD5700
const TerraCotta = &hE2725B
const Thistle = &hD8BFD8
const Tomato = &hFF6347
const Turquoise = &h40E0D0
const Ultramarine = &h120A8F
const Vermilion = &hFF4D00
const Violet = &hEE82EE
const VioletEggplant = &h991199
const Viridian = &h40826D
const Wheat = &hF5DEB3
const White = &hFFFFFF
const WhiteSmoke = &hF5F5F5
const Wisteria = &hC9A0DC
const Yellow = &hFFFF00
const YellowGreen = &h9ACD32
const Zinnwaldite = &hEBC2AF

end namespace


Code: Select all

' pieces.bi

WarlordChessPieces:

data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000011111111000000000000000000000"
data "000000000000000000122222222100000000000000000000"
data "000000000000000001222222222210000000000000000000"
data "000000000000000012222222222221000000000000000000"
data "000000000000000122222222221222100000000000000000"
data "000000000000000122222222222122100000000000000000"
data "000000000000000122222222222122100000000000000000"
data "000000000000000122222222222122100000000000000000"
data "000000000000000122222222222122100000000000000000"
data "000000000000000122222222221222100000000000000000"
data "000000000000000012222222222221000000000000000000"
data "000000000000000001222222222210000000000000000000"
data "000000000000000000122222222100000000000000000000"
data "000000000000000000122222222100000000000000000000"
data "000000000000000000122222222100000000000000000000"
data "000000000000000000122222222100000000000000000000"
data "000000000000000001222222222210000000000000000000"
data "000000000000000012222222222221000000000000000000"
data "000000000000000122222222221222100000000000000000"
data "000000000000001222222222222122210000000000000000"
data "000000000000012222222222222212221000000000000000"
data "000000000000122222222222222221222100000000000000"
data "000000000001222222222222222222122210000000000000"
data "000000000012222222222222222222212221000000000000"
data "000000000122222222222222222222222222100000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001221111111111111111111111112221000000000"
data "000000001222222222222222222222222222221000000000"
data "000000001222222222222222222222222222221000000000"
data "000000001222222222222222222222222222221000000000"
data "000000001111111111111111111111111111111000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"

data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000111111110011111111001111111100000000000"
data "000000000122222210012222221001222222100000000000"
data "000000000122222210012222221001222222100000000000"
data "000000000122222210012222221001222222100000000000"
data "000000000122222210012222221001222222100000000000"
data "000000000122222210012222221001222222100000000000"
data "000000000122222210012222221001222222100000000000"
data "000000000122222211112222221111222222100000000000"
data "000000000122222222222222222222222222100000000000"
data "000000000122222222222222222222222222100000000000"
data "000000000122222222222222222222222222100000000000"
data "000000000111121111111111111111112111100000000000"
data "000000000000122222222222222222222100000000000000"
data "000000000000122111111122222222222100000000000000"
data "000000000000122100000122222222222100000000000000"
data "000000000000122100000122222222222100000000000000"
data "000000000000122100000122222222222100000000000000"
data "000000000000122111111122222222222100000000000000"
data "000000000000122222222221111111222100000000000000"
data "000000000000122222222221000001222100000000000000"
data "000000000000122222222221000001222100000000000000"
data "000000000000122222222221000001222100000000000000"
data "000000000000122222222221111111222100000000000000"
data "000000000000122222222222222222222100000000000000"
data "000000000000121111111111111111112100000000000000"
data "000000000011222222222222222222222211000000000000"
data "000000000122222222222222222222222222100000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001222222222222222222222222222210000000000"
data "000000001111111111111111111111111111110000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"

data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000010000000000000000"
data "000000000000000000000000000000121000000000000000"
data "000000000000000000000000000001222100000000000000"
data "000000000000000000000000000012222100000000000000"
data "000000000000000000000000000122222100000000000000"
data "000000000000000000000000001222222100000000000000"
data "000000000000000000000011111222221210000000000000"
data "000000000000000000011122221222221221000000000000"
data "000000000000000000122222222222222221000000000000"
data "000000000000000001221112222222222222100000000000"
data "000000000000000012211122222222222222100000000000"
data "000000000000001122222222222222222212210000000000"
data "000000000000112222222222222222222221221000000000"
data "000000000001222222222222222222222222122100000000"
data "000000001112222222222222222222222212212100000000"
data "000000012222222222222222221222222221221100000000"
data "000000012222222222222222221222222222122100000000"
data "000000012222222222222222212222222212212100000000"
data "000000011222211111111111122222222221221100000000"
data "000000000111100000012221222222222222122100000000"
data "000000000000000000012221222222222212212100000000"
data "000000000000000000012221222222222221221100000000"
data "000000000000000000012221222222222222122100000000"
data "000000000000000000012221222222222222212100000000"
data "000000000000000000012221222222222222221000000000"
data "000000000000000000122212222222222222210000000000"
data "000000000000000011222122222222222222210000000000"
data "000000000000001122222222222222222222210000000000"
data "000000000000112222222222222222222222221000000000"
data "000000000011221111111111111111111111122110000000"
data "000000000122222222222222222222222222222210000000"
data "000000001222222222222222222222222222222210000000"
data "000000001222222222222222222222222222222210000000"
data "000000001111111111111111111111111111111110000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"

data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000011111000000000000000000000"
data "000000000000000000000122222100000000000000000000"
data "000000000000000000001222222210000000000000000000"
data "000000000000000000012222222221000000000000000000"
data "000000000000000000122222222222100000000000000000"
data "000000000000000001222222222222210000000000000000"
data "000000000000000012222221112222221000000000000000"
data "000000000000000122222221012222222100000000000000"
data "000000000000001222222221012222222210000000000000"
data "000000000000012222222221012222222221000000000000"
data "000000000000122222222221012222222222100000000000"
data "000000000000122222111111011111122222100000000000"
data "000000000000122222100000000000122222100000000000"
data "000000000000122222111111011111122222100000000000"
data "000000000000122222222221012222222222100000000000"
data "000000000000122222222221012222222222100000000000"
data "000000000000012222222221012222222221000000000000"
data "000000000000001222222221012222222210000000000000"
data "000000000000000122222221112222222100000000000000"
data "000000000000000012222222222222221000000000000000"
data "000000000000000001222222222222210000000000000000"
data "000000000000000000122222222222100000000000000000"
data "000000000000000000012111111121000000000000000000"
data "000000000000000000012222222221000000000000000000"
data "000000000000000000012111111121000000000000000000"
data "000000000100000000122222222222100000000100000000"
data "000000001210000001222222222222210000001210000000"
data "000000001221111112222111111122221111112210000000"
data "000000001222222222221000000012222222222210000000"
data "000000000122222222210000000001222222222100000000"
data "000000000011111111100000000000111111111000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"

data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000110000000000000000000000"
data "000000000000000000000001221000000000000000000000"
data "000000000000000000000012222100000000000000000000"
data "000000000000000000000122112210000000000000000000"
data "000000000000000010001221001221000100000000000000"
data "000000000000000121001222112221001210000000000000"
data "000000000000001222100122222210012221000000000000"
data "000000000000012212210012222100122122100000000000"
data "000000000000122101221001221001221012210000000000"
data "000000000000012212210001221000122122100000000000"
data "000000000100001222100001221000012221000010000000"
data "000000001210000122100001221000012210000121000000"
data "000000012221000012210001221000122100001222100000"
data "000000122122100001221001221001221000012212210000"
data "000000122112210001222101221012221000122112210000"
data "000000012222100000122211221122210000012222100000"
data "000000001221000000122221221222210000001221000000"
data "000000000122100000012222222222100000012210000000"
data "000000000012211000012222222222100001122100000000"
data "000000000001222110001222222221000112221000000000"
data "000000000000122221101222222221011222210000000000"
data "000000000000012222211222222221122222100000000000"
data "000000000000001222222222222222222221000000000000"
data "000000000000000122222222112222222210000000000000"
data "000000000000000012222221001222222100000000000000"
data "000000000000000001222210000122221000000000000000"
data "000000000000000000122221001222210000000000000000"
data "000000000000000000012222112222100000000000000000"
data "000000000000000011122222222222211100000000000000"
data "000000000000000122222222222222222210000000000000"
data "000000000000000122222222222222222210000000000000"
data "000000000000000122222222222222222210000000000000"
data "000000000001111122111111111111112211111000000000"
data "000000000012222222222222222222222222222100000000"
data "000000000122222222222222222222222222222210000000"
data "000000001222222222222222222222222222222221000000"
data "000000001222222222222222222222222222222221000000"
data "000000001222222222222222222222222222222221000000"
data "000000001111111111111111111111111111111111000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"

data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000001100000000000000000000000"
data "000000000000000000000012210000000000000000000000"
data "000000000000000000000122221000000000000000000000"
data "000000000000000000001221122100000000000000000000"
data "000000000000000000012210012210000000000000000000"
data "000000000000000000012210012210000000000000000000"
data "000000000000111111001221122100111111000000000000"
data "000000000001222222100122221001222222100000000000"
data "000000000012211112210122221012211112210000000000"
data "000000000122122221221122221122122221221000000000"
data "000000001221222222122222222221222222122100000000"
data "000000012212222222212222222212222222212210000000"
data "000000122122211211221222222122112112221221000000"
data "000000121222210101222122221222101012222121000000"
data "000000121222221012222222222222210122222121000000"
data "000000121222210101222222222222101012222121000000"
data "000000122122211211222222222222112112221221000000"
data "000000012212222222222222122222222222212210000000"
data "000000001221222222222221012222222222122100000000"
data "000000000122122222222210001222222221221000000000"
data "000000000012212222222100000122222212210000000000"
data "000000000001221222222210001222222122100000000000"
data "000000000000122122222221012222221221000000000000"
data "000000000000012212222222122222212210000000000000"
data "000000000000001221222222222222122100000000000000"
data "000000000000000122122222222221221000000000000000"
data "000000000000000012212222222212210000000000000000"
data "000000000000000111222222222222111000000000000000"
data "000000000000001222222222222222222100000000000000"
data "000000000000012222222222222222222210000000000000"
data "000000000000012222222222222222222210000000000000"
data "000000000000012222222222222222222210000000000000"
data "000000000001112211111111111111112211100000000000"
data "000000000012222222222222222222222222210000000000"
data "000000000122222222222222222222222222221000000000"
data "000000001222222222222222222222222222222100000000"
data "000000001222222222222222222222222222222100000000"
data "000000001222222222222222222222222222222100000000"
data "000000001111111111111111111111111111111100000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"
data "000000000000000000000000000000000000000000000000"


Code: Select all

' cursor.bi

HandCursor:

data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000110000000000000000"
data "00000000001101221110000000000000"
data "00000000012211221221000000000000"
data "00000000012211221221010000000000"
data "00000000001221221221121000000000"
data "00000000001221221221221000000000"
data "00000000110122222221221000000000"
data "00000001221122222222221000000000"
data "00000001222122222222210000000000"
data "00000000122222222222210000000000"
data "00000000012222222222210000000000"
data "00000000012222222222100000000000"
data "00000000001222222222100000000000"
data "00000000000122222221000000000000"
data "00000000000012222221000000000000"
data "00000000000012222221000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"

data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000110110110000000000000"
data "00000000001221221221100000000000"
data "00000000001222222221210000000000"
data "00000000000122222222210000000000"
data "00000000001122222222210000000000"
data "00000000012222222222210000000000"
data "00000000012222222222100000000000"
data "00000000001222222222100000000000"
data "00000000000122222221000000000000"
data "00000000000012222221000000000000"
data "00000000000012222221000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
data "00000000000000000000000000000000"
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Apr 04, 2018 18:55

All rewritten in object style. Suggestions and improvements welcome.

Warlord Chessboard (source and Win32 binary in ZIP file)
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs

Postby Roland Chastain » Apr 08, 2018 14:55

Exported the graphics as BMP and PNG pictures.

Image
Image
Image
Image
Image
Image
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs (chess GUI)

Postby Roland Chastain » Apr 16, 2018 23:24

Hello!

Here is a new version of Eschecs. Now it uses the UCI protocol to communicate with an engine.

Play chess against Rybka 1.0!

Download Eschecs (source code and Win32 binary)

The formerly built-in chess engine has been turned into an experimental UCI engine, named Mosquito.

If you don't move the mouse over the window, the engine takes hours to answer. I don't know how to solve that problem. Until I find a solution, just move the mouse!
Last edited by Roland Chastain on Apr 21, 2018 16:45, edited 1 time in total.
caseih
Posts: 1338
Joined: Feb 26, 2007 5:32

Re: Eschecs (chess GUI)

Postby caseih » Apr 17, 2018 0:28

Sounds like the chess engine only processes when an event has been triggered. You might need to place the engine in its own thread.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs (chess GUI)

Postby Roland Chastain » Apr 17, 2018 3:44

caseih wrote:You might need to place the engine in its own thread.


I see. Thank you.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs (chess GUI)

Postby Roland Chastain » Apr 19, 2018 19:00

caseih wrote:Sounds like the chess engine only processes when an event has been triggered. You might need to place the engine in its own thread.


Done. Solution inspired by this example. Thank you fxm. ;)

Code: Select all

' eschecs.bas
type TListener
  dim handle as any ptr = 0
  dim quit as boolean = false
  dim procedure as sub (aOutput as const string) = 0
end type

declare sub ProcedureThread(byval param as any ptr)
declare sub OnOutput(aOutput as const string)
declare sub OnUciOk(aOutput as const string)
declare sub OnBestMove(aOutput as const string)


The program works very well now. It's almost the program I dreamed of when I started this project. :)

At the moment you can not select the engine at runtime: you have to edit the code and recompile the program.

Code: Select all

' eschecs.bas
const ENGINE_INDEX = 1 ' <--- change this
dim engineConnected as boolean = _
  cbool(ChDir(EXEPath() & engines(ENGINE_INDEX).ENGPATH) = 0) _
  andalso Connect(engines(ENGINE_INDEX).ENGNAME) _
  andalso uci.CompileRegExpr()


The engines data (path and name) are stored in the file engines.bi.

Download Eschecs 0.9.9
Last edited by Roland Chastain on Apr 21, 2018 16:45, edited 1 time in total.
paul doe
Posts: 913
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Eschecs (chess GUI)

Postby paul doe » Apr 19, 2018 19:22

Roland Chastain wrote:The program works very well now. It's almost the program I dreamed of when I started this project. :)

At the moment you can not select the engine at runtime: you have to edit the code and recompile the program.

Congratulations, Roland!

Say, I was thinking of you (and your Chess engines) when I wrote this. Perhaps you could use a similar technique with them? Nice work!
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs (chess GUI)

Postby Roland Chastain » Apr 19, 2018 19:46

paul doe wrote:Congratulations, Roland!


Thank you.

paul doe wrote:Say, I was thinking of you (and your Chess engines) when I wrote this. Perhaps you could use a similar technique with them?


Yes I could. Your code example gave me another fun idea. I can not say more for the moment. I have to think about it again. :)
paul doe
Posts: 913
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Eschecs (chess GUI)

Postby paul doe » Apr 19, 2018 20:04

Roland Chastain wrote:Yes I could. Your code example gave me another fun idea. I can not say more for the moment. I have to think about it again. :)

Very well, then. Looking forward! ;)
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs (UCI chess GUI)

Postby Roland Chastain » Apr 21, 2018 21:23

Another day spent on my chess program. :)

Here is a new version. Now you can choose the engine against which you play.

Image

The engines menu is generated at runtime. To add your favourite chess engine, you have to edit by hand the files engines.csv.

fruit_21.exe,Fruit,\engines\fruit\
Hermann.exe,Hermann,\engines\hermann\
mosquito.exe,Mosquito,\engines\mosquito\
Pharaon.exe,Pharaon,\engines\pharaon\
Ruffian_105.exe,Ruffian,\engines\ruffian\
Rybka v1.0 Beta.w32.exe,Rybka,\engines\rybka\


Thanks to fbsound, the referee whistles if you attempt an illegal move. :)

Download
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Eschecs 1.0

Postby Roland Chastain » Apr 24, 2018 21:28

Hello! Here is Eschecs 1.0.

The CSV file has been replaced by a JSON file. You can modify that file to add your favourite chess engine. Be careful, the paths are relative to eschecs.exe.

[
{
"command" : "fruit_21.exe",
"name" : "Fruit",
"protocol" : "uci",
"workingDirectory" : "\\engines\\fruit\\"
},
{
"command" : "Hermann.exe",
"name" : "Hermann",
"protocol" : "uci",
"workingDirectory" : "\\engines\\hermann\\"
}
]


Download Eschecs 1.0

The binary included in the ZIP file is the german version. To rebuild in another language, start a command prompt, change directory to eschecs.exe directory and type "build english" (or "build french"). Before that, you have to modify the path to the compiler in build.cmd.

Eschecs uses the following libraries. Thanks to the authors.

paul doe
Posts: 913
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Eschecs 1.0

Postby paul doe » Apr 25, 2018 3:45

Roland Chastain wrote:Hello! Here is Eschecs 1.0.

Well, congratulations! =D

Really nice work, Roland. One of these days I'll have to code mine, too. However, I'm stuck coding data structures (again), since I lost most of my old code >:(

Keep it up!
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Eschecs 1.0 (UCI chess GUI)

Postby Roland Chastain » Apr 25, 2018 16:07

@paul doe

Thank you.

In the ZIP file that I uploaded yesterday, the file engines.json was missing. I uploaded a new file.

Eschecs 1.0

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests