Python Forum
Efficient algorythm for checking occupied fields.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Efficient algorythm for checking occupied fields.
#1
Hi, I'm making a game - something like this - my game changes in detaile, but for describing my problem, that game is great. I have a problem with marking a area.

Rules of the game (if you play in linked game for a minute, you will get if - it's basically described what pacman and ghosts do in that game):

On the map there is a player and enemies.When starting, whole map is empty (all fields are unoccupied).While player is moving through unoccupied area (the dark one on liked game) he is marking his path behind. If the enemy (ghost) hits the mark, player dies. This part is pretty easy - I a 2d array with numbers, where 0 = unoccupied area, 1= occupied and 2 = marked area, I just draw appropriate tiles and check array when objects are moving.
The problematic part comes, when player goes from unoccupied area to occupied area. There are three scenarios (this part is exactly the same as in linked game):
* the occupied tile is not connected with the edges of the map (this can happen when enemy destroys few tiles hitting them, and few are left alone in the middle of the map) - then marked path should be draw as occupied area,
* the player marks the path between two occupied areas, both connected to the map edges, then he makes two separated areas and two things can happen:
** first his path is marked as occupied,
** if on the first separated area is enemy (ghost) don't do anything,
** if on the first separated area there are no enemies, mark whole area as occupied,
** the same for second area

--- end of rules :)

As you see I described you something very similar as linked game, my will be different in details and is made mostly to learn python and have fun, but I have big problem with the last part, when I have to decide what to do if player goes from unoccupied to occupied area.
I could check tiles recursive - first the one I stand on, then her neighbours, then return true or false, but complexity of samthing like that is tragic (my map will have around 200 fieds).

Do you have some idea how to check and mark appropriate area, and don't have tons on computations at once?
Reply


Messages In This Thread
Efficient algorythm for checking occupied fields. - by kq2211 - Apr-17-2019, 09:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Efficient sprite scaling with Vector3 michael1789 1 1,913 Apr-25-2020, 11:18 AM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020