Jump to content

How to prevent no out problem?


coderontheroad
 Share

Recommended Posts

Hey, I am new in game development and trying to develop my first games with Phaser. I am building something like old-style racing game. Think like you are the red car and blue cars are enemies. Right 2 line goes slower because of the same direction as you and left 2 line goes faster because of the opposite direction as you. I have a total of 8 number cars and placing them above the screen randomly when they go down the screen. The problem is, sometimes randomly you are in the situation like the image with there is no way out. Do you have any theoretical idea how can I fix it? This is a good challenge but I can't think anything useful yet :) 

https://prnt.sc/p8dsob

Link to comment
Share on other sites

@coderontheroad the image didn't work but I think I understand the problem.  If you are new in game development I'd encourage you to think about a general solution for creating patterns of "Entities" (such as cars on a road).  Basically random is almost always a mistake; it's chaotic, untestable, poorly designed, cheap, nasty, and prone to unwinnable scenarios.  It's not the "real" solution because it doesn't consider all the inputs.  Instead begin to think of using smart "Factories" to create Entities ...

The pattern of creation should be deterministic and regular, based upon a configuration and an elapsed state.  For example a deck of cards is not random, it is shuffled (a seeded rearrangement) and then each card turned modifies the state in a pre-determined way.  The dealer has the choice to either arrange the deck in such a way that desired interplay occurs (procedural-generation aka "cheating"), or automatically reshuffle when non-desirable interplays are detected (simulation and heuristics).

In the 4-lane road game scenario a procedural-generation approach might involve the use of prime numbers to ensure gaps between vehicles occur.  Or a heuristic approach might run the sequence in simulation (prior to the level starting) and remove any 3 lane overlaps.  A very simple old-school alternative is to have a fixed dataset, and to use that exact same sequence of cars for that level every time - if the playtester can complete the level then the data is acceptable because it will be replicable for other players.

All that being said the most commonly used solution is to introduce a new game mechanic that sweeps an existing issue under the carpet.  Or "that's not a bug it's a feature".  Who said games should be fair?

Link to comment
Share on other sites

@b10b thanks for your answer. I am trying to upload the image to the forum but always gives an error :(

Here is the problem image https://prnt.sc/p8dsob

There are 6 blue cars and 1 red car in total. And let's think lines like from left to right 1 to 4. The red car has a "speed" variable, and 1 line goes with speed*1.5... 2 line goes with speed*1.7... 3 line speed/1.5... 4 line speed/1.3.. I am adding cars one by one to each line. For example if the car added to 1 line the next car will be added to 2 line and it goes on order.

Fixed data set can be easiest solution, but if I can solve in another way I prefer it :) I checked "procedural-generation approach " and "heuristic approach" keywords in Google but can't find similar examples, can you help more to understand them? Thanks

Link to comment
Share on other sites

@coderontheroad Yes, looks like the forum no longer allows uploads, so remote hosting them is the way forward.  The image looks similar to what I imagined.

Terms like procedural generation and heuristics are quite broad.  Procedural Generation is where the creation details are determined by an underlying process.  Heurists are where the system can self-improve - rarely are they perfect, but just good enough.

To elaborate on a possible solution: Prime Numbers.  E.g. if lane 1 moves at 7, lane 2 moves at 11, lane 3 moves at 13, lane 4 moves at 17 then the odds of them coinciding are considerably reduced.  Ask any cicada!  Change the example Primes to any other distinct Prime, and multiply all by any constant to arrive at the on-screen velocity.

 

Link to comment
Share on other sites

@b10b can you use more simple english please :D sorry I can't understand your last paragraph. I want to share my find location function maybe it helps to understand my current situation;
 

locateEnemy(){
		var targetLocation;
		var locationX;
		var locationY;
		var skin;

		switch(this.lastLocation){
			case 0:
				this.lastLocation = 1;
				locationX = 112;
				skin = "enemy2";
				break;
			case 1:
				this.lastLocation = 2;
				locationX = 146;
				skin = "enemy";
				break;
			case 2:
				this.lastLocation = 3;
				locationX = 180;
				skin = "enemy";
				break;
			case 3:
				this.lastLocation = 0;
				locationX = 78;
				skin = "enemy2";
				break;
		}

		locationY = (Math.random()*400) - 420;

		while(this.checkEnemyOverlap(locationX, locationY, this.enemies)){
			locationY = (Math.random() * 400) - 420;
		}

		return [locationX, locationY, skin];
	}

locationX represents to which line, and there is while loop to check is there overlap with any other enemy car. Don't forget the lines moves different speed so I can't trust to locate perfectly at first position. Because of speed is different first position becomes doesn't matter. So if could you be more specific on how to modify locationY than maybe I can understand more easily. Sorry again to bother you more, but I really trying to understand :)

Link to comment
Share on other sites

@coderontheroad Thanks for the code.  I see only that you are randomising the start position, and rejecting such positions where another car overlaps it.  I don't see anything about movement, or any heuristic that considers whether a lane is open to the player either side of their current lane?

Usage of Prime Numbers for movement speed ratios would negate the need to randomise the starting Y or to check for overlaps.  Yes both the cars (and the player's opportunity to move) are not strictly confined to integers so some creative interpretation of this theory is needed - but the underlying quantizing will be good-enough to make the chances of an open lane (or imminent open lane) a higher probability than using random alone.  Or at least that's my "theoretical idea" ...

In simpler words, don't randomise the start position, do use Prime based ratios between each lane's speed (e.g. 7, 11, 13, 17).

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...