I don't understand the algorithm for Skynet: The Bridge!

Guys, I really need your help. I have been working for 2 days on this puzzle and my head is on fire now

This is the algorithm I thought about :

  1. Initialize game (bridge setting, initial speed etc…)
  2. First loop, explore all game states (i) and leave out those that do not end up winning
  3. Keep a running queue of game states (with the commands in string as a member)
  4. Replay the sequence by dequeuing the game states every game loop

(i) Each gamestate node has :

  • Array of bikes (x,y, active or destroyed)
  • Bikes’ speed
  • Command (JUMP,WAIT , etc…)
  • Boolean “visited?”
  • and an array of Child nodes

Now for some reason, the search algorithm seems to keep using the DOWN command… the bike stays stationary in the first test case for example and I run out of moves…

I am sure my code is poorly written. It is my first time implementing something this complex (backtracing) and I would love to have some feedback on why it doesn’t work. I’d feel very frustrated if I have to start from scratch again … I feel like all it needs is some logic restructuring …

Here is my code :

I made sure to insert comments everyone so you can understand my line of thought …

Please help me!! THANK YOU.

I havn’t read and checked everything but here’s some things:

-your down and up arn’t checking if bikes can move up or down. you just node.moto[i].y++; ?

-your check for negative speed seems wrong you are doing && !node.speed it should be && node.speed I think, when you put an int in place of a bool the 0 is false and everything else is true. So if you have &&node.speed if speed is 0 it wont decrement the speed

I would also avoid 0 speed because you dont want your code to stand still, it’s a trivial stupid solution that keeps all bikes alive. So I would have speed>1 on the SLOW.

-you seem worried to pass the end of the bridge, this is actually hurting you, the bridge extends infinitely the only problem in going past the end is you might segfault depending on your code. What I did was add extra squares in my representation of the bridge

-your death check on up and down will have to be better than that, look at the rule for falling into a hole when you go up or down

You know your code better than I do so check if the things I mention are actually true

1 Like

Though I really like your post, I must edit your message to remove the link to your code.

You can give some part of your code that would lead to this “Always DOWN command” etc. but full code are forbidden.

It’s better for u to make some decision value.
If decision=0 then wait
if decision=1 then speed
if decision=2 then slow
if decision=3 then jump.
also you can make jumped value
and if jumped=1 then slow

Hi Saffar !

  1. First thing you need to know is when to increase speed.
    -speed up until you reach gap+1 to perform the jump

  2. Second you have to know the right time to jump
    -jump at the last cell off the road

  3. Finally you have to Slowdown and stop
    -slowdown right after the jump, or if you are exceeding the speed of gap+1

Have fun