# Questions tagged [algorithm]

Algorithms are used for calculation, data processing, and automated reasoning. More precisely, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function.

1,122 questions
Filter by
Sorted by
Tagged with
25 views

### Calculate index of bottom left block on a mxn grid

I am working on a board game that requires me to color the bottom left corner of the board with random number of rows and columns a different color from the other blocks. Given an m x n grid, how do I ...
25 views

### Algorithm to get all the blocks to the top and right of the current chosen cell in Chomp game

If I have a grid of 4x4, I want to get all the blocks/buttons in java that are to the right and top of the chosen block, how would I write an algorithm for it? For instance if the user picks the block ...
46 views

### Trying to generate a Tile labyrinth in Unity

So I have a generator code that renderes a TileMap on the scene, but It keeps creating a sollid block of walls Where I want it to have empty cells(This is not the final algorythm(Recursive ...
• 11
2k views

### Maintaining unit formation while following path

I'm currently working on a 2D Age of Empires style RTS game. Here's my problem: I'm currently using the A* algorithm (via Path finding package) to move my units. When you select a "group" of ...
39 views

### How to quickly calculate the number of tiles between buildings in a tile system

my friend and I are currently working on a city builder game like Anno/Cities Skylines but with some own ideas and tweaks. (of course, on a much smaller scale) Currently, we are struggling a bit with ...
1 vote
36 views

### Determine if a triangle is on the screen

I am working on a small software renderer, and I want to discard invisible triangles from the drawing process. Let's say I have a screen with resolution of 200x100 pixels. The triangle is defined with ...
• 339
1 vote
102 views

### Find closest open space in grid of rectangles?

I'm making a builder game where you snap arbitrarily sized rectangles into a 2D grid. I want the player to be able to drag and drop these rectangles anywhere on the grid, but prevent collisions (i.e., ...
• 13
10 views

### aiming prediction in 2d game using projectile [duplicate]

I am trying to make an agent predict the velocity required to throw a ball at a target and take into consideration the target. So what I need is a ball following a projectile path until it hit the ...
1 vote
30 views

### Detect if a chain of tiles form an enclosed shape/contour [duplicate]

I'm looking to determine if in a tilemap if a set of tiles of same color in a chain (either right next to cardinally, or diagonal) is forming a closed shape and to detect the tiles inside the said ...
45 views

### How to render the border of a collection of many overlapping radii on the surface of a sphere

I am developing a 3D game with THREE.js where all players are represented as points on the surface a sphere. The player A can move on the surface of the sphere within a radius of X meters. If another ...
• 1
1 vote
58 views

### Determine if a static mesh is lit by directional light

I want to determine if a mesh is lit by the directional light on my scene in editor to automatically disable its "dynamic shadow casting" property (let's say I have one light source in my ...
• 339
77 views

### How to find words on a hex grid

I am trying to make a hex grid based word game. Currently the words are placed from a list of pre-defined words(a list of animals in this case). All colored cells make a word that was placed, while ...
49 views

### What is the most efficient way to detect collisions of a large number of similarly sized objects?

Also, the maps are around 4000x4000 (pixels) So, all the objects in my game are 2D circles, and they all have a radius of between 5 and 10 pixels. My current solution is to use a spatial hash where ...
• 205
1 vote
117 views

### How to generate boards for a game like GamePigeon's Word Hunt?

Naively, I would assume that there's an even probability of any of the 26 given letters appearing in a tile and that each tile is generated independently. After playing around a hundred times, though, ...
• 13
41 views

### Projectile Aim Prediction with Target Acceleration and Bullet Deceleration Varying with Angle

I previously asked a question about this topic here, and now I'd want to review if the offered solutions worked, and then frame a new inquiry based on the difficulties and issues that resulted. So my ...
1 vote
48 views

### How can I implement an algorithm to mix potions?

I would like to build something that allows me to obtain potions using two identical lists of ingredients. ...
• 257
30 views

### Finding connected values of the same type within a 2D array

I am currently working on a puzzle game where blocks drop and you match nearby colors Blocks are stored within a int 2D array that stores with a value between 1-3 once placed, and it should find ...
60 views

### In a portal-based engine where Items are owned by a room, how to do inter-room collision detection?

My engine consists of Rooms. Rooms are connected via Portals. Items have a roomNumber field to indicate which room they belong to. And rooms have a linked list of ...
• 641
69 views

### Balancing random chance

I'm working on a text-based RPG incremental/clicker game. One of the features I'd like to implement is a 'bloodline' system; Every user gets a one time random chance to 'roll' for a bloodline. ...
• 113
88 views

### Understanding use of "localUp" in planet mesh generation code

I'm following a tutorial on YouTube about procedural generation of planets. I'm puzzled in some aspects of the code shown. If any of you could explain the following points, I would be very pleased. ...
66 views

### How to check multiple rings of tiles around a center tile on a 2D grid

In my game project I create the terrain programmatically by creating tiles on a 2D grid as the player moves around the game map. I have it working where I select the current tile and check all 8 ...
• 145
26 views

### Algorithm to create adjacent cubes while updating neighbour pointers

Following problem: I have a class node. Each node holds 6 pointers to its neighbours. I recursively check for nullptr while creating them but that leads to double declarations of the same node. I am ...
1 vote
55 views

### Fast way to test whether a point is over a 3D mesh

I have a map with islands, and I need to detect whether the player is on an island or not. The player can be flying far above the island, so a fixed-distance raycast is not sufficient, and firing long ...
• 241
1 vote
87 views

### Optimal way to find the closest entity to player with a restricted set of functions

The scripting engine of Skyrim (and Fallout 4) has an interesting function called FindClosestActor(x,y,z,radius). If you call it with x,y,z center coordinates and a radius, it returns the closest ...
91 views

### Best way to save game in story game

In a while I plan to create a story game that would have different routes and endings and I was wondering what would be the best way to save a game of a game like this, if it would be a folder, ...
• 1
4k views

### How to calculate player damage in a game

I'm developing an RPG and I want to do the damage calculation in my game. I have for example the following situation: Player 1 Stats: ...
• 197
28 views

### Given a set of points with color values, finding a gradated color value from a given position

I guess the verb form of gradient is "gradate" and not "gradiate"? Hi! I have a set of 2D points (actually 3D, but we can ignore the Y axis unless it's trivial) bound to color ...
44 views

### Need help on finding the algorithm for getting the FlipX, Y and TextureRotation of my DirectionalAnimation class

I've created a class called DegreeAnimation, which is basically an implementation of my CustomAnimation class, but works with other directions, there are 2 constructors for this class, one where the ...
1 vote
76 views

### Dividing amount of exp between rank A and B into a curve?

In my game I have a rank system. You start at rank A, and then you can level from level 1 to level 10. When you reach level 10, you get promoted to rank B, and you go from level 1 to 10 again, and ...
• 113
24 views

### Aim assist-- How to cast a wedge in screen space

My character exists in a 3D, isometric, top-down world. I'd like to make an aim assist mechanic, such that when holding the right joystick in a direction the game will choose the enemy roughly in that ...
• 143
113 views

### Extracting cell center and corner points from rasterized Voronoi diagram

I currently have this code which I copied from Rosetta code: ...
1 vote
132 views

### Rollback netcode: how to avoid teleportation?

I've currently implemented rollback netcode with a central, authoritative server (wooh!). I'm running into issues where if players have zero input delay, the other players see them "teleport"...
49 views

### In-game computation of heat maps OR pre-computed floyd warshall algorithms for AI path problems

I am working on a project, in developing a simple game. We need to have bots that shoot, ram, flee and chase other bots/players. Currently, I pre-compute my Floyd warshall algorithm so it is ...
88 views

### Check if a procedurally generated maze built out of cubes is solvable

I have created a procedural level generator in unity. However, occasionally the algorithm creates a level that is impossible to solve. Therefore, I tried to implement a navmesh agent to check if it is ...
236 views

### How can I build an accurate 15-bit Highcolor RGB palette

I want to recreate an accurate version of a 15-bit RGB color palette (PC Highcolor, SNES, Playstation 1), storing each color from the palette as a standard 6 digit hex code. With each color component ...
• 151
808 views

### How to read a sparse Octree sequentially, like a 3D array?

Is it possible to read a sparse Octree like a regular 3D grid: for(z) for(y) for(x) ...and still benefit from skipping large empty areas? I need this for a ...
• 161
97 views

### Confirming whether a user has drawn a character correctly

This is a follow-up post to this post: How can I check if a player-drawn line follows a path?. I'm having difficulty implementing the said feature and I believe it's because of a lack of math ...
• 103
1 vote
50 views

### How can I remove unnecessary vertices from wall edges?

I've got a pretty simple tile based 2d top-down map with an array of walls. In order to figure where to cast light and shadows, I've generated an array of vertex coordinates along the walls like so: ...
• 11
1 vote
57 views

### How to draw splatter (one color) on 2D grid to cover approximate number of pixels? (looking for algorithm/math answers)

Imagine a 2D grid, where water stain increasing because of water drops. But not in plain circular way but more like noisy-splatter way. Or like corruption way. I want to create effect that will ...
• 145
60 views

...
1 vote
31 views

### How to implement a big audio source and a cluster of audio sources?

I have a 3D game. The sound engine supports: playing ambient music to the player (two channels always the same) playing static sounds from a single position in space playing mobile sounds from a ...
• 188
1 vote
175 views

### How does a game like slither.io handle collision?

This question can be generalized to "how does one efficiently determine if a collision has taken place between curvy lines" On https://slither.io there are snakes that players play as that ...
• 205
1 vote
80 views

### How do I create an event trigger system for a Discord bot?

I am making a card game and I am having issues implementing "effects" and effects that are continuous. How can I get effects to activate at the right times, before and after an attack does ...
58 views

### Recycling bullets versus spawning them on demand

Until now, I know 2 bullets' algorithms/configurations : (I mean 2 ways of logically creating a bullet class) Make a bullet class and create only one instance from it that represents the bullet. The ...
• 216
1 vote
53 views

### Making Sprite Movement Appear More Natural

Currently I have a 2D game in which the player and a computer controlled (non-player) sprite move from point to point collecting tokens in a continuous environment. The player and the non-player ...
• 111
67 views

### Space out units to a grid pattern

So imagine an RTS game, with ~150 units all cramped together, just staying chill. What I would like is to "space them out" so that they d form a grid. This is useful for example when a large ...
• 121
96 views

### Need help with fixing Optimized Raycasting / Line of Sight algorithm

I'm trying to implement collision detection with raycasting for my 2D javascript game. The game uses equally-sized tiles as its level structure so to optimize collision detecton I'm trying to use a ...
38 views

### Finding a path to a circular zone in continuous space [duplicate]

I need to find the shortest path for an agent that wants to use a ranged attack against the specified target. This means that the path's ending point should be inside the range of the attack and have ...
• 121