Code Character

Game on!

Vishnu Deepak
The Pragyan Blog
5 min readFeb 7, 2018

--

In an era where video games push the limits of creativity in storytelling, level design, graphical fidelity and team play, it is hard not to give in to the opportunity to get lost in a virtual world of magical forests and mythical creatures. What if, however, your knowledge of strategy and logical thinking could be put to test in an environment which rewards skill in coding as well?

This is where ‘Code Character’, a gaming event focused on pitching players against each other on the basis of pre-developed AI comes in. A part of the ‘Code It’ cluster of events for the techno-managerial festival organised by Pragyan, NIT Trichy, ‘Code Character’ combines coding and strategy gaming, reminiscent of the ever popular ‘Age of Empires’ franchise. After going through the inbuilt documentation and tutorials provided at the login page, we felt confident enough to open the dashboard and start creating what we hoped would be a highly competitive bot to challenge other players on the leaderboard with. The Code could be easily entered and edited in the editor window to the left and appropriate errors could be seen in the debug window to the bottom right. To the top right was the renderer window where the bot-on-bot action unfolded in all its beauty. One of the major advantages was that only basic knowledge of C++ was required to play. After playing around with the interface and experiencing exhilarating victories and several crushing defeats, we were left intrigued and had plenty of questions on our minds.

In an interview session with Venkatraman Srikanth and Arun Ramachandran, the lead developers for ‘Code Character’, we explored the story behind the game.

Q: What started this quest for adjoining coding and gaming?

A: Four years ago, Pragyan came up with ‘Code Character’, a 1v1 coding challenge aimed at competitive gamers. In its inaugural edition, players battled it out in a test of logical thinking and capability as they tried to manoeuvre a gopher through complex terrain by coding in a Javascript environment. In its third iteration in 2017, ‘Code Character’ featured three uniquely generated maps with several types of terrain, infantry and buildings. With the objective being based on capture-the-flag mechanics, the game achieved an unprecedented level of depth and provided a programming challenge the likes of which had never been seen before.

‘Code Character’ — 2017

Q: As intriguing as that sounds, we’re sure it must not have been an easy road. What were the challenges you faced in bringing ‘Code Character’ to life and what’s new and different from the previous edition?

A: Every novelty does face a challenge. One such unexpected challenge we saw was in the design of the mechanism by which each player’s turns were measured. Up until the 2017 edition, each player’s turn was timed. That is, each player was given a specified period within which their code had to run. This led to drastic differences in results depending on the computer the game was running on, due to one simple reason — all computers are not built equal. Different processors compile in different time periods. These differences in CPU power and architecture led to non-deterministic scoring. That is, even on the same computer, scores often differed. Many factors apart from the actual code determine the final running time; like other processes running on the machine, and caching.

To solve this problem, we, the development team came up with an ingenious solution (humour us a bit here) to this problem. The idea was to discard the very notion of timed play. Instead of time, the number of instructions executed by the player’s code at every turn was measured. Since machine code is dependent on hardware, the intermediate, cross-platform output of a compiler was used instead. An upper limit was then set on the number of instructions the player can execute per turn.

Thus, each turn of the player involved running the code that they have submitted and only allowing the server to run their code if it adhered to the set upper limit. If the computation of final return values (which are the commands the player gives to their troops) uses more instructions than the set upper limit, their AI is declared invalid and victory is awarded to the other player.

‘Code Character’ 2018 — Layout

A second hurdle faced by the designers was that as stimulating as the complexities and intricacies of the original game were, it was perhaps too complex and intricate. Having such a level of depth to the challenge introduced a steep learning curve which was not very inviting to the average coder, and the investment of time and energy required to be competitive at the game was not something which attracted a large audience. To alleviate the issue, the team decided on a new set of rules that were simple to learn, while at the same time resulted in a game that is deep and engaging.

Q: How does the new version work better?

A: For starters, while the initial version had different types of terrain, troops and buildings, the current version has been stripped down to its most essential elements and now, has only one kind of terrain, one kind of infantry, one kind of building and one kind of resource (money).

The game is one of territory acquiring, that is, building and upgrading towers with money to gain territory. The player with the most territory at the end of a thousand turns wins the game. It’s a simple idea, but it leaves a lot of room for strategic planning. Where and when to build your towers, when to upgrade them and how to micromanage your troops all through lines of code pose a very satisfying challenge.

Once a player has written some working code, they can head to the leaderboard and challenge anyone on it to a skirmish. The match is simulated on the server and you will be able to view your scores in a matter of seconds. A frame-by-frame reconstruction of the match can be played back in the renderer window, where contestants can speed up or slow down matches and zoom in and out to view the results of their troops engaging in pixelated warfare in its full glory.

‘Pixelated warfare in all its glory’

Q: Would you say this game really is for everyone?

A: Yes! Irrespective of whether you are a beginner or a hardcore coding enthusiast, you can take part. Anyone who knows a bit of C++ programming can write an effective and competitive AI.

With the conversation wrapped up, we got a clearer picture of what went on behind the scenes. Curious about the game? Head on over to https://code.pragyan.org, fire up the online code editor, hammer out a dozen lines of code and see your strategies come to life in the rendering window.

--

--