Skip to main content

Posts

Showing posts with the label Python

Criss Cross AI

Some weeks ago, to end an evening of board gaming, I was introduced to the Knizia roll and write called Criss Cross (or Détrak here in France). A fascinating two dimensional dice placement game with very simple rules. As we left my friends place we discussed that it should be feasible to implement a simple AI for the game. So, when I got home, I started the process… Part 1 Part 2

Benchmarking Dynamic Programming with Python

In this post I'll explore and benchmark some simple dynamic programming concepts in Python. The example I'll use is a classic recursive implementation of the fibonacci series . (And for simplicity I'll skip the first element in the series (fib(0)=0).) Naive approach  This implementation: ...works well (enough) for small numbers: but becomes impossibly slow quickly... ...since it has a time complexity of O(2 n ). (So our seemingly harmless fib(42) would result in more than 4 trillion calls to fib... (Or about 4 times the number of bacteria on the human body... Or 2 times the number of galaxies in the observable universe... Or more than the estimated population of fish in the ocean... Etc.)) Enter dynamic programming Since the result of these recursive calls to fib are all deterministic, we can cache the results instead of recalculating them. @functools.cache First a test by simply leveraging the cache in the library functools ... This speeds, as expected, the runtime up si...

Metaballs Revisited

The new visual identity of my work place (and the re-ignition of an old lava lamp) made me think of the good old metaballs from the Amiga demo-scene of yonder and how it has been a while since I have implemented them from scratch. This time I wanted to play around with Python and numpy to see what that could bring. But first, what are metaballs?  It's, for example, this: Wikipedia defines them as: In computer graphics, metaballs are organic-looking n-dimensional isosurfaces, characterised by their ability to meld together when in close proximity to create single, contiguous objects. https://en.wikipedia.org/wiki/Metaballs As cool as multidimensional metaballs are, we'll stick to 2D ones in this post. The algorithm The algorithm behind them is quite straightforward -- in their simplest form. Basically for each pixel in each frame, or buffer, you add up the influence of each metaball in the simulation and then cut off below a certain threshold and normalize what’s left. The...

Crafting an artificial opponent for Fjordar

Fjordar is an epic, tactical strategy game for 1 to 4 players, set during the Norwegian Civil War. The game begins in the year 1130, when the old king Sigurd Jorsalfar dies. Each player begins the game as one of Sigurd's heirs or one of the other influential people in Norway at the time, who is vying for power in the vacuum left by the old king's death. – Fjordar, BGG A while back, after a lengthy exchange on ideas around this topic, the designer of Fjordar, Frode Brændø, asked me if I would be interested in helping out with designing a solitaire variant for this upcoming game. Of course I would! Here are some brief notes on some from the design process. Idea We wanted to make an artificial opponent based the following criteria: Non-fiddlyness Running the opponent should not lead to a lot of overhead for the player. Readability The player should to some extent be able to read the artificial player enough to predict future actions and react to them. Keep ga...