New Year's resolution: a chess engine written in BASH script

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 11:40 am
Location: Naperville, IL

Re: New Year's resolution: a chess engine written in BASH sc

Post by UncombedCoconut »

benstoker wrote:In the meantime, can you tell me where I can insert a loop counter (let node=node+1) to get a count of the nodes? I aint too smart and caint figer it out.
Sure. You can zero it in the go() function and increment it at the start of the score() function (before the "if (( DEPTH <= 0 )) || [ -n "$TRICK" ]" clause). I think the hard part is timing the search in pure bash (I think you have to parse the output of "times" before&after and do some math) so you can report the nps.
benstoker wrote:One other thing. This is not as useless as you imply. This is a pedagogical chess engine. In my view, it's the best one because it's so absolutely basic. Extra comments to explain what's going on would be the final selling point.
Thanks, but I disagree. There's too much code spent fighting the language; it obscures the tiny amount of code spent on chess. The search and eval also aren't orthogonal enough from the board rep. If I wanted to write a good intro engine, I'd use a rapid language (perl+moose, python, ruby) with basic square/board/move classes. Better yet, I'd see if somebody's done this already. :)
smcracraft
Posts: 737
Joined: Wed Mar 08, 2006 8:08 pm
Location: Orange County California
Full name: Stuart Cracraft

Re: New Year's resolution: a chess engine written in BASH sc

Post by smcracraft »

MattieShoes wrote:I wrote one in perl. I think nps was in 200 or 300. I eventually abandoned it because with the long capture sequences and whatnot, even a 1 ply search could take an absurd amount of time.
How many lines of code did you shorten it to?
smcracraft
Posts: 737
Joined: Wed Mar 08, 2006 8:08 pm
Location: Orange County California
Full name: Stuart Cracraft

Re: New Year's resolution: a chess engine written in BASH sc

Post by smcracraft »

bob wrote:
benstoker wrote:It's stoopid, I know. But, it's been done in Javascript. I would like to see an obviously very basic script that searches 3 or 4 ply, with simple piece value eval. A minimax and no alpha-beta, etc.

Anybody out there who could help?

The world is crying out for a BASH chess engine.
This is not a hard project, but it is a painful one. And it would be slow beyond belief, since bash is a true interpreter and it would continually pass over the script, parsing and executing as it searches. Slow is not strong enough to describe this. :)
Call it molasses.sh
Michel
Posts: 2272
Joined: Mon Sep 29, 2008 1:50 am

Re: New Year's resolution: a chess engine written in BASH sc

Post by Michel »

I have installed the fixed version.. I'll let it run a couple of days. The previous version was indeed making illegal moves from time to time. I wanted to report this but then you posted 0.2.
UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 11:40 am
Location: Naperville, IL

Re: New Year's resolution: a chess engine written in BASH sc

Post by UncombedCoconut »

Michel wrote:I have installed the fixed version.. I'll let it run a couple of days. The previous version was indeed making illegal moves from time to time. I wanted to report this but then you posted 0.2.
Thank you! Please let me know if you see the fixed version make an illegal move (or if you've seen illegal moves other than knight teleportation and double-pawn moves through the line of check).
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: New Year's resolution: a chess engine written in BASH sc

Post by Don »

UncombedCoconut wrote:
Michel wrote:I have installed the fixed version.. I'll let it run a couple of days. The previous version was indeed making illegal moves from time to time. I wanted to report this but then you posted 0.2.
Thank you! Please let me know if you see the fixed version make an illegal move (or if you've seen illegal moves other than knight teleportation and double-pawn moves through the line of check).
Now the question is how strong can you make a bash chess engine? It should be possible to look ahead at least a few ply - bash on a modern computer is still faster than a C program was in the 80's.
benstoker
Posts: 342
Joined: Tue Jan 19, 2010 2:05 am

Re: New Year's resolution: a chess engine written in BASH sc

Post by benstoker »

Don wrote:
UncombedCoconut wrote:
Michel wrote:I have installed the fixed version.. I'll let it run a couple of days. The previous version was indeed making illegal moves from time to time. I wanted to report this but then you posted 0.2.
Thank you! Please let me know if you see the fixed version make an illegal move (or if you've seen illegal moves other than knight teleportation and double-pawn moves through the line of check).
Now the question is how strong can you make a bash chess engine? It should be possible to look ahead at least a few ply - bash on a modern computer is still faster than a C program was in the 80's.
The race is on. I suggest you employ a "Cheat Mode" for the bash engine, whereby it pipes to Stockfish for a little advice and consultation. Obscure that part of the script, of course.
UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 11:40 am
Location: Naperville, IL

Re: New Year's resolution: a chess engine written in BASH sc

Post by UncombedCoconut »

Don wrote:Now the question is how strong can you make a bash chess engine? It should be possible to look ahead at least a few ply - bash on a modern computer is still faster than a C program was in the 80's.
ShouldntExist would fare better if the board rep was just replaced by a more sophisticated global structure (with piece lists, static score...) and a stack of undo information. With a faster movegen one could consider a qsearch; without it the script will never get stronger.

I like HGM's idea: the easiest path to a "strong" bash engine is probably porting micro-Max. Good luck modifying it afterward though; it won't look much like a shell script. :)
Michel
Posts: 2272
Joined: Mon Sep 29, 2008 1:50 am

Re: New Year's resolution: a chess engine written in BASH sc

Post by Michel »

Version 0.2 has played 108 games on FICS at 15+5 time controls. No more illegal moves have occured. So I guess it can be declared stable with some confidence...
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: New Year's resolution: a chess engine written in BASH sc

Post by Don »

MattieShoes wrote:I wrote one in perl. I think nps was in 200 or 300. I eventually abandoned it because with the long capture sequences and whatnot, even a 1 ply search could take an absurd amount of time.
I think a relatively strong engine could be written in perl or one of the high level languages such as python, ruby, tcl, lua, etc. Probably a better one could be done in lua because it's impressively fast for an interpreted language.

I think you would have to give up no more than about 700 ELO for such an engine in perl, if you put the same amount of work into it that you would a C program (which is out of the question for me :-)

I once wrote a scrabble program in perl using tk for the graphics. I did it to prove to someone that it could be done, we got into a friendly debate about whether perl was fast enough to produce a move doing a full board search in a reasonable amount of time. This was something like 10 years ago and my perl program could find the highest scoring play in seconds, something like 5-10 seconds on a LAPTOP that I had back then.

I still have the program and did a check and it now finds a move in some fraction of a second. The time it takes is still clearly perceptible, so it's something like 1/4 to a full second on my core 2 duo.

I could also put my own high level chess program out there - I have a full move generator in tcl - it's part of my autotester which plays games. So I could very quickly have a rudimentary chess program which performs an alpha/beta search with quies.

I might also have move generator logic for lua - I did build some lua based tools for chess which I don't use any longer. I don't remember if they contain a move generator.

So if someone could organize a tournament we could have the battle of the scripted language chess engines!