Mosquito (UCI chess engine)

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

Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 10, 2018 18:11

Hello!

I decided to break my chess game in two parts, a GUI and a UCI engine. Here is the engine.

Download Mosquito (source and Win32 binary).

@Luis

I hope it will be a more serious opponent for Soberango. ;)

Mosquito

UCI chess engine written in FreeBASIC by Roland Chastain.

Mosquito is based upon three chess programs: an opening book, a mate solver and a standard chess
program.

ProDeo (formerly Rebel) opening book is the work of Jeroen Noomen. The C program is the work of Ed
Schröder. Fonzy Bluemers turned the program into a dynamic library.

The mate solver is an awesome Pascal program by Valentin Albillo, ported to Free Pascal and turned
into a dynamic library. See "materdemo" folder for a simple demo based upon the examples provided by
Valentin Albillo.

JS Chess is derived from Jürgen Schlottke Pascal chess program. The program was rewritten in
FreeBASIC by Roland Chastain.
Last edited by Roland Chastain on Apr 24, 2018 22:37, edited 1 time in total.
grindstone
Posts: 639
Joined: May 05, 2015 5:35
Location: Germany

Re: Mosquito (UCI chess engine)

Postby grindstone » Apr 10, 2018 22:31

First thing to improve: mosquito should have an unambiguous mate sign, either a move that never can be legal (like "a1a1" or "a1b8" or a literal like "mate" or "NULL") and it should always be the same.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 11, 2018 6:42

@grindstone

Thank you. I will think of it.
grindstone
Posts: 639
Joined: May 05, 2015 5:35
Location: Germany

Re: Mosquito (UCI chess engine)

Postby grindstone » Apr 11, 2018 19:49

Obviously mosquito isn't oblivious of being mate.

I'll add an option to Colochessum to consider any illegal move as mate sign, although I'm pretty sure that this behaviour doesn't comply with the standard.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 11, 2018 22:18

grindstone wrote:Obviously mosquito isn't oblivious of being mate.

I'll add an option to Colochessum to consider any illegal move as mate sign, although I'm pretty sure that this behaviour doesn't comply with the standard.


Thank you for reporting that problem. It's fixed now. :)

Code: Select all

const ERRORFLAG = "a1a1"


Mosquito (source and Win32 binary)
Last edited by Roland Chastain on Apr 24, 2018 22:38, edited 1 time in total.
grindstone
Posts: 639
Joined: May 05, 2015 5:35
Location: Germany

Re: Mosquito (UCI chess engine)

Postby grindstone » Apr 12, 2018 21:42

It works.

Next thing to fix: To "position startpos moves" (with an empty moves list, means: mosquito starts as white) mosquito now responses with its mate sign ("bestmove a1a1") instead of the opening move.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 12, 2018 22:09

Thank you for testing and reporting the result.

Please replace this

Code: Select all

' mosquito.bas
  elseif uci.IsCommandPosition(cmd) then
    if uci.IsCommandStartPos(cmd) then
      game.Initialize(STARTPOS)


by this

Code: Select all

  elseif uci.IsCommandPosition(cmd) then
    if uci.IsCommandStartPos(cmd) then
      fen = STARTPOS
      game.Initialize(fen)
Luis Babboni
Posts: 300
Joined: Mar 15, 2015 12:41

Re: Mosquito (UCI chess engine)

Postby Luis Babboni » Apr 15, 2018 20:11

I can´t find a time mode that make both engines uses aproximately the same amount of time. Mosquito seems to move instantly.
I think you must add a time use strategy. With it Mosquito could join CCRL Ranks for example. I´m sure there are several weaker engines than Mosquito.

Edit 1: 300/1 seems to be a time mode whereas both enignes uses near the same amount of time.
Just 5,5 to 4,5 for Soberango in first try!
I did not see any invalid moves from Mosquito till now! :-)

Edit 2: seems I found it, is 400/1!
Match too 100 games in progress, 8.5 to 2.5 for Soberango 0.09.8 right now.

Edit 3: 100 games 400/1 time mode. Just one game ends cause illegal move. 74-12-14 for Soberango:
https://www.dropbox.com/s/9zcvjzlfvbp0iyg/Mosquito%20vs%20Soberango%200098%20T06.pgn?dl=0
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 15, 2018 22:22

Very interesting. Thank you Luis. I download your PGN and will study it.

About time control, the problem is that Mosquito uses a recursive evaluation. If I increase the depth, the program crashes. I should replace recursion by iteration, but it isn't easy to do.
Luis Babboni
Posts: 300
Joined: Mar 15, 2015 12:41

Re: Mosquito (UCI chess engine)

Postby Luis Babboni » Apr 15, 2018 22:29

Roland Chastain wrote:Very interesting. Thank you Luis. I download your PGN and will study it.

About time control, the problem is that Mosquito uses a recursive evaluation. If I increase the depth, the program crashes. I should replace recursion by iteration, but it isn't easy to do.


Sorry, my programming terminology is not good, what you mean?
But no matter what you mean, I think you could add a "time tester" that in some point of the program that you are sure takes no longer than, say 0.1 seconds to be reached since last time was reached, see if time left is more or less than your stablished limit time for that move number and if is less just stop and use as best move the best move from previous depth.
I mean, you must start with depth = 1, found best move for that depth. If time is more than limit time, then start analyzing depth 2 (with breaks for time tester each time reaches some point into the program) and so on till your find best move for depth 2 and so on.
I´m wrong? At least this is the way I did with Soberango.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 15, 2018 22:44

I understand what you say. I will study again the question.
BasicCoder2
Posts: 3344
Joined: Jan 01, 2009 7:03

Re: Mosquito (UCI chess engine)

Postby BasicCoder2 » Apr 16, 2018 0:51

Roland Chastain wrote: I should replace recursion by iteration, but it isn't easy to do.

I used four nested for/next loops i,j,k,l before I got my head around using recursion.

Code: Select all

sub computerMove()
    dim as integer score
    'dim as integer bestScore
    dim as string  bestMove
    dim as chessMove cMove
    score = 0
'    bestScore = 0
    bestMove = ""
    dim as integer x1,y1,x2,y2,x,y
    dim as integer valid  'flag valid move selected
    dim as integer r
    valid = -1

    score = 0

    bestMove = ""
   
    'create list of all possible moves for player
    createValidMoveList(player,vMove1(),vCount1) 'hold valid moves for player for current board state

    'for each legal move test if results in check condition?
    dim as integer i
    i = 0
    while i <= vCount1-1
       
        makeMove(chessMoveToString(vMove1(i)))
       
        createValidMoveList(-player,vMove2(),vCount2) 'get opponents responses
        vMove1(i).v = 0 'reset from any other opponent moves
        for j as integer = 0 to vCount2-1 'for each opponent response
            if vMove2(j).t2 = sgn(player)*6 then
                vMove1(i).v = -9  'mark invalid this legal move
            end if
        next j

        undoMove()
       
        if vMove1(i).v = -9 then

            'erase move from valid move list
            for k as integer = i to vCount1-1
                vMove1(k) = vMove1(k+1)
            next k
           
            vCount1=vCount1-1
           
        else
            vMove1(i).v = computeBalance()
            i = i + 1
        end if
       
    wend
   
    'check if in checkmate (no moves left)
    if vCount1=0 then
        checkMate=1
    end if
   
    if checkMate = 1 and check = 0 then
        staleMate=1
    end if
   
     '************************    START OF NESTED FOR/NEXT LOOPS      ******************************
    'create list of all possible moves for player
    createValidMoveList(player,vMove1(),vCount1) 'hold valid moves for player for current board state
    max1 = -90000
    min1 = 90000
    for i as integer = 0 to vCount1-1
        makeMove(chessMoveToString(vMove1(i)))

        createValidMoveList(-player,vMove2(),vCount2) 'NOTE -player is OPPONENT
        max2 = -90000
        min2 = 90000
       
        for j as integer = 0 to vCount2-1
            makeMove(chessMoveToString(vMove2(j)))

            createValidMoveList(player,vMove3(),vCount3)
            max3 = -90000
            min3 = 90000
           
            for k as integer = 0 to vCount3-1
                makeMove(chessMoveToString(vMove3(k)))
               
                createValidMoveList(-player,vMove4(),vCount4)
                max4 = -90000
                min4 = 90000
               
                for l as integer = 0 to vCount4-1
                    makeMove(chessMoveToString(vMove4(l)))
                   
                    score = evaluate()* -player
                   
                    if score > max4 then max4 = score
                    if score < min4 then min4 = score

                    undoMove()
                next l

                score = max4                         'NOTE RETURNS MAX
                if score >= max3 then max3 = score
                if score < min3 then min3 = score               
                undoMove()
            next k
            score = min3                             'NOTE RETURNS MIN
            if score >= max2 then max2 = score
            if score < min2 then min2 = score
            undoMove()
        next j
        score = max2                                 'NOTE RETURNS MAX
        if score >= max1 then max1 = score
        if score < min1 then
            min1 = score
            bestMove = (chessMoveToString(vMove1(i)))
        end if
        undoMove()
    next i

' ***************************   END OF NESTED FOR/NEXT LOOPS  *****************************

    makeMove(bestMove)
    drawBoard()
    cMove = stringToChessMove(bestMove)

    'did this move put opponent in check?
    check = 0
    createValidMoveList(player,vMove1(),vCount1) 'get player's possible moves
    for j as integer = 0 to vCount1-1 'can any of them check the opponent King?
        if vMove1(j).t2 = sgn(-player)*6 then
            check = 1
        end if
    next j   
   
end sub


Luis Babboni
Posts: 300
Joined: Mar 15, 2015 12:41

Re: Mosquito (UCI chess engine)

Postby Luis Babboni » Apr 16, 2018 1:37

Sorry BasicCoder2, I just take a fast look at your code.
Why max 1 to 4, min 1 to 4?
Seems to me that it could look just 4 halfmoves ahead. I´m wrong?
BasicCoder2
Posts: 3344
Joined: Jan 01, 2009 7:03

Re: Mosquito (UCI chess engine)

Postby BasicCoder2 » Apr 16, 2018 1:53

@Luis Babboni
Probably. I haven't looked at the code for some years now.
It was just to show how I used nested for/next loops.
My last version used a recursive negamax routine with alpha beta pruning.
I didn't want to mess up the thread's topic as my interest in the topic those many years ago were different to Roland's interests.
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: Mosquito (UCI chess engine)

Postby Roland Chastain » Apr 16, 2018 6:34

@BasicCoder2

Thank you for your contribution.

@Luis

I watched the game (Round 16) where Mosquito played an illegal move. I believe it is because of the underpromotion of the white pawn to bishop. I have to fix that.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests