Alpha Pie

Breadth-first Search algorithm for a fun programming task

Challenge

We have created a mini game to test your skills. Go grab the flag!!

authors : careless_finch, malf0y

nc misc.challenge.bi0s.in 1337

Solution

Here are the rules of the challenge:

This could be solved by performing a breadth-first search (BFS) on all the possible moves. The problem with a depth-first search (DFS) - which I tried at first - was that we could get a solution, but it wouldn't be the best solution (it will exceed the maximum number of moves) , and finding the best solution would take too long on later levels.

But even on a BFS, the lower layers would eventually get too big since each game state would have many possible moves. To solve this, I filtered out those moves that heuristically "don't make sense".

In particular, I implemented this function that computes the "difference" between the current grid and the target grid. This is essentially the sum of the absolute differences of the x and y coordinates between the grids.

Heuristically, if making a move increases this difference, then that move is worse than one that decreases it. After generating all the possible moves, a threshold is applied at each layer to filter these bad moves.

Here's the final solve script:

After successfully solving nine levels, we get the flag.

Last updated

Was this helpful?