this is my next publication in which I would like to share one of my first experiences as a programmer.
I strongly believe the best method of learning something is simply to start doing it. Yep, it’s all about practice.
So, there was no better way for me to learn a new programming language than just start writing a project using this language. One of my first self-educational projects was YahooChessMaster – a chess bot that can play chess at Yahoo game portal.
I think, it was one of the first Yahoo bots at that time. I have written it using VC++ v.6.0 back in 2005.
YCM was identifying the open browser window with a chessboard inside and it was scanning the board visually pixel by pixel. Then YCM was passing the pieces position from the board to a local chess engine, using UCI protocol. The engine was making a move and returning its algebraic notation to YCM.
After that YCM was moving the corresponding piece on the board by transmitting mouse events to browser window. You may say: “Scanning the board is an overhead. Wouldn’t be much easier to emulate the network interactions: request/response?”
No it wouldn’t, turns out, to emulate the networking may not be that simple at all. First, the communication mays need to be ssl encrypted; then, it has to use some sort of custom protocol that would require tons of reverse engineering efforts.
In my method, I had managed to speed up the board scanning process by reducing the amount of pixels that need to be scanned. Thanks to the reach color pallet of the chess pieces representation, it was possible to identify a chess piece by getting only one single pixel from a single square. Thus, to read the entire game position was a matter of reading 64 single pixels only. YCM was able to do it many times per second.
Eventually, after all the Internet lags, plus pixels reading stuff, plus IPC interactions with engine and mouse events passing back to the browser, YCM was able to shoot 1 move per second, playing 1 minute blitz game. In addition to incredibly short move time, YCM playing strength was amazingly high. Behind the curtains YCM was using one of the strongest chess engines at this time called Spike – a winner of a first Computer World Championship in 2005. And Spike was free of charge.
Very quickly YCM became 2400 rated. It literally never lost any game. I have realized that I’ve created something really good and tried to sell it… During playtime YCM was posting spam-like messages in the rooms chat that were referring individuals who might be interested to my website where a limited demo version was available for free and fully-functional-commercial one for only $9.
Only one YCM copy was sold and later refunded. It turned out, YCM did not have an ability to comply with too many different versions of Windows at that time. Just to name few of them: XP Home, XP Professional, ME, 2000, 98, 95… I just had no time to support all of this “commercial” stuff, and eventually I abandoned the project. The website with the demo version was shut down. All this happened in 2005
Today there are couple of chess bots for Yahoo that are dramatically similar to my YCM. One of them is Chess Buddy.
Here is how it looks like:
And here is the screen shot from YCM:
So there is a chance that my ideas were adopted and are living till now. And I’m good with that.
Eventually I was involved in a talk about different ways of establishing a real time connection between browser and server. One of my colleagues just said: “I would use a GIF for that”, and I was like “whaat?”, and then he showed me this library: gifsockets. This is an implementation of Graphical Interchange Format protocol, known as GIF. It’s supposed to represent animation in browser, that consists of set of frames that are consistently changing each other. When downloading GIF animation, browser is doing this frame by frame and is holding the connection till receiving a special character from the server. Potentially, when there is no such special character sent, the browser might hold the connection opened forever. It’s also possible to convert plain text to a special format (RGB frame) and send it via a regular GIF protocol to a browser.
Back in 90’s, when there was no websockets, people were using this feature for establishing a real time communication between browser and server. Although this is clearly a big piece of hack – when something is used in a way it’s not supposed to – I think this is an amazing example of creativity in programming..