Hot answers tagged

11

Finding an algorithm is usually best done with a data structure that makes the algorithm easy. In this case, your territory. The territory should be an unordered (O(1) hash) set of borders and elements. Whenever you add an element to the territory, you iterate over adjacent tiles and see if they should be a border tile; in this case, they are a border ...


9

If you need to find edges of holes in the middle of your territory too, then your linear in the area of the territory bound is the best we can do. Any tile on the interior could potentially be a hole that we need to count, so we need to look at every tile in the area bounded by the territory's outline at least once to be sure we've found all the holes. But ...


7

Notice: Whether or not a tile is on the boundary only depends on it and its neighbors. Because of that: It is easy to run this query lazily. For instance: You do not need to search for the boundary on the whole map, only on what is visible. It is easy to run this query in parallel. In fact, I could image some shader code that does this. And if you need it ...


2

There is an else wrong indent in line 21. Add one more tab to it and in its code block. After try to rebuild. Python use identation to make code blocks.


2

I believe that this is what you were looking for: keys = pygame.key.get_pressed() # checking pressed keys if keys[pygame.K_ESCAPE]: # If 'esc' - QUIT GAME game_exit = True if keys[pygame.K_RIGHT]: # If 'right' - MOVE RIGHT character.move('right') The longer you hold the key down, the more it would move


2

Move your area up one tile, then up-right, then down right, etc.. Afterwards remove the original area. Merging all six sets should be O(n), sorting O(n.log(n)), set difference O(n). If the original tiles are stored in some sorted format, the merged set can be sorted in O(n) too. I don't think there is an algorithm with less than O(n), since you need to ...


2

A common technique for generating random worlds with large biomes is to use stock noise algorithms like perlin noise or simplex noise. Such algorithms generate noise patterns which generate a kind of "smoothed out randomness". Values don't change abruptly like they do in random white noise (like you are using right now). They change gradually with varying ...


1

Don't add biomes, instead vary parameters around your world and pick the biome based on that. For example you set a temperature and rainfall and you can use them to pick a biome; dry and how would be a desert, cold and dry would be taiga, cold and wet would be snow lands etc. That way you avoid having a snow biome next to a hot desert without a buffer zone....


1

Databases are supposed to be used for persisting long-lived data, not for ephemeral data. Using a database for storing short-lived chat messages just to delete them seconds later is quite an anti-pattern. It was common in the early years of PHP where databases were pretty much the only way to exchange data between sessions. But more modern web application ...


1

I'm on my phone and can't provide a super detailed answer, but here goes. This answer will not cover the physics calculation that you use, only the logic. It looks like there is trash data in your loop. When evaluating a body with itself, you do not update the angle and the acceleration, it remeains to what was used with a previous body. Whatever is in ...


1

I'm not sure if it would work well, as I'm not familiar with pygame, but you could stick the value that you want in your Dog object as a float, and do calculations on this value, then use this value converted to int to update the rect.y variable. Dog.computation_y += 0.5 Dog.rect.y = math.floor(Dog.computation_y) You'll be able to control a bit more the ...


1

pygame.sprite.groupcollide returns a dictionary that always includes the sprites in the first group. Therefore, the if test you have written will always return true. You should re-write the function to check whether or not there are sprites in the list for every sprite in the dog group.


1

So you have a "one-button" gameplay and it's not engaging enough? Have you played NFSU? It had a drag race mode, which is basically pressing one button in perfect timing to outrace other competitors. Why not try to replace turns with cooldowns. Whenever someone's cooldown reaches zero - they can have their turn and try to press the button in perfect time. ...


1

worldNormal = modelMatrix * vertexNormal; x = Dot(camera.right, worldNormal); y = Dot(camera.up, worldNormal); angleaRadians = Atan2(-x, y);


1

The KEYDOWN event is fired every time the key is pressed down, so the impulse is applied only then. Instead, you should remember the state of the key and apply force in every iteration of the main loop if the key is pressed down. See this article for example code: https://www.iforce2d.net/b2dtut/forces Also to make sure the speed is framerate-independent, ...


1

First, instead of storing each platform as a member in class, do it like this: self.platforms=[Platform(200, 550), Platform(600, 550), Platform(1000, 550)] It's the list of all platforms in the game. By storing them in the list, you'll be able to easily add or remove them. Do the same for each object that's going to be more than one in the game (coins, ...


1

As you've pointed out, the other question you linked to is more about how to render a nice graph and numerical change, and not how to decide exactly how or why the number should change. It just states... You start at time T1. You're going towards time T2. Price at time T1 is P1. P2 is end price. You generate a random number (probably based on some events, ...


1

When you use something like self.foo.bar = self from the class bar, you're telling foo which bar it is linked to. Basically, self.scene = scene self.scene.manager = self is used to set reference in both ways, so that from the SceneManager, you can know which scene is managed, and from the scene, you can get access to the scene manager through the ...


1

The code formatting for your answer has mostly broken down, it would be a lot easier to help you if you fixed it. What does it mean for turtles to collide? It means that they occupy the same space, so the easiest thing to do is: if player.position() == player2.position(): print("GAME OVER") quit() however, this doesn't quite work because turtle ...


1

I just wrote a blog post about how to do this. This uses the first method that @DMGregory mentioned starting with an edge cell and marching around the perimeter. It's in C# instead of Python but should be pretty easy to adapt. https://dillonshook.com/hex-city-borders/


Only top voted, non community-wiki answers of a minimum length are eligible