Saturday, October 29, 2011

Hosting chess games in your blog posts

Finally I have found the chess game viewer I wanted in order to publish my own PGN games in the blog! The name is Chess Tempo PGN Viewer and it is well written, fast, supports annotations and variations and is very configurable. Most of all, it is all Javascript (sorry for the occasional Java prompts. I almost caved in and did what I swore I wouldn't ever do: have Java applets in my blog).

Please tell me if you have issues with the new chess viewer.

The Stonewall attack chess opening

Luckily for me, some chess videos are for beginners like me. Here is one from OnlineChessLessons, describing a simple, clear opening called The Stonewall Attack. After watching the video I played a game with my trusted Nokia phone and managed to create a game starting with this opening. I then analysed it using chess engines Houdini and Rybka and annotated it manually. Check it out, including the variations.

Video first:

Make sure you also follow the article attached to the video.

And now my game:
[Event "29/10/2011 1:08:49 pm"]
[Date "29/10/2011"]
[White "Siderite"]
[Black "Nokia Easy5"]
[Result "1-0"]
[ECO "D05"]
[Opening "Colle"]
[Variation "5.c3 Nc6 6.Nbd2 Bd6 7.O-O O-O"]
[TimeControl "600"]
[Termination "normal"]
[PlyCount "59"]
[WhiteType "human"]
[BlackType "computer"]

1.d4 e6 2.e3 d5 3.Bd3 Bd6 4.f4 Nf6 5.Nd2 O-O 6.Ngf3 c5 7.c3 Nc6 8.O-O c4 9.Bc2 Ng4
{At this point, the engines suggest Bxh7, a classic sacrifice.}
{However, I moved the queen to defend e3.}
( 10.Bxh7+ Kxh7 11.Ng5+ Kg8 12.Qxg4
{This variation wins the h7 pawn, but moves away from the spirit of the original game.}
12...Qf6 13.e4 ) 10...f5
{At this point, engines suggest Ne5, followed by knight exchange from black.}
{I chose to shoo the knight away, but weakening g3, where the knight would love to come later.}
( 11.Ne5 Ngxe5 12.dxe5 Be7 13.b4 ) 11...Nf6 12.Ne5 Qa5 13.g4 fxg4 14.hxg4 Qb6
{engines would want me to attack the knight on f6 before moving the rook out.}
15.Rf2 ( 15.g5 Bxe5 16.dxe5 Ne8 17.Kg2 g6 18.b3
{Engines decide to try a queen side attack as well, in order to weaken the black pawn chain. I was not interested in that.}
) 15...h6
{engines suggest attacking the rook and with Ng6, which is a natural attacking move and a lovely outpost.}
16.Rh2 ( 16.Ng6 Rf7 17.g5 Nh7 18.Qh5 Ne7 19.Nxe7+ Rxe7 20.gxh6 Nf8 21.Rg2 Qc7 22.Qg5
{However at this point the game moves into queen side attacks and a slower attacking pace.}
) 16...Ne7 17.g5 hxg5 18.fxg5 Bxe5 19.dxe5 Nd7
{engines suggest now a beautiful move: Rh8, followed by a munching of black pieces or/and mate. Make sure you check out the variation.}
20.Nf3 ( 20.Rh8+ Kf7 ( 20...Kxh8
{Taking the rook leads to a quick mate.}
21.Qh5+ Kg8 22.Bh7+ Kh8 23.Bg6+ Kg8 24.Qh7# ) 21.Qh5+ g6 22.Bxg6+ Nxg6 23.Qh7+ Ke8 24.Qxg6+ Kd8 25.Rxf8+ Nxf8 26.Qf6+ Ke8 27.Nf3
{Try this variation on a chess engine to see it to the end. White is only one pawn up, but it is a passed one. The king is safe as well.}
) 20...Rb8 21.g6 Nf5 22.Rh3 Nh6 23.Kh1
{I felt like the pin on e3 was annoying and stopping me from using the black bishop. The engines recommend moving Qh2 instead, which is much better.}
( 23.Qh2 Nc5 24.Ng5 Ne4 25.Bxe4 dxe4 26.Nh7 Qc7 ( 26...Rd8
{If you wanted to know why black did not move the rook when attacked by the knight, follow this variation through.}
27.Rxh6 Rd1+ 28.Kg2 Qd8 29.Nf6+ Kf8 30.Rh8+ Ke7 31.Qh4 Rd2+ 32.Bxd2 b6 33.a4 Qxd2+ 34.Kh1 Qe1+ 35.Rxe1 Bb7 36.Rxb8 Bc8 37.Rxc8
gxf6 38.Qh7# ) 27.Nxf8 Qd8 28.Rxh6 Qg5+ 29.Kf2 Qxh6 30.Qxh6 gxh6 31.Nh7
{At this point white is a knight up, but what a boring continuation.}
) 23...Nf5 24.Qh2 Ng3+
{Engines suggest I move the king and concentrating on the attack, but I took the knight with the rook.}
25.Rxg3 ( 25.Kg1 Qxe3+ 26.Bxe3 Ne2+ 27.Kg2 Nf4+ 28.Bxf4 Rf5 29.Rh8# ) 25...Re8 26.Qh7+ Kf8 27.e4
{At this point, a mate in 8 is found.}
{But with this move, mate will happen in 4.}
28.Bg5 Nf6 29.exf6 Rd8 30.Qh8# 1-0


P.S. I am currently looking for a method of displaying the game as I want it on the blog: dynamic, with annotation and variation support, preferably something that is not Java and optimally something that reads the PGN from a span and replaces it with a nice looking chess interface. Right now, the usual game engine fails for some reason I need to analyse.

Friday, October 28, 2011

Optimizing Visual Studio solutions and projects or how good intentions can pave a lot of road

I've had a horrible week. It all started with a good Scrum sprint (or so I thought) followed by a period of quiet in which I could concentrate on my own ideas. And one of my ideas was to optimize the structure of the solution we work on, containing 48 projects, in order to save space and compilation time. In my eyes, I was a hero, considering that for a company with tens to hundreds of devs, even a one second increase in speed would be important. So, I set up doing that.

Of course, the sprint was not as good as I had imagined. A single stored procedure led to not less than four bugs in production, with me being to blame for them all. People lost more time working on reproducing the bugs, deploying the fix, code reviewing, etc. At long last I thought I was done with it and I could show everyone how great the solution looked now (on my computer) and atone for my sins.

So from a solution that spanned from 700Mb clean and 4Gb after compilation, I managed to get it to a maximum of 1.4Gb. In fact, it was so small I could put it all in a Ram disk, leading to enormous speeds. In comparison, a normal drive goes to about 30MB per second, an SSD drive (without encryption) goes to about 250MB/s, while my RamDisk was running at a whooping 3.6GB/s. That sped up the compilation and parsing of files. Moreover, I had discovered that MsBuild has this /m parameter that makes it use more processors. A compilation would go to about 40 seconds, down from two minutes and a half. Great! Alas, it was not to be so easy.

First of all, the steps I was considering were simple:
  • Take all projects and make them have a single output folder. That would decrease the size of the solution since there would be no copies of the .dll files, Then the sheer speed of the compilation would have to increase, since there would be less copying and less compilation.
  • More importantly, I was considering making a symlink to a RAM drive and using it instead of the destination folder.
  • Another step I was considering was making all references to the dll files in the output folder, not to the projects, allowing for projects to be opened independently.

At first I was amazed the solution decreased in size so much and I just placed the entirety of it into a RAM drive. This fixed some of the issues with Visual Studio, because when I was selecting a file through a symlink to add as a reference, it would resolve to the target folder instead of the name of the symlink. And it was't easy either. Imagine removing all project references and replacing them with dll references for 48 projects. It took forever.

Finally I had the glorious compilation. Speed, power, size, no warnings either (since I also worked on that) and a few bug fixes thrown in there for good measure. I was a god! Then the problems appeared.

Problem 1: I had finished the previous sprint with a buggy stored procedure committed to production. Clients were losing money and complaining. That put a serious dent in my pride, especially since there were multiple problems coming from both less attention to how I wrote the code to downright lack of knowledge of the flow of the application. For the last part I am not really the only one to blame, but it was my responsibility.

Problem 2: The application was throwing some errors about the target framework of a dll. It was enough to make me understand a major flaw in my design: there were .Net 3.5 and .Net 4.0 assemblies in the solution and placing them all in the same output folder would break some build scripts. Even worse, the 8 web projects in the solution needed to have their output in the bin folder, so that IIS would find them. Fixed it only to see the size of the solution rise back to 3Gb.

Problem 3: Visual Studio would not be so smart as to understand that if a project is loaded, going to the declaration of a member in the compiled assembly means I want to see the actual source, not the IL code. Well, sometime it worked, but sometimes it didn't. As a result I restored the project references instead of the assembly references.

Problem 4: the MsBuild /m flag would do wonders on my machine, but it would not do much on the build server. Nor would it do its magic on slower, less multiprocessor computers than my own.

Problem 5: Facing a flood of problems coming from me, my colleagues lost faith and decided to not even try the modifications that removed the compilation warnings from the solution.

Conclusion: The build went marginally faster, but not enough to justify a whole week of work on it. The size decreased by 25%, making it feasible to put it all in a RAM Drive, so that was great, to the detriment of working memory. I still have to see if that is a good or a bad thing. The multiprocessor hacks didn't do much, the warnings are still there and even some of my bug fixes were problematic because someone else also worked on them and didn't tell anyone. All in a week's work.

Things I have learned from all this: Baby steps. When I feel enthusiasm, I must take it as a sign of trouble. I must be dispassionate as an ice cube and think things through. If I am working on a branch, integrate the trunk into it every day, so as to not make it harder to do at the end. When doing something, do it from start to finish, no matter what horrors I see while doing it. Move away from Sodom and not look back at it. Someone else will fix that, maybe, you just do your task well. When finishing something, commit it into the source control so it can easily be reverted through a single atomic operation.

It is difficult to me to adjust to something that involves this amount of planning and focus. I feel as if the chaotic development years of my youth were somewhat better, even if at the time I felt that it was stupid and focus and planning was needed. As a good Romanian, I am neurotic enough to see the worst side of everything, master at complaining about it, but incapable of actually doing something. Yeah... this was a bad week.

Saturday, October 22, 2011

Two interesting news and no news

No news from my personal or work fields. However, I've found two interesting news just today and I wanted to share them.

First, the development of a camera to capture pictures that you can focus later. Although I have heard of solid metal lenses that would be less than 1$ to make and would achieve the same effect, the only actually functioning system I've heard of so far is the Lytro Living Picture camera. Here is an Ars Technica article on it and here is a YouTube video demo.

The second news is more IT related. It involves the cryptographic standards for XML, as defined by W3C. They failed! Here is an article about how they were cracked by using a vulnerability in the Cipher Block Chaining and here is a link to their press release.

Monday, October 17, 2011

How Life Imitates Chess, by Garry Kasparov

Book cover
The complete title of the book is How Life Imitates Chess: Making the Right Moves, from the Board to the Boardroom, which is a mouthful, but very precise. It does explain how principles of chess, economics and politics apply in all three fields and how Garry Kasparov has evolved from chess player to world champion and, nowadays, into a political anti-Putin figure.

If you ask me, abandoning chess to get into business and worse, politics, it's a complete loss. However I do understand the guy, he got bored. Someday I may abandon computer programming.

Back to the book, though, it felt a lot like The Art of Learning, also written by a brilliant chess player (who incidentally also abandoned chess... hmm). It was more precise, most logical, though, looking at things from a more of a clinical perspective. I would have wanted to learn more about Kasparov's relationship with Karpov, for example, since he is always calling him his nemesis, but never says anything about how he felt about the guy.

This book is peppered with good advice, historic comparisons and great quotes from chess players and great men. Also, short descriptions of the relationship between famous "chess pairs" are giving the book an extra chess dimension. All in all I recommend it highly, although it felt more like a useful reference than a soul book like The Art of Learning.

Friday, October 14, 2011

TV Series I've Been Watching - Part 10

I really wanted to wait a little longer before writing this post, but the shere number of series that appeared forced my hand. So here it goes:

  • Doctor Who - As I was saying before, the show is slightly darker now, with the Doctor dying and River Song being somehow involved... It's kind of fun. The new actor, Math Smith, has matured in the show and exudes more confidence on the set.

  • Torchwood - Continuing the format of the third "season", that of a continuous miniseries, season 4 explores dark cabals that manipulate the world and use a device to make everyone immortal. Fascist like camps for people who would normally be dead are created, complete with crematoria. Some interesting ideas there, but the acting and scripting were pretty poor.

  • The Sarah Jane Adventures - I was surprised to see that the new season of Sarah Jane Smith started with Elisabeth Sladen still in the lead role. As you may know, the actress succumbed to cancer, so these are previously filmed episodes. Sarah Jane adopted new alien child, a girl this time, and she has the curious ability to grow spontaneously. Maybe she will become the next Sarah Jane? The show is pretty nice and doesn't seem so childish anymore. It is almost on par with its progenitor show, Doctor Who

  • Eureka - It continues to be brainless fun, a show basically held together by the lead actor, Colin Ferguson. As a funny side note, The Guild's very own (and smoking hot) Felicia Day together with show colleague (and Wesley Crusher from Star Trek) Wil Wheaton. They both act like their Guild characters, too :)

  • House MD - The eight season gets rid of useless Cuddy and gains a small Asian girl prodigy who stands up to House and gains his respect. We know she is going to leave dejected and heartbroken, as all the others did, but at least she's a change from the stuck up bimbo role that usually filled the gap. She is not smoking hot, though, and that is an issue that needs resolving!

  • Criminal Minds - I couldn't get myself to watch any of the episodes in season 7. It is basically the lack of time that is the cause. I will get to it eventually.

  • Dexter - The show is back on track with the usual Dexter, lovable and deadly. As opposed to the fourth book in the series, this season seems to explore religious cultism rather than cannibalism. Works for me. BSG's Edward James Olmos is the bad guy here, joined by Colin Hanks, as his acolyte.

  • Fringe - Peter Bishop has healed the wound between the two universes, but erased himself from existence in the process. Or has he? His father and Olivia keep getting glimpses of him. Same old show, in rest. The weird experimentation at the end of the last season seems to have ended. I don't know if that is good or bad.

  • True Blood - In the end it was still satisfying to watch. Not great, but certainly entertaining. Tara (finally) dies, as well as the annoying werewolf bitch, the pathetic old witch and the ridiculous gay nurse guy. A culling of all obnoxious characters can be good.

  • Men of a Certain Age - I keep nagging the wife to keep watching the show, as we started watching it together, but she keeps delaying. She doesn't want me to watch it alone either. Girls!

  • Weeds - After 7 years, the hot MILF Mary-Louise Parker is still hot! Anything else about the show kind of sucks, though. Same old convoluted plots that somehow revolve around marijuana, but have ceased being about the light drug for quite some time. I am still watching it because of the MILF factor, naturally.

  • The Good Wife - As Aron Nimzowitsch used to say, the threat is stronger than the execution. The fact that Alicia is finally banging Will removes the thrill of the sexual tension between them. The personal issues of the characters also begin to take a larger role than actual court cases. That is not good. The show is still entertaining, but has lost some of its appeal (pun not intended)

  • Haven - still silly, but now has gotten more confrontational, with "troubled" being discriminated against by normal people. Also we learn that Audrey is not really Audrey, nor is she the woman that looked like her and was in the town a few decades ago. Instead, it seems she appears whenever the troubles start and she always has the memories of someone else.

  • Royal Pains - I haven't watched it and I don't miss it. The wife doesn't seem to consider it either. It's personally cancelled.

  • Lost Girl - A new Ash has been chosen, one that is less lenient than the one before and who is quite annoying. There is a sort of cold war between him and our lovely succubus. An old girlfriend of Dyson also appears. Wrraawr! (or is it Growl! ?) The show is fun enough.

  • Nikita - The second season has started with gorgeous Amanda now heading Division. Except the ridiculously good looking actors, the show's got nothing for me anymore. I am discontinuing it from my show list.

  • Falling Skies - Still waiting for season 2.

  • Southpark - I've just watched the third episode from season 15. It is the only one that was funny from the season. I hope this is the beginning of a trend.

  • The Killing - Still on my watch list, didn't get around to it.

  • Mortal Kombat Legacy - The web show stopped at episode 9, just when it was getting interesting. Oh, well...

  • Suits - The very light courtroom male show is still fun to watch, although it has become sort of repetitive. The betrayed friend that turns on the main character is both exaggerated and an obvious season end cliff hanger.

  • Camelot - Claire Forlani and Eva Green, free boobs or not, are not enough to make me watch this series. Sorry, girls!

  • Wilfred - Unwatched episodes are rotting in my view list and I could not force myself to watch them. I guess this is another show I will stop watching.
  • Breaking Bad - A full season is waiting for me to watch. Whenever I had the time, I didn't have the mood to watch it. Maybe it is still fun, but I don't know yet. I fear disappointment.

  • Californication - Waiting for the next season.

And now for new shows:

  • King - Beautiful police woman... bla bla bla. I can google the actress and drool at her pictures instead of watching this average police drama. Not a new show, because I mentioned it in the last post, but it is part of a larger group of "do not want"s

  • The Protector - Blonde police woman protects the city. Yeah, right.

  • Against the Wall - Blonde police woman takes a job in Internal Affairs, much to the dismay of her policeman father and policemen three brothers, who feel she switched sides. Some funny situations and an interesting concept kept me watching this for a few episodes, but that's about it.

  • Prime Suspect - Blonde police woman fights to gain acceptance in a misogynistic crime unit. The cases are brutal, so is her mistreatment from her colleagues. That would make for an interesting premise if it weren't for my lack of time and ... because she is a police woman! And like it or not, this is no misogynism, either. There are just too many shows about that at a time when I've had it up to my ears of police dramas.

  • Unforgettable - Redhead ex police woman (and smoking hot, too), can't forget anything she sees. She teams up with ex boyfriend to... solve police cases. Yes, he is a cop. If not for the lead actress, a completely forgettable show.

  • Ringer - Sarah Michelle Geller is NOT a police woman. I like that. Instead she is a police witness that runs away from testifying and/or getting killed by a drug kingpin. Her solution is to take the role of her twin sister who mysteriously commits suicide. She finds herself married to a gold digging con artist, having a interior decorator best friend, having an affair with the husband of her best friend and so on and so on. I didn't buy it. Sorry.

  • Suburgatory - The short plotline sounded interesting: a single dad moves into the suburbs with urban, mischievous teenage daughter. The execution, though, was ridiculous. One of those obvious shows that spoon feed you anything you need to think or enjoy. Pass!

  • How to be a Gentleman - Drama from Entourage was one of the lead actors. Unfortunately for him, the show got cancelled almost immediately. It was also one of those background "ha ha" things. Awful!

  • Beavis&Butthead - Yes! My childhood show is coming back. I don't know when, but when it will start it will either be disappointing or epic. I am betting on epic.

  • American Horror Story - Interesting TV series remake of The Shining. I didn't really enjoy the film and I don't like how King writes his books. I tried to watch the first episode, but stopped in the middle. Not my type of show. Also, the "horror" is one forced by sound effects and obvious film tricks. I hated it.

  • Homeland - Haven't started to watch it yet, but it sounds promising.

  • Hung - Season 2 started, but I couldn't get myself to watch it. I guess I won't watch it.

  • Lie to Me - A lot of people recommended this show. I finally started to watch it. The insights in human behaviour are very interesting, especially since they are showing pictures or videos of celebrities in similar situations to the fictive situations in the episodes. There is much to learn there. However the structure of the show is a combination of CSI and House. All too fast, trying to seem intelligent and smart, but creating a soulless mechanical feel. I will be watching it occasionally for the science alone.

  • Terra Nova - Finally a sci-fi show! Humanity has botched the future, so they come back into the past, during the age of the dinosaurs. The main character is a cop. WHY?!?! OH, WHY?!?! The show is ok, but full of clich├ęs and the idea of a father of three fending off for his family in a colony of humans in the Cretaceous... brrrr, who the hell thought that up? The science is nil and the family issues override any decent sci-fi in the show. Too bad. I will watch it, still, but only because of lack of alternatives.

  • The Fades - By a long shot, this is the best of the new shows. It is a British horror series involving dead people trying to get back to life by eating living flesh. They are not zombies, they are Fades, and they make a lot more sense than other undead concepts. The main character is a clueless kid who happens to have special powers. Watch this, it is very nice, indeed.

  • The Field of Blood - Well, it appears as a series, but for now it was a two parter film. A heavy Glasgow accent makes this hard to watch with no translation, but a nice film anyways. A sort of journalist drama in the 80's, with crimes and family issues and rampant religious ideology.

  • The Secret Circle - A tv series remake of The Craft, as far as I see, with good looking teens being... witches! At least they are not vampires. The out of control member of the circle doesn't come even close to the beautiful craziness of Fairuza Balk. Baby, I still love you! Btw, the show is not worth watching, better rewatch The Craft a few times.

  • Hidden - Not watching it yet, but it is on my list


  • Grimm - A fantasy series related to fairy tales. To my chagrin this is what Wikipedia says: The show has been described as "a cop drama—with a twist...a dark and fantastical project about a world in which characters inspired by Grimm's Fairy Tales exist". Cop drama? Really?!

  • Once Upon a Time - Another fairy tale series, with actresses from House and Big Love and whatever shows ended or from which people left.

  • Hell on Wheels - a Western tv series. Could that work? We'll have to see

I have been pruning away from the TV series I have been watching, in order to gain some control over my personal life. But whenever I do that, more TV shows appear. It's like I need a hot redhead police woman to investigate this serial murders of my time and bring the culprits down in a climactic ending. But with my luck, I will probably find myself in cliff hangers at the end of each season!

Tuesday, October 11, 2011

Optimal use of case insensitive Dictionary in .Net

A question arose at the office today: What is faster? Using a Dictionary<string,object> with a StringComparer.OrdinalCaseInsensitive constructor parameter or using a normal constructor call and using ToLower on the key before using it. The quick answer: using ToLower on the key.

The longer answer is that StringComparer.OrdinalCaseInsensitive implements IEqualityComparer<string> by using a native code function for GetHasCode(), which is very efficient. Unfortunately, it must use the case insensitive string comparison on both input key and stored keys, while calling ToLower on the keys before using them makes the comparison only once.