Winter Challenge 2024 by Codingame

“It’s the season to be jolly …” a famous Christmas carol starts, and this year CodinGame.com brought us programmers a present in the form of their Winter Challenge 2024. Being a nerd and a game enthusiast, tackling these kinds of problems always brings out a smile on my face πŸ˜‰

The overall premise of the challenge is that you get a problem to solve programmatically, while competing against other people doing the same. The best your algorithm is, the higher you’ll rank. The competitors are divided into leagues, and as you move up the leagues the challenge becomes more complex. I’ve never considered myself an expert on these things, but nothing like a learning opportunity, so I went at it again this year.

So what the winter challenge 2024?

This year you’ll be playing the part of an organism, living on a game board. The goal is to outgrow a competing organism over 100 turns. You can grow new organs to an adjacent field. You consume proteins while growing, but can gain more by growing organs onto protein caches found on the board. If you grow more organs than you opponent, you win. Oh yeah, and the board changes between games.

Here’s an image of what the board looks like in league “Wood 3” after the first turn has elapsed.

Seems simple enough, so game on!

To bold grow where no one has grown before …

Having thought about how to become the biggest organism on the board, I divided the problem it into a set of sub problems. I want my organism to:

  1. Find the distance to all protein caches
  2. Pick the closest cache
  3. Calculate the shortest path to the protein cache
  4. Grow an organ on the shortest path
  5. End turn, by going back to 1.

I can treat the board as a Cartesian coordinate system and use a two dimensional table as the underlying data structure for each tile. So if this was just a flat board, calculating the distance would be fairly simple math. Unfortunately the world is full of obstacles, and unfortunately our tiny simulation of it is no exception. Someone decided to put up walls! Alas simple math will not get us there.

Back in my student years I came across something called graph theory. The short version is that we can see the board as a set of nodes (each tile). Nodes can be connected to one another by edges. In our case edges exist between two adjacent tiles, as we cannot grow diagonally. So going from one node to another is done by traveling along the edges. Having a wall represented in the graph would basically be a node with no edges connected to it, thereby preventing us from going there. Ok, this is all fine an dandy, but where does this get us you may ask. The good thing about entering into a know domain is that you get to use known ways of solving the problem. Enter graph solving algorithms πŸ˜€

The shortest path between two points

There are a number of suitable algorithms one can use, but I went for a simple approach – Djikstra’s algorithm. We wanted to know the distance to each protein cache, but Djikstra can give us the distance to each point on the board. And I foresee us needing at a later point…

My board representation would look something like this, with asterisks being walls, ‘X’ being root nodes and ‘A’ being protein caches.

* * * * * * * * * * * * * * * * * *
*                                 *
* X                               *
*         A                       *
* * * * * * * * * * * * * * * *   *
*                                 *
* X                               *
*         A                       *
* * * * * * * * * * * * * * * * * *

After having implemented the algorithm I could then run it to calculate the distance, giving me this.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 --
--  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 --
--  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 17 --
-- 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 --
-- 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 --
-- 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Sweet, now I just need to read the values in the table for each protein cache and pick the lowest value.

Backtracking isn’t so bad …

Djikstra’s algorithm has a really simple way of finding the shortest path. Beginning at the destination, check the distance to every connected node and pick the one with the lowest value and remember that. Repeat this for the node you just found until you reach a zero distance coordinate and voila all the nodes you remember forms the shortest path.

Time to grow

So from here I took the coordinates from the node with distance = 1 in the shortest path and grew an organ there. And with that I grew big enough to enter the next league πŸ™‚

“Terraforming Mars” – and why I think a board game like this is worth your time

Hello good people!

Recently I acquired a new board game dubbed Terraforming Mars. The game is developed by Jacob Fryxelius and published by Stronghold Games. It has a price tag of around 60 EUR / 45 USD on Amazon. The game has an impressive rating of 8.4 on BoardGameGeek.com.
The game can be played by 2 to 5 people. The box says a game should take 90 to 120 minutes, but in my experience it’s more like 2 to 3 hours (I’ve played 20+ games so far).

The objective and how the game is played
You and your fellow gamers will be assuming the role of big corporations working to … *queue suspense sound effects* … Terraform Mars *fanfare*. Not that surprising really, is it πŸ˜‰
You start out by having a set production for your corporation, some starting capital and a corporate feat, which may help you throughout the game to a greater or lesser extent.
The games is played in rounds (simulating generations in timespan), where you go through phases of producing resources, buying project options, spending money to built said project or from a set of standard projects. Players take turns performing one or two actions per turn. When everyone is done, the round ends and a new one begins. Each project can have a variety of effects, of which some raises one or more of the three global parameters (oxygen, water and tempetature). When all these parameters reach a set level each, the game ends.
During the course of the game you raise your Terraforming Rating, which ultimately serves as Victory Points. The player with the highest amount of victory points is the winner.
The game is composed of both cards and a board on which you play tiles, thus giving an additional way to interact with other players.
You can find the rules here; Terraforming Mars rules

Why I love it and what I think makes it great
Terraforming Mars has me hooked on a number of things, which is why I’ve played more than 20 games in the course of 4 weeks. First off it has a set of really interesting mechanics. I’ve found myself pondering over which projects and actions are the best, what the return on investment is on each, how I should sequence them and lastly what my opponents are doing. I’ve played 2-player games by far the most. Even here the actions taken by my opponent in these games are an important enough factor, that I could never successfully disregard this.

Another interesting thing is that the resources you produce over time enable you to complete more projects, making you produce even more resources over time. Thus building up resource production is the most important thing in the beginning of the game. But when the game end all these resources are worth nothing in terms of winning the game – only Victory Points is – which brings in a whole new aspects of when should you shift your focus from producing resources, to gaining Victory Points.

The setting of the game is great too. It’s really well executed with regards to mechanics and gives a great ambiance to the game as a whole. I’ve caught myself chuckling a few times, when I read the flavor text on a project card and seen how well the story on it supports what it actually does in terms of gameplay.

Complexity wise the game has a lot to offer. More than once I’ve found myself missing things, so if I had to say something negative it’s got to be that the game is best played when you’re not too tired, as it will affect your enjoyment, as misplays will happen more frequently.

Terraforming Mars does have an element of luck, but I’ve never felt that you couldn’t make skill count too. It balances a fine line between skill and chance, and it does it well.

Ending remarks
I see myself playing this game over and over, and are trying to find pockets of time during my week constantly.
Terraforming Mars has all the good elements that you could stuff in a box and I am happy to toss countless hours into managing my interstellar corporation for generations to come.

Kudos FryxGames.se on a job well done πŸ˜€

10,000 version 1.6 is up on Google Play

Hi,

The 10,000 app has recieved an update.
I’ve made some improvements to the User Interface, so that buttons will be easier to tell apart from the rest of the UI. There has also been made some modifications to the computer player, so that it will try and score more than you, if you’ve reached 10,000.

I hope you all enjoy it. Go check it out πŸ™‚

Best Regards
Lars Sonne