Tuesday 29 May 2012

Serial Experiments Lain

Lain, the main character of the anime Serial Experiments Lain is a strange little anime. It reminded me a bit of Dennou Coil, but the subject was more akin to the show Caprica, as it covers virtual worlds, disembodied conciousness, gods and the barriers between what is real and what is "Wired". It was also psychedelic as hell at times, full of fractured philosophical ideas that were presented in digital like flashes.

After all its 13 episodes, it is hard to say what I was left with. I enjoyed the show, but more because of its overall subject and weird presentation. I am sure I haven't understood half of what the creators were attempting to communicate. In a way, it is an abstract art anime, which might not appeal to some people and other people might like it for completely different reasons than intended, such as myself. I couldn't shake the feeling that this is what the Japanese would have done if they were making Caprica. How the characters see the connected world is interesting, as something almost occult, that can store human conciousness into protocols that are hardly well understood and that have evolved organically in time. The concepts of ego and self are also explored, when one has to ask: if I am both connected in a virtual world and have a body in the real world, where is "I" ?

All in all a pretty decent anime, something that lacked any attempt to make it artificially humorous. No highschool love stories, no weird lewd jokes, just the plain storyline. I liked it.

Saturday 26 May 2012

On Analysing Chess Games

In a previous post I've written about my thoughts on how to learn chess, with the main emphasis being on game analysis. But how that is done is a matter of time, taste and budget. This post is about how I do it. I don't know how other people are analysing chess games, except from hearing them talk about it, so I am not an authority in the matter, but it will save you some time figuring it out for yourself (which you still have to do even if you read the post :) ).

The easiest way of all is to get a game in PGN form, load it in a chess program, then watch it unfold, while you think about what you would have done differently and highlight what you thought was a good move and a bad move. Of course, that relies on your own thinking, which may be flawed, so you can gain help from a chess engine that will analyse the variations and tell you what it thinks of what you thought. It sounds complicated, but it is not. You ask yourself why the player didn't fork the queen and the rook with the knight, you can do it for them (creating what is called a variation). While you are moving the pieces, a chess engine can suggest, based on the time you let it analyse, what is the best move in that situation.

For this I use Arena Chess GUI, a free chess program, and load up the free chess engine versions of Houdini and Rybka. Arena comes with more engines, so you can try them all, but really it's a matter of taste. I once did a championship of chess with the chess engines available in order to see which is best, but there is no real way of giving both chess engines the same computer resources, so the programming style of each engine makes this only a fun comparison, not a scientific one. There are videos on YouTube with competitions of chess engines; those are fun in their own right. Unfortunately, Arena is not really bug free. There are a few gotchas that you learn the hard way, like don't use the Minimize to tray option if you have the default "load PGN at startup" on, or don't use "save back into PGN", etc.

Of course, most chess engines have a free version and a commercial one. Depending on your seriousness, you can choose to pay money for them and get the advantages of new development in chess computing, but don't expect too much. After all, a computer engine only takes a formula that gives a value for a position and then makes a tree of possible move orders in order to minimize their opponent's advantage and maximize theirs. The algorithm is pretty standard and the formula, which really makes the difference between engines, is the outcome of centuries of chess analysis. The game hasn't changed that much in a few years. And exactly this difference between how humans process a game and how a computer does it, makes this analysis a little flawed. A computer will tell you where you went wrong, but won't be able to devise a winning strategy for you, as it is examining every move like it would be the first. So we move to plan B.

Another option for analysing a game, thanks to the vast database of chess games ever played, is to see what other players, human grandmasters and below, have done in the same situation. A software that was built to do this is ChessBase. And it is true that there is a gazillion of possible chess games, but they all begin kind of the same. The opening principles restrict the way a game can start and for the first 20 or 30 moves, there are a lot of players that did the same thing (and played a decent game). ChessBase is a great program, just like Chess Arena, because it allows flexibility in the way you use it without bundling it all. The program is small to download, then you get to download whatever chess engines you want, game databases, video tutorials, etc. To give you an example of size difference: ChessBase 11 is 150MB, the chess player base is 640MB, a video tutorial of chess openings in ChessBase format is 1500MB, while the MegaDatabase of chess games is 2700MB. You can imagine that there are a lot of games in that database, over five million of them. Unfortunately, ChessBase, the databases and the tutorials are not legally free. They cost around 200 euros, plus a few more for the tutorials. Not much for the effort that was put into them.

The chess blog posts that I am using to publicize games are done by using these kinds of scenarios. I am taking a game that I played with someone or with my phone, I am analysing the game so see where changes in the score have occurred (those are the interesting bits in a game) and then try out variations, using engines or databases to see what else could have been done. It is a good practice to analyse the game as soon as possible, as the ideas that led to the moves are still fresh in your mind. It may seem like a drag, but commenting why you did the moves allows you to understand the game later on, when you are revisiting it. Also a good idea is to have your chess partner do the same thing and then merge the two PGNs into one, that makes clear the overall play. A chess analysis engine will comment every move with what it thought would have been the best continuation and the value of the board at that time. It makes a PGN horrible to read, because even if you put it into a visual display of the PGN, you still want to have a clean, readable PGN file. What you want to do is analyse a single move with the engine, see were it goes, then write a humanly understandable statement like "which would have been disastrous because of the sacrifice of the rook on f8, followed by Qxf7, mate".

As examples, try to compare the following blog post PGNs. My first chess game post, was annotated automatically by ChessMaster XI, which has a human readable annotation engine which I first thought was great. But look at the texts: they are either obvious or resort to stuff like "Leads to 15...Kf7 16.Bh4 h6 17.b4 Rab8 18.a4 Bxf3 19.Qxf3 Be7 20.Ng4 Bxh4 21.Nxe5+ Kg7 22.bxc5, which wins a bishopand two pawns for a bishop and a knight.". Unless used to read PGN like English (which most professional players can, btw, complete with a chess board in their heads), you see a lot of mambo jumbo. A later game post, that contained annotated moves by me, as translated from chess engine analysis.Or this one, which contains no annotations at all. Which one do you like best?

A word of warning, analysing chess games is not a short process. The advantages of the ChessMaster XI auto analysis was that you could leave it on at night, then come back in the morning and see it unfurl before you (and audio read by the chess software). To do it manually, or even let the auto analysis run at night and then decode the best move suggested by the computer and translate, takes a lot of time. I've spent an hour per game to annotate a match (two games) that two coworkers had and that I dutifully stored on my cell phone while they were playing. It was satisfying, but time wasting. A lot like blog posting... I leave you at that. Have fun dissecting chess games.

On Learning Chess

There is, of course, a long tried method of learning chess: find a bunch of people that want to play chess and go fight with them. Like that old Army line: join the Army, meet interesting people, kill them. But also obvious is that this is not the best method there is. You meet old men that play chess every day with other old men that have a lot of time on their hands and, even if they kick your ass rather quickly, you often find ways of defeating them because all their play is organic, lacking a principled structure. And that is what this post is about. I am the least principled player out there, as I have a ridiculously leaky memory and am rather greedy (I want fun games, now, not dirty principles), and therefore I get often beaten by people that should not have been able to defeat me. And, like in the old adventure games: So, you want to be a (principled) chess player - this is the quest.

First of all, don't google "how to learn chess" as you will get swamped by all the chess players that think they can teach you for money and all the software that you need to buy and all the DVDs that you absolutely need to buy. That doesn't mean that if you are patient you wouldn't eventually find what you need and, being a wannabe chess player, you should have a little patience. But if you are like me (why do I want to play chess again?) you don't have patience. Second of all, don't start with chess books. You can find zillions of them on the web, but in order to read them you will have to become very familiar with a chess board. Unlike a video, they will require to read the book with a chess board at hand and do the moves as you read. That pretty much means you can read them only in specific settings and you will feel like an idiot for reading a page a day. Books are great, but not for beginners.

Then there are some free online resources that one can use, lovely chess sites like JRobiChess.com, theChessWebsite or ChessVideos.tv, where one can get multiple opportunities to learn: grandmaster games, videos, tutorial, references. These are great, and I thoroughly recommend them. Also, look for "chess" on YouTube and you will find a plethora of people discussing and teaching chess, some of them completely for passion alone. On JRobi's site you can even find a chess study time recommendation: Opening Study – 10%, Tactical Puzzles - 20%, Endgame Study – 10%, Analyzing Your Games – 30%,Analyzing Master Games – 30% of Time. Let's analyse this plan a little bit and some very interesting ideas will emerge.

As you can see, there is time allotted for openings, only a tenth of the time, and the same amount of time for endgames. This leads to the first very important idea: endgames are (at least) just as important as openings. If you think about it, most of the amateur games, played for fun and not for some chess rating, are spectacularly inaccurate and end in quick mates. That means that most of the "go get'em" practice will teach you about openings and some of the middle game. Once in endgame territory, we are suddenly beginners again, trying to get by and failing miserably. That's why it is important to spend time with endgames. Josh Waitzkin, a US champion at chess, recommended learning endgames even more than openings. He described how, by careful study of just a few pieces on the board (two kings and a pawn, or some other piece, the usual endgame scenarios) he would emerge slightly disadvantaged in the endgame, then crush his opponent, less instructed in this most important part of a chess game. The opening and endgame learning is only a fifth of all learning time, though. Other things are even more important.

20% tactical puzzles. This is the equivalent of learning karate moves out of context. You are not fighting anybody, but you learn to hit them in a particular way. You don't have the pressure of a game, you have all the time in the world, find the best move! Both JRobi's site and Kevin's (theChessWebsite) have daily tactical puzzles. This is actually one of the few exercises that I do almost every work day: I open their sites and do those puzzles. But let me tell you something: if you open a chess book with tactical puzzles, you get some really nasty, mind boggling stuff. These online ones, at least the two I mentioned, are made for people that if they don't immediately see the answer, they start trying moves until they get them right. I should know; that hint button also gets heavy use. So this is one of the moments when I can recommend books, but start with the online ones first and try to see them through before moving.

Now comes the heavy part. We've covered a little more than a third of the time one should spend on chess learning, according to JRobi. The other two thirds are analysing games. That is it. Take the game out of the competition and clinically dissect it until you learn everything there is to learn. A major idea comes out of this, though: if you need to analyse your own games, that means someone must record them as you play. Professional and club games have score cards: they write every move they and their opponent make, the score, even small comments (you will see what I mean when we get to PGNs) and they sign each other's cards at the end of the game. I've never done it, but I imagine it is satisfying to get your adversary to sign their own defeat while you desecrate their own card with your victory scribble (heh!). I also imagine it adds to one's motivation, getting this kind of direct recognition of your effort in the game. Another option, much easily available, is to load a chess game on your mobile phone and set it to two player game. Once you make a move, you make it on the phone as well. At the end, you download the PGN file on your computer for later analysis. With a chess engine at hand and all the time in the world you can see where mistakes were made, where good moves changed the score balance and what was missed. A spectator of the game can do that for you, as well. I originally planned to write in this blog about analysing games, but it has become too long already. I will, therefore, detail that particular part in another blog post.

Of course, analysing the games played at grandmaster level shows how other people are thinking when playing the game. It's not unlike reading material relevant to your line of work. You may be smart, but you are not expecting to think of everything that may be of use to you in a specific context. You read what other wrote on the subject and gain inspiration. And when you see a giant chess player sacrifice a queen for two knights and then mating the other guy in another ten moves, you also gain humility (or you close the bloody game and go watch a movie or something). Indeed, try not to let it get to you. Grandmasters are not geniuses that can outthink you at every step, monsters that can intellectually squash you like a bug, they are people just like you that also dedicated their lives to the game of chess. Professional chess players do it for life. Expecting to understand what they did without a lot of effort is a stupid expectation. It is important to analyse their games and learn from both their mistakes and brilliant moves.

That leaves us with the endgame of this post: computer chess tutors. That is different from playing chess with your computer or pad or cell phone. That enters the first category of just playing. Computers also play differently than people, they are great at not making mistakes and punishing yours, but their design also allows for moves that would mate you in 235 moves or something like that, which is insane for any human being. Don't get me wrong, computers are great practice, but consider that if you beat them at a certain difficulty level, it is because they were programmed to let you. With the computing power available today, a cell phone would probably be able to beat Kasparov. So, back to chess tutors. I've only found one that I liked, and that is the ChessMaster XI game. Incidentally, there is where I've learned of Josh Waitzkin, as he is the voice and mind behind the game tutorials. I've also heard a lot of Fritz, but I haven't found a context where it really tutors you. Fritz is bundled with ChessBase and there are some tutorials with board, PGN games and video that use ChessBase to teach you stuff. There are probably some ChessBase based tutorials, but I haven't searched for them yet.

So, I leave you with this little research I've done, I hope it helps you get better and encourages me to heed my own advice.

Tuesday 22 May 2012

On RegexOptions.IgnoreCase performance

I found a bit of code today that tested if a bunch of strings were found in another. It used IndexOf for each of the strings and continued to search if not found. The code, a long list of ifs and elses, looked terrible. So I thought I would refactor it to use regular expressions. I created a big Regex object, using the "|" regular expression operator and I tested for speed.

( Actually, I took the code, encapsulated it into a method that then went into a new object, then created the automated unit tests for that object and only then I proceeded in writing new code. I am very smug because usually I don't do that :) )

After the tests said the new code was good, I created a new test to compare the increase in performance. It is always good to have a metric to justify the work you have been doing. So the old code worked in about 3 seconds. The new code took 10! I was flabbergasted. Not only that I couldn't understand how that could happen, how several scans of the same string could be faster than a single one, but I am the one that wrote the article that said IndexOf is slower than Regex search (at least it was so in the .Net 2.0 times and I could not replicate the results in .Net 4.0). It was like a slap in the face, really.

I proceeded to change the method, having now a way to determine increases in performance, until I finally figured out what was going on. The original code was first transforming the text into lowercase, then doing IndexOf. It was not even using IndexOf with StringComparison.OrdinalIgnoreCase which was, of course, a "pfff" moment for me. My new method was, of course, using RegexOptions.IgnoreCase. No way this option would slow things down. But it did!

You see, when you have a search of two strings, separated by the "|" regular expression operator, inside there is a tree of states that is created. Say you are searching for "abc|abd", it will search once for "a", then once for "b", then check the next character for "c" or "d". If any of these conditions fail, the match will fail. However, if you do a case ignorant match, for each character there will be at least two searches per letter. Even so, I expected only a doubling of the processing length, not the whooping five times decrease in speed!

So I did the humble thing: I transformed the string into lowercase, then did a normal regex match. And the whole thing went from 10 seconds to under 3. I am yet to understand why this happens, but be careful when using the case ignorant option in regular expressions in .Net.

Wednesday 16 May 2012

System.InvalidOperationException: Static types cannot be used as parameters or return types

A short post about an exception I've met today: System.InvalidOperationException: There was an error reflecting 'SomeClassName'. ---> System.InvalidOperationException: SomeStaticClassName cannot be serialized. Static types cannot be used as parameters or return types.

Obviously one cannot serialize a static class, but I wasn't trying to. There was an asmx service method returning an Enum, but the enum was nested in the static class. Something like this:
public static class Common {

public enum MyEnumeration {
Item1,
Item2
}

}

Therefore, take this as a warning. Even if the compilation does not fail when a class is set to static, it may fail at runtime due to nested classes.

Monday 7 May 2012

Gaprindashvili - Blagidze, Georgia 1963

I found this game on The Kenilworthian blog, a game between Nona Gaprindashvili and Alexander Blagidze. What fascinated me about this particular game is the position after 12... Nc6. Only twelve moves into the game, a position that seems normal, like something one would see when studying a particular opening, and then Bam! Can you see the bam? That is the challenge. Try to find it yourself.

I've analysed the game (very superficially) using Houdini and I've added two variations, just to see what would have happened in the more obvious situations. One question remains: what was really black's downfall? What was black's bad move and what could have been done instead of it? You can see it in the analysed PGN, but try to see it, it's a deceptively silent move.

[Event "USSR"]
[Site "USSR"]
[Date "1963.??.??"]
[Round "?"]
[White "Nona Gaprindashvili"]
[Black "Alexander Blagidze"]
[Result "1-0"]
[BlackElo "2400"]
[ECO "B23"]
[Opening "Sicilian"]
[Variation "Closed, 2...Nc6 3.Bb5 Nd4"]
[WhiteElo "2400"]
[TimeControl "600"]
[Termination "normal"]
[PlyCount "47"]
[WhiteType "human"]
[BlackType "human"]

1. e4 {(e7-e5) +0.10/16 20}
...c5 {(Ng1-f3 Nb8-c6 Nb1-c3 Ng8-f6 d2-d4 c5xd4 Nf3xd4 e7-e6 Bf1-e2 Bf8-b4 Nd4xc6 b7xc6 0-0 Qd8-a5 Qd1-d3 0-0 Bc1-e3 Bc8-b7 Be3-d4 e6-e5) -0.20/16 20}
2. Nc3 {(Nb8-c6 Ng1-f3 Ng8-f6 d2-d4 c5xd4 Nf3xd4 e7-e6 Bf1-e2 Bf8-b4 Nd4xc6 b7xc6 0-0 Qd8-a5 Qd1-d3 0-0 Bc1-e3 Bc8-b7 Ra1-d1 Bb4xc3 Qd3xc3 Qa5xc3 b2xc3 Nf6xe4 Rd1xd7 Ne4xc3) +0.22/17 20}
...Nc6 {(Ng1-f3 Ng8-f6 d2-d4 c5xd4 Nf3xd4 e7-e6 Bf1-e2 Bf8-b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) 0.00/18 20}
...Qe5 {(Rf7-f5 Qe5xf5 e4xf5 0-0 f5xe6 d7xe6 Qd1xh5 Bc8-d7 Qh5-g4 Ra8-e8 Bg5-h6 Re8-e7 Bh6xg7 Re7xg7 Bc4xe6+ Kg8-h8 Qg4-h3 Bd7xe6 Qh3xe6 Rg7-f7 Qe6-b3 Rf7-e7 Ra1-f1 Rf8xf1+ Kg1xf1 Kh8-g7 Qb3-d5 h7-h6 Kf1-f2 Re7-f7+ Kf2-g3) -4.44/16 20}
(14. .. Kxf7 15. Qxh5+ Kf8 16. Rf1+ Qf4 17. Rxf4+ Bf6 18. Rxf6+ Ke7 19. Rxe6+ Kf8 20. Re8+ Kg7 21. Qh6#)
15. Rf5
(15. Rf5 Qxf5 16. exf5 O-O 17. fxe6 dxe6 18. Qxh5 Bd7 19. Qg4 Rae8 20. Bh6 Re7 21. Bxg7 Rxg7 22. Bxe6+ Kh8 23. Qh3 Bxe6 24. Qxe6 )
1-0

Saturday 5 May 2012

World of Ptavvs, by Larry Niven

Book cover
World of Ptavvs is a book first published in 1966, therefore it feels very dated indeed. Still, while reading the book, I've realised how I missed the style of the sci-fi back then, when the world was grand, the future was brilliant, people would all be intelligent and rational, doing what is smart and what is right, with a power of will that defined their very being. Remember Asimov? It's like that! And it's no wonder, both Larry Niven and Isaac Asimov were technical people at their core, even if they have expanded their interests in many other spheres as well. I have to reiterate this: in this time of Generation Me, when everything seems to be focused on the intensity of one's emotions, rather than on what the situation at hand is and what to do about it, when legions of film makers and young adult writers pound this insane idea that what we feel is more important than what we think and our own belief is more important than the welfare of the people around us, in these horrible times books like World of Ptavvs feel like good medicine.

Not the the book was not ridiculous in many aspects. The fusion drives, the trips towards Pluto that took a few days, a "belter" civilisation populating the main asteroid belt and moving around in ships that were essentially huge fusion bombs, the way people with terrible burns and psychic trauma would calmly talk about their ordeal to the scientific investigator come to solve the problem, the idealistic discussions that spawned out of nowhere in moments of maximum tension, the intelligent civilisation of dolphins that dream to go to space, the psionic powers... all of these were at the same time wonderful to behold and quite silly. However, I liked the book, I gobbled it up.

The plot is about this alien that can control the minds of others. Their entire civilisation is based on enslaving other populations via their Power. He is the victim of a malfunction in space and activates a retarder field that will protect him from time and space interactions until someone removes him from this stasis. Thus, he reaches Earth and remains on the bottom of the ocean for billions of years. When people get him out of his shell, all hell breaks loose, the book transforming into a space race and a philosophical introspection at the same time.

I can't make justice to the subject in a few words any more than I can do it in more words without spoiling the pleasure of the read - I've already said too much. If you feel you are in the mood for old school sci-fi, World of Ptavvs is a good book, reminiscent of the works of Asimov or van Vogt. Silly, yet grandiose at the same time.

Wednesday 2 May 2012

HtmlAgilityPack incorrectly handles form tags

It's a horribly old bug, something that was reported on their page since 2007 and it in the issue list for HtmlAgilityPack since 2011. You want to parse a string as an HTML document and then get it back as a string from the DOM that the pack is generating. And it closes the form tag, like it has no children.
Example: <form></form> gets transformed into <form/></form>

The problem lies in the HtmlNode class of the HtmlAgilityPack project. It defines the form tag as empty in this line:
ElementsFlags.Add("form", HtmlElementFlag.CanOverlap | HtmlElementFlag.Empty);
One can download the sources and remove the Empty value in order to fix the problem or, if they do not want to change the sources of the pack, they have the option of using a workaround:
HtmlNode.ElementsFlags["form"]=HtmlElementFlag.CanOverlap;
Be careful, though, the ElementsFlags dictionary is a static property. This change will be applied on the entire application.