How to run the bash engine ShouldntExist on OSX and Windows

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
User avatar
JuLieN
Posts: 2947
Joined: Mon May 05, 2008 10:16 am
Location: Nantes (France)
Contact:

How to run the bash engine ShouldntExist on OSX and Windows

Post by JuLieN » Tue Feb 22, 2011 12:36 am

In order to run Justin Blanchard's ShouldntExist bash chess engine on my Mac, I had to solve a number of difficulties. So I thought I could summarize what I did in this thread in order for these efforts not to be lost. Then I helped Olivier Deville to run it on Windows, so I'll add a help section for Windows as well.


I- Running ShouldntExist on MacOSX

Some steps of this walkthrough will use Apple's development tool "Xcode" (don't worry, it will be all automatic and the only thing you'll have to do is to sit and drink a good cup of coffee). It comes free with your Mac, on MacOSX's installation DVD. If you didn't install it, you can download it by visiting Apple Developer (or just go find where your Installation DVD is ;) ).

[1] Recover the bash file
AFAIK, the most recent version is to be found on this page
Just click the "download" button on the page. The file you'll get won't be usable yet, because it will have windows-terminated end of lines char that will just generate errors under Unix systems. So open the file with a good text editor (like BBEdit or Editra), do a cmd-A to select all the text and a cmd-c to copy it all. Now close your editor and open Apple's simple "textedit" tool. Press cmd-v to paste the script in the newly created document, and save it with a ".sh" extension. (for the rest of this tutorial, and for readability, we'll consider you saved the engine under the name "se.sh").

[2] Make the bash file executable
Open the Terminal and navigate to your se.sh file. Then enter the following command:

Code: Select all

chmod +x se.sh
This command tells the OS that it is an executable file. Actually it's not, as it's a script, but you can trust the OS that it'll be smart enough to go use bash for you to run it.
To run an executable file under OSX (and any Unix system), you have to prefix it with "./". So now, enter this command :

Code: Select all

./se.sh
At first, everything will seem to go fine: the engine will give you its name, author and options. But if you try to play (using uci commands. If you don't know them, go read the UCI protocol at this address.) a game against it, it will soon complain for various reasons. Why is it so? Because Apple is quite conservative and the version of bash that comes with Snow Leopard is quite old yet (it's version 3.2.48, when Linux yet uses a 4.1.x version). SE needs a very recent version of the bash interpreter.

[3] Update bash
So we have to update the default bash. To do that, we will use MacPorts. Go download it by clicking this link, and install it.
Then enter the following command into the Terminal to get sure you have the latest version of MacPorts :

Code: Select all

sudo port selfupdate
Using MacPorts is quite complicated, but the good news is that a wonderful tool exists that will simplify everything by doing all the work automagically for you! Its name is Porticus. Go download it on this website, put it in your Application folder, and run it.
Now click on "all ports" on the left, only once: it's just to get it selected. Then enter "bash" in the top-right corner search box. Click once on "bash" in the results list, to select it, and then click the "install" button on top left iconbar. Don't select "universal" when asked for it, except if your Mac uses a PowerPC CPU.
That's it, now Porticus will go retrieve all the needed files, sources and dependencies for you and compile and install them in your Mac where needed. As it took about 10mn of verbosing and scratching on my Core i5 iMac I guess you'll have time to go get a good cup of coffee now.

[4] Make it the default shell
Now run the Terminal again, and go into "Terminal->Settings". Select the first Pannel, called "start" and, into the "Open shells with" select "command (full path)" (or whatever stands in your language, I did a raw translation of my french OSX).
You can then let it use the default path "/bin/bash", as MacPorts adds all its installed program to this path (actually they sit in opt/local/bin, but this path is added to the system's one).
Now close these preferences and type the following command in the terminal:

Code: Select all

sudo mv bash bash-3.2.48

(It will archive your default bash binary, in case you want to reverse back to it one day...).
That's it, we're done with the tricky parts! Now exit the Terminal (using the menu : Terminal->Quit Terminal, or you'll just close the program's window without leaving), and restart it.
If you run se.sh's script again, this time you should be able to play without trouble.

[5] Making it a bit more comfy
Typing UCI commands in a shell is not the most user friendly experience one can imagine (except of course if you're a Linux addict, but then "user experience" has a different meaning to you). The good news is that, for the system, this script is now considered to be a normal executable. So just go run your favorite UCI-Compatible interface and add this new "engine" into it. As for me, it runs flawlessly using Sigma Chess, while Jose reports a problem when SE wants to play its move... Have fun! :)


II- Running ShouldntExist on Windows

When attempting to run SE on Windows, we tried different bash interpreters with no success. The most well known, win-bash, is based on a much too old version of bash (1.14) and will definitely NOT run with SE. Another interpreter, Zsh is more up to date but doesn't seem to be bash-complient.

So we went for the mammoth: Cygwin. Cygwin is a kind of unix/Linux compatibility layer for Windows (for instance, using cygwin.dll, you can compile your posix programs for Windows without modifying them). It will install all the needed tools for you. Just go download it at this address, and install it. Please note that you shouldn't have any space into your windows logon in order to run cygwin without problems. If you do, go read this section of the online doc for solutions.

When you're done installing Cygwin, you can try it by navigating to the place you saved the SE.sh script (see point [1] in the Mac section above), using "cd .." to go down in the tree, "cd drawer" to go up, and "dir /" to list the files in the current drawer. Once you're in SE's drawer, just type the following command to run it:

Code: Select all

./SE.sh
If you did everything well, this should work like a charm, like it does for us.

Now, just like in our Mac's fifth point above, you'll probably want to run it as an engine inside a GUI. To do that, create a SE.bat file with the following command inside :

Code: Select all

c:\cygwin\bin\bash.exe -l C:\path\to\SE.sh
and add this .bat file as a normal engine inside your favorite UCI compliant interface. have fun!
"The only good bug is a dead bug." (Don Dailey)
Image [Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]

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

Re: How to run the bash engine ShouldntExist on OSX and Wind

Post by UncombedCoconut » Tue Feb 22, 2011 4:35 am

Thanks!! I didn't realize Macs had such an old version of Bash by default. If you don't like to replace system files, you can also edit the first line of the script: the OS uses the file named after the "#!" (in our case, /bin/bash) as the interpreter, so you can replace it with the location of your newly built Bash. I'll see if I can figure out the issue with Jose.

A note to anyone not familiar with this engine: it's interesting because its code is funny, and it proves that a shell script can play at all. I don't really expect non-programmers to enjoy it much, but I'd be happy to be proven wrong. :)

tmokonen
Posts: 993
Joined: Sun Mar 12, 2006 5:46 pm
Location: Vancouver

Re: How to run the bash engine ShouldntExist on OSX and Wind

Post by tmokonen » Tue Feb 22, 2011 9:51 am

Well, I had to update my Cygwin to the latest version. ShouldntExist didn't seem to work with bash version 3.2, but version 4.1 is ok.

Not exactly a barnburner, is it? :D It took seven minutes on my machine to respond to 1. e4 from the opening position. I got impatient, and modified the script to allow a minimum Root Depth of 1. But an interesting programming exercise, nevertheless.

Post Reply