Sunday, June 23, 2013

Build a desktop online translator with Bing


Somebody on Codeacademy wanted a little help building a dictionary application for Windows 8. As a matter of fact, online dictionary/translator function in similar ways. Since I already worked on such functionality, I thought I would try to do it again, let's go!

1. Check online translation services

Nowadays, all online translation services seem to require a key for API use. Since Google Translate became paid only, Bing seems the best free option at the moment.

2. How the BING Translator API works...

It's much more difficult now that appID no longer works.


  1. Wang Pidong's blog: How to use new Bing translator API.
  2. MSDN blog: Bing Translator API, getting started.
  3. MSDN Microsoft Translator: Obtaining an access token.
  4. MSDN documentation on the protocol: HTTP interface in C#
  5. Microsoft Bing Translator Language Codes and Names: [1][2].
Basically you want to copy the C# code from steps 3 & 4, to create classes and functions that will handle the http stuff and deserialisation (JSON and raw string) for you.

Since we're using the WPF template for the project, you will probably need to add references to:

  • System.Configuration
  • System.Runtime.Serialization
  • System.Net
  • System.Web

3. Verify the registration process

The registration process for the service is a bit painful. You must have something like this in your Azure Marketplace account for it to work : 

Windows Azure Marketplace data

Notice the two rows for both Bing Search API & Microsoft Translator.

4. Build a WPF interface

If we want to get fancy we can create to ComboBox controls databounds to the languages lists (checks links in section 2.5).
WPF interface

5. Implement custom configuration

Obviously, I can't give out my personal Bing keys. You will have to fill both the ClienID and the ClientSecret in exe.config.

Windows Azure Marketplace application registration


You will find the sample application at WPFOnlineTranslator. You can also download the source code on the code project. Have fun! =)

Retrieve contacts with Google Contacts API (Python)

I recently registered an account on codecademy. It was so fun that I completed all Python courses in one day! They also have a course for Python API which I also completed.

Codeacademy badges

As an experiment, I thought of trying to retrieve contacts using GMail API. It was really easy. Here are the steps and requirements:
  1. Python 2.7 installation
  2. Google Data Python Library installation (run install) from
  3. Download from Contacts API v3
  4. Create test account on GMail
  5. Run You will be prompted for username and password.

As a last step you wil want to customize the script to fit your needs. Have fun!

Friday, June 21, 2013

Grandia's initiative bar

The inspiration

For a game idea I had in mind for a very long time, I wanted to use the battle system of the Grandia series.
In the picture above you can see in the bottom right, what is called the IP Bar. Basically, there are 3 phases : WAIT, COM, ACT. Each character (player or computer):

  • enters the wait phase
  • selects a command from combo / critical / special move or magic / defend / evade / flee
  • performs the selected action
What is really beautiful about this system is that it's the best compromise between real-time anc turn-based game mechanics. All actions are performed live, but there is a stop to enter your command. This means you have time to plan your actions. But for what purpose ? Here are the cool things you can do:
  • Normal attacks (combo) results in a small knockback. Initiative is frozen until the character recovers from the hit. This also means that if attacked by many characters at once, not only the damage can add up, but the target is momentarily disabled.
  • Cancel an enemy's command by performing a critical attack during the buildup of its action phase.
  • Counter, if your critical lands as the target is in execution (end of action phase). Counters often results in knockdowns, which put the target on the ground. Nothing they can do until they get up!
Overall, I think the amount of control you have during the fight (if you play it smart), makes any battle really fun. The developers also did something for lazy dudes: you can define a combat strategy for the team, and just watch the AI do the job (handy versus weak enemies).

Additional information: Grandia II on IGN

The implementation

Using C# and WPF, i developed an animated initiative bar control.

Wednesday, June 19, 2013

Mastermind in C#

I thought, as a small project, it would be interesting to implement this game. I always had a lot of fun playing it as a child. It took only one day of development, for the first post on this blog. Enjoy!

Informations about the game : Mastermind (board game)
Compiled binaries (Windows, .NET Framework) :

Ideas to make it more fun or challenging :
  • High scores (based on timer and number of tries)
  • Multi-player mode (with tournaments)
  • AI personalities
  • Tutorial
Exploration: this is a game of imperfect information. I already wrote a chess AI. I don't know yet what it would be like to create one to break the code as fast as possible. But it could be fun, I'll try later!