2

I am currently trying to code an android game (I will not describe it in detail as it is irrelevant) in which I am faced with something I have no idea how to do:

In this game, you control a point on a 4x4 square (like a 4x4 chess board for example).

You can only move 1 square in each turn. Obstacles spawn on a random side-square (on the outer limits) of the board, and travel from one side to the other (so their direction is the same throughout their whole life-span), moving 1 square each turn. They disappear once they've reached the other side of the board. More than 1 obstacle can spawn each turn.

You lose the game instantly if you end up colliding with an obstacle.

My problem is the following : How do I make sure the obstacles always spawn so that there is at least one way of succeeding in dodging all of them? What are the tests I should operate on their spawn location that would ensure that?

The answer may be simple but I do not have a lot of experience in this kind of mathematics-applied-to-programming problems.

Thanks in advance!

(PS: I wasn't sure if Stack Overflow was the right Stack Exchange forum to ask this question, please do tell me if I should ask somewhere else.)

mrqs
  • 23
  • 4
  • Smarter people than me may give you very well explained answers, but from what you say i would say you should go looking for pathinding algorithms as you want to "make sure there is at least one way". Wich is what pathfinding algorithms do ^^ – yan yankelevich Jun 30 '16 at 10:15
  • If i got it right maybe you just have to check if all borders center square aren't occupied by obstacles This is one of the rare situations where your player is doomed. But to increase difficulty in this kind of game i would mostly increase speed rate of block spawning and block movment, an makes sure that there is never more than 7 obstacles on board – yan yankelevich Jun 30 '16 at 10:19
  • The thing is, as I understand it, pathfinding algorithms would give me answers to the question "is there a way to go from A to B?" but here I don't specifically want to go anywhere, I could even spend a turn without moving if no obstacle run into me. I will look into pathfinding algorithms though, thanks for the tip! – mrqs Jun 30 '16 at 12:07
  • Well what you want to accomplish is to know if there is a way from your player position to anywhere. So a pathfinding algorithm should work, all you would have to do is checking if " there is a way to go from MyPlayer.Position to allPositions[i] in a for loop. You could have a look at this also if you don't want to use pathfinding http://stackoverflow.com/questions/4120609/more-efficient-way-to-check-neighbours-in-a-two-dimensional-array-in-java – yan yankelevich Jun 30 '16 at 12:15
  • 1
    I'm looking into that right now, this might make it work! But I just now realised that what I am asking for is probably a bit complicated, at least for someone like me, because I would basically need to calculate a very high number of turns in advance to know for sure that the game can continue for this given amount of turns, if I want to stick to pseudo-random spawns that is... This is bothering me more than I expected it would, as it is crucial to the game mechanics... Eh. – mrqs Jun 30 '16 at 12:34
  • 2
    Welcome to programming video games, where many things looks easy at first sight and end up being well more complicated. If this looks like to hard to you, i would recommand you to try what i said above about only increasing the obstacles speed and how often they spawn while being sure they are never more than 7 at the same time on hardest difficulty. – yan yankelevich Jun 30 '16 at 12:39

0 Answers0