Archive for the ‘c++and c#’ Category

I made top ten for C++ Programming on Google!

Writing for About.com (see previous post) isn’t done just for love; they do pay and that depends upon how many people visit the site. Which means I have to write stuff that people want to read and also apply a bit of SEO magic to make sure it’s found for what people are actually searching for.

Well my C++ column (including C and C#) is now at #9 on the first page of google for c++ programming. Getting to #1 position will be a lot lot harder. In fact staying in the top ten won’t be that easy!

Now I just have to work out how to get something that people on Digg and Reddit want to read…

Rock, Scissors and Paper Contest

http://cplus.about.com Rock, Scissors and Paper Contest
My other hat is writing the About C, C++ and C# website for About.com– the New York Times owned website. I’m one of their 600 guides who write for them.

One of the interesting things I’ve been doing there is running the Rock, Scissors and Paper (RSP) contest– it’s free and open to anyone and new players can join anytime between now and Christmas. It’s not the easiest to let developers use all three languages to write bots to play RSP but I managed it.

Each week, every bot in the contest plays every other bot in a 100 hand match. All wins are totalled up and that determines the ranking.

What I did was develop a C# Winforms application that uses a dll for each bot. I’ve done the hard bit and provided a full skeleton dll for C, C++ and C# that anyone can download and flesh out; just fill in the function bodies, the move logic goes in the GetMove() function. I wrote a C# wrapper for the C and C++ bots which wraps the dll calls in a class- it looks like this:

   public class bot
         {
      public const int botnum = 1;
      const string dll = “c:\ongoing\dlls\skeleton1.dll”;

      [DllImport(dll,
      CallingConvention = CallingConvention.Cdecl)]
      public static extern string GetBotName(); // returns name of your Bot

      [DllImport(dll,
      CallingConvention = CallingConvention.Cdecl,CharSet=CharSet.Ansi)]
      public static extern char
         GetMove([MarshalAs(UnmanagedType.LPStr)]String S,
         [MarshalAs(UnmanagedType.LPStr)]String S2); // return move

.. others trimmed for shortness
      }

Note the marshalling attributes – the dlls use cdecl, it’s ansi chars (8 bit as C# uses Unicode) and the strings are passed as lpstr. A string in C is just an array of 8 bit chars.

This function GetMove passes in the previous hands (in this match against one bot) so you can see what your bot played and what the opponent played. After each week I publish the results and a file containing all bots moves- eg this was the match between bot 1 and 5. 1 won 29 times, 5 won 33. Below this are the strings which I’ve trimmed to fit this.

1 v 5 29 33
1 SSSRSSSRSRRRSSRSRRRRRRRRR…..PPSPSRSS
5 PSSPRRSPSSPPRSPSSSPSSSSPP…..SSSRSSRP

You can see the full file this came from: Week 6 results It’s just a text file, generated by the application.

So if you fancy entering- remember it’s free just follow this link:
Rock, Scissors and Paper Contest

Google Dancing.. Music Stopped?

A Google Dance is the term for when Google updates all of it search centres. It can take a few days and during that time, search results, and Google Page Rank can go hither and thither.

One of my websites personality tests had had a Google Page Rank of 5 until a week or two ago when it vanished. At the same time, my C, C++ and C# topic had dropped from 7 to 6. I held my breath (best advice under such circumstances- figuratively I mean, not physically!) and lo and behold, they’re back today.