Score Based on Game play Time and a Int I'm trying to do a score that is based on the time taken and number of manipulators used. The faster you do it, with the fewest manipulators, the higher the score. I've managed to get it working with you get the lowest score but not the highest and i can't think how to do it. Any help would be appreciated. I have a play time (GameTime.TotalGameTime.TotalSeconds startTime.TotalSeconds) and a count of the manipulators used (grid.NumberOfManipulatorsInGrid(TextureList.GameplayTextures)) to work with


Algorithm for game difficulty pacing curve generation in single player RPG I'm looking at this article about pacing in entertainment and games. It suggests that all good entertainment roughly follows a pacing engagement curve like Star Wars(below). I'm interested in how I can procedurally generate random looking curve that would conform to the Star Wars engagement intensity pattern (linear increase and oscillating peaks valleys). The simplest implementation I can think of is a rectified sine wave and a sloped line, but that would be very predictable. I have an algorithm for perlin noise already in the game and am interested if I can leverage perlin noise algorithm to procedurally generate a varying sequence of peaks and valleys on an increasing slope. Here's my attempt so far Once I have an algorithm, I can reference it to get engagement difficulty in relation to game turn or progress through some level. I will add my thoughts to this question in hopes that someone can correct or point out flaws in my approach below I get the basic XP system in place (previous level 1000 to advance to next level) Decide on the level cap (lets say 20 levels) Plot available equipment tiers vs 20 levels (regular at lvl 1, magical at lvl 10, epic at lvl 20) Using the peak valley graph decide how many fights are in each peak valley cycle (5 to reach lvl 2, 12 to reach lvl 20). estimate number of turns per fight, let's say 5 turns per fight calculate xp needed and turns needed to reach to each new level Plot turn number and hypothetical xp the party has at each level. Now for each peak I have a number of turns and the amount of XP that the curve should have between two valleys. Using whatever formula the curve follows at that peak (let's assume a bell curve), I can get the xp value of monsters I have to spawn during that turn. These monsters have their equipment adjusted according to the equipment vs tier turn number that was calculated above. Now I need to adjust monster XP and test it at different levels. A simple sanity check a party of 6 players must kill 750 xp of monsters in first fight in 5 turns, that is 30 actions. 1500 in second fight 1800 in third fight 1350 in fourth 555 in fifth


Connecting two arbitrary points with 2 lines DEFINITIONS Any "Point (x, y)" mentioned below is really the bottom left coordinates of a 1 unit by 1 unit rectangle. A "Line" is a defined as a rectangle that is either 1 unit tall and 1 unit or greater wide, or 1 unit wide and 1 unit or greater tall. These rectangles are constructed given a Rectangle(bottomLeftX, bottomLeftY, width, height). The height and or width can be negative. If either are it will shift the start x or y accordingly as so public Rectangle(int x1, int y1, int width, int height) left x1 right x1 if(width lt 0) left width else right width bottom y1 top y1 if(height lt 0) bottom height else top height THE GOAL Given two arbitrary points, define two lines (as rectangles) connecting the two points. The two lines need to randomly 'bend' at one of the two possible connections (see below). The two points aren't in any specific order. Point A's X and or Y can be above, below or even the same as Point B's X and or Y. THE PROBLEM I have made a solution that only partially works. There is a bug in my method below where sometimes the two lines do not connect at the bend junction. It seems to only be when the bend junction is in the bottom right of the points' bounds. WHAT I HAVE NOW A little background I'm working on a random dungeon generator. I create rooms randomly, and then I am going to connect them using the described point and line system above. Here's what I have now. "graph" is a Map , technically it's directional, but the reason was so that I wouldn't draw the same lines twice. int x, y, dx, dy Rectangle a, b loop through each edge of the graph for(Rectangle outer graph.keySet()) for(Rectangle inner graph.get(outer)) randomly set a and b if(random.nextBoolean()) a outer b inner else a inner b outer generate the origin points based on a x (int) a.getCenterX() y (int) a.getCenterY() and the delta of b to a dx (int) b.getCenterX() x dy (int) b.getCenterY() y create line starting at a, then create line starting at end of above line lines.add(new Rectangle(x, y, dx, 1)) lines.add(new Rectangle(x dx, y dy, 1, dy)) Here's what it produces. Most of the time it works, however there are cases where the corners do not line up. I'm not sure how to fix this. Any input is much appreciated.


How can I generate Worms style terrain? I'm working on a Worms styled game and want to generate some terrain procedurally. I've previously done a lot of terrain generation using perlin noise, and this is what I started out using for this game. The only problem with it is that it's too simple and boring, giving me some hills but not the complexity I want. I'd like to have features like caves and hanging mountains and I don't mind floating islands and such. Something like this, but even crazier would be ok I thought of first generating the terrain using classic perlin noise, then just removing parts to create caves and what not, but I'm having trouble guiding the removal of those parts. Are there any alternatives to generating such a terrain?


How can I create the arriving engaging in combat movement like in StarCraft 2? I currently have two armies (smaller scale) crashing into each other. They will usually form a line of units fighting. I have no idea how to handle a unit coming from behind the line to properly go around its allies to reach the enemies. Like in this position, where a new unit approaching from the green army needs to navigate around the battle front to reach the red enemies StarCraft 2 handles this beautifully, as seen here I've read that SC2 uses steering for local avoidance and A and some other methods to plan out the paths. Which all is perfectly clear, but I haven't found anywhere any details on engaging the enemy. This is what I have, it's been a month and I still haven't solved this specific issue. How is it possible to do continuous checks of possible destinations before engaging the enemy, wouldn't it be too costly? To clarify, in the video of the Zerglings vs Zealots, they first engage each other and form a line, all the other units that come after them will go around the line, but, if space opens in the line they will immediately go towards it. This kind of arrival behaviour is briefly explained in their GDC talk, they have a cone of vision in which they do checks. The only ideas I had was Have a cone of vectors (in the direction of Velocity) and do checks for each vector to see if it could provide a favorable position to move to issue Cannot figure out the math to create offsetted (by an angle) vectors, but it seems like a pretty decent solution Have a spatial query in a rectangle to where the unit is moving issue How do I check for an empty space? I can get all entities in that rectangle but how can I check for empty places and score them (how favorable are they)? Are they even reachable, I'd still need some kind of raycast like with the first option I have circlular collision shapes, seperation and goal following in place. I somewhat have introduced a goal system that should further spread the units, but as it stands I still lack the arrival behaviour described in the GDC talk.


Locating point on a closed path to maximize sum of distances to a sample of weighted points I'm doing AI for a simple puzzled game and need to solve the following problem efficiently (less than 1 sec for the range specified since I need to do many iterations in a game). A sample of N (1 to 100,000) monsters with strength from 1 to 10,000 are distributed on the sides of a square (0 to 200,000,000) at 1 unit interval starting from the upper left corner. Move hero to a point X on the square to maximize sum of the weighted distances to the monsters. A weighted distance to each monster is calculated by MonsterStrength ShortestDistanceToX (by going clockwise or anticlockwise). X must also be on the 1 unit interval mark and the monsters and hero move on the sides of the square only I have tried several approaches but none are fast or accurate enough. The possibly complementary of this problem (minimizing the sum of distances to set of points at furthest distance from each corresponding monsters in the original set) seems to related to finding the geometric median, facility location problem, Weber problem etc. Linear programming is also possible but might be too slow and overkilled. Does anyone have any idea for a good approach? Here is an illustration on a square of sides of length 3 1 2(M 3) 3 4(M 1) 12(M 2) 5 11(M 1) 6 10 9 8(X) 7 if you put a monster of strength 3 at 2, one with strenth 1 at 4, one with strength 2 at 12 and one with strength 1 at 11 and the hero(X) at 8. the sum of weighted distane is 3 6 1 4 1 3 2 4 33, which is also the maximum in this case


What is the simplest method to generate smooth terrain for a 2d game? What is the simplest method to generate smooth terrain for a 2d game like "Moon Buggy" or "Route 960"? I got an answer at stackoverflow.com about generate an array of random heights and blur them later. Yes, it's quite okay. But it would be better to give some points, and get a smooth curve.


How to create a random, warped 2D grid? How do you create a random grid where the lines aren't orthogonal (and cells aren't a perfect square), but are warped? Here's an example of what I mean (Credit screenshot taken from a video by Silvarret about the game Townscaper.) Lines curve. Sometimes many cells come together in a single point. Yet, it still looks like a grid and the cells are clearly visible and roughly equal in size and shape. I have absolutely no clue how to go about something like this. How is this achieved? Is there an algorithm for this? How would you detect the cell over which the mouse hovers?


Predicting enemy position in order to have an object lead its target In my 2D game I have AI turrets that should assist the player by automatically firing towards enemies. I would like to make them fire intelligently and lead their target instead of just targeting an enemy's current position. So, given the (always constant) velocity and position vector of both the enemy and the turret's projectile, how can I find a vector that represents the actual position the turret must target in order for the projectile to intersect (and hit) the enemy? Any links to articles that describe the math, algorithms, etc. would be appreciated!


Axis Aligned Spatial Division Divide space into random rectangles? I need a method to divide 3d space into random axis aligned box shapes. For now I am currently dividing the 2d space for testing purposes. The most immediate approach I came up with was to define a rectangle of size (1, 1) and then recursively split all existing rectangles to two uneven rectangles alternating between axis X and Y. The problem here is obvious. This approach results in long stretching lines (marked in red) What I would like is something more organic looking (I included an example) See, no long straight lines from top to bottom or left to right. The only constraint is that I may wish to limit the minimal size of the rectangle without affecting the granularity of the sizes. i.e. if the smallest rect is 1 square centimeters than the seconds smallest room should not be 2 square units. So ideally the algorithm should meet all three following constraints Rectangles are not infinitesimally small. Rect sizes aren't discrete multiplication of the smallest rect size. i.e. if the smallest rect is 3 square unit than larger rects are not constrained to be 6, 9, 12 and so forth square units and instead could be 3.2 or 4.7 for that matter). The algorithm runs in polynomial time (needs to compute fast).


Algorithm for staying "alive" forever I am implementing a game where the player is playing(sliding) the little red rectangle and the purpose is to not hit the black rectangles and to not move out of the inner blue rectangle. The black rectangles are moving in trajectories from left to right(right to left) and from top to bottom(bottom to top). The speed they are moving with is constant e.g. 5 pixels. You can get a better idea in this video. One of the game modes is the following 2 paths will be proposed by the game displayed as arrows and one of them may lead to "death", while the other will always be the right one and the user will have to choose one of them until he makes the wrong choice. The movement directions can only be top,bottom,left or right and not diagonal and the speed of the red rectangle is constant e.g. 6 pixels and the black rectangles speed is 5 pixels. I am struggling with the algorithm for the "successful" direction for more than a week and what I have done so far is the following Generate a random float number between 1.0 and 2.0 seconds and then divide the generated number by 0.030 for example to get the number of moves that will be made by the black rectangles and red rectangles. Calculate the black rectangles and red rectangle move points that will be made for the following time session by multiplying the number of moves by the speed which is 5px for the black rectangles and 6px for the red rectangle. After I know the speed of the black rectangles and the number of moves I can tell their position in any time of the current time session. Move the red rectangle to the left until it is being hit and remember that result e.g. 15 moves until hit. Do the same thing for right,up,down direction. Sort the direction by the moves that can be made before hit in ascending order. Move the red rectangle in the direction in which the most number of moves can be made. Do the same thing until the time session ends i.e. the random float number generated in the first step. This solution works most of the time, but some times it leads to a position where an escape is not possible. The problem is not in the code, but in the algorithm logic. For example look at the following image As you can see the red rectangle will go to a position where it will be stuck by two of the black rectangles. The best possible solution in this situation would be to move to top 1 time and then to left and after that to top, because the black rectangle in the top left corner is going to top, but I really have no idea how to solve this task. What would be the optimal way to accomplish this task. Thank you in advance!


How to calculate best move in Match 3 game? I am having a hard time identifying how to approach this problem. If you have a match 3 game and the objects can only be swapped horizontally and vertically, and only swapped if it will result in a match of 3 or more jewels, which will be removed, with each removed jewel adding 1 to the score. How would I find the best possible move? I'm confused at where to start and been searching for a while now and getting nowhere. Board 6x6 or 8x8 Matches 3 or more of same kind write function to find best swap for maximum score. Any help would be greatly appreciated ! EDIT So I could iterate through the entire board with a nested for loop for the rows and columns, but im not sure what approach to take from here. For example, say I start with top left which is quot red quot and I want to test if swapping this will result in a match. How would I go about searching and identifying all possibilities that would result in swapping this left equaling a match and score of 5. If I am being really unclear I apologies and will remove my question and possible reword.


Fastest way to neutralize scale in the transform matrix? Let's assume we have 4x4 3D transformation matrix, that is the result of scale, rotation, and translation transforms. How to set its scale to (1,1,1) in the fastest way? Assume also that the matrix is represented by float 16 array. By fastest way I mean, the most performance accurate way, that will be low CPU cost.


Voxel sparse octrees for indirect illumination I don't understand the use of voxel sparse octrees for indirect illumination calculations. First of all, what exactly is happing? We're rendering the scene as usual with diffuse lighting. In the meantime, we're maintaining the octree of our scene. But when do we use it and for what exactly?


Documentation on 2D space partitioning I am looking for documentation that explains the different kinds of (well the major ones anyway) 2D space partitioning algorithms amp data structures. Any pointers besides 'Google it and sift through hundreds of papers'. A book perhaps?


Algorithm to modify a color to make it less similar than background I'm creating a demo of 20 balls bouncing each other, with a background filled with a solid color. Color for each ball is chosen randomly with randint(0, 255) for each R, G, B tuple component. Problem is some balls end up with a color that is very similar to background, making them hard to see. I would like to avoid that, either by rolling another color if the chosen one is too similar (within a given threshold), or by moving it away from the background color. How to calculate a similarity index to use as a threshold? Or how to transform a color to make it, say, less blue ish? Obvious disclaimer I know nothing about color theory, so I don't know if the above concepts even exists! I'm coding in python, but I'm looking for concepts and strategies, so pseudo code is fine (or just the theory). EDIT To clarify a few points Each ball have its own random color. I'd like them to remain as random as possible, and to explore as much as possible of the color space (be it RGB or HSV, pygame accepts both formats for defining color) I'd just like to avoid each color of being "too close" to background. Problem is not just about hue I'm perfectly OK with a light blue ball against a dark blue background (or a "full blue" against a "white ish" blue, etc) For now, I don't care if a ball ends up with a color similar (or even identical) to another ball. Avoiding that is a bonus, but it's a minor issue. Background color is a constant, single RGB color. For now I'm using "basic" blue (0, 0, 255), but I'm not settled with that. So consider the background to be of an arbitrary color (with arbitrary hue, brightness, saturation, etc). EDIT2 TL,DR version Just give a way to create X random colors so that none "fades in too much" against a background of arbitrary (but single and constant) color


Generate 2D Triangular Mesh from Vertices on a Map Given a map of vertices (x1,y1), (x2,y2), ... (xn,yn) , how can I generate a 2D triangular mesh covering all vertices, and where the area of all triangles completely covers the map? The triangular areas may fully enclose other triangular areas, but no two triangles may intersect.


How to avoid self intersection when applying stroke to a curve? I have several Spline2D objects in my code, each of which has a Position, Velocity, and Acceleration method that returns a vector of the specified quantity at a particular time. I've been using these vectors in order to construct geometry to create gradient strokes for the curves, but I'm having problems with self intersections at steep curves. As an example, here's one curve where I'm having this occur Wireframe http twitpic.com 2zplw1 full Filled http twitpic.com 2zpmnt full As you can see, on the second bend, the inner portion intersects itself, which causes that ugly artifact. Is there a good algorithm method to stroke curves without causing that self intersection? EDIT More extreme examples, plus a mock up of what I'd like to achieve Wireframe http twitpic.com 2ztwzi full Filled http twitpic.com 2ztwkt full Ideal Outcome (Mock Up) http twitpic.com 2ztxa8 full


How do I avoid obstacles on a predefined path? I want is a character to walk along a path defined as a waypoint sequence. For example, a soldier patrolling around a castle. However, I want the soldier to avoid (dynamic) obstacles, without deviating from the path too much. How can this be done?


How Can I Improve This Card Game AI? Let me get this out there before anything else this is a learning exercise for me. I am not a game developer by trade or hobby (at least, not seriously) and am purely delving into some AI and 3D related topics to broaden my horizons a bit. As part of the learning experience, I thought I'd have a go at developing a basic card game AI. I selected Pit as the card game I was going to attempt to emulate (specifically, the 'bull and bear' variation of the game as mentioned in the link above). Unfortunately, the rule set that I'm used to playing with (an older version of the game) isn't described. The basics of it are The number of commodities played with is equal to the number of players. The bull and bear cards are included. All but two players receive 8 cards, two receive 9 cards. A player can win the round with 7 bull, 8, or 8 bull (receiving double points). The bear is a penalty card. You can trade up to a maximum of 4 cards at a time. They must all be of the same type, but can optionally include the bull or bear (so, you could trade A, A, A, Bull but not A, B, A, Bull). For those who have played the card game, it will probably have been as obvious to you as it was to me that given the nature of the game, gameplay would seem to resemble a greedy algorithm. With this in mind, I thought it might simplify my AI experience somewhat. So, here's what I've come up with for a basic AI player to play Pit... and I'd really just like any form of suggestion (from improvements to reading materials) relating to it. Here it is in something vaguely pseudo code ish ) While AI does not hold 7 similar bull, 8 similar, or 8 similar bull, do 1. Establish 'target' hand, by seeing which card AI holds the most of. 2. Prepare to trade next most numerous card type in a trade (max. held, or 4, whichever is fewer) 3. If holding the bear, add to (if trading lt 3 cards) or replace in (if trading 4 cards) hand. 4. Offer cards for trade. 5. If cards are accepted for trade within X turns, continue (clearing 'failed card types'). Otherwise a. If only one card remains in the trade, go to 6. Otherwise i. Remove one non penalty card from the trade. ii. Return to 5. 6. Add card type to temporary list of failed card types. 7. Repeat from 2 (excluding 'failed card types'). I'm aware this is likely to be a sub optimal way of solving the problem, but that's why I'm posting this question. Are there any AI or algorithm related concepts that I've missed and should be incorporating to make a better AI? Additionally, what are the flaws with my AI at present (I'm well aware it's probably far from complete)? Thanks in advance!


algorithm for combining smaller tiles to balance the bigger ones I have a field of tiles basically each tile is a country that has some kind of sovereign. The tiles countries have different weight. For now I use some numerical value but in the future the weight will depend on tile size, produced resources and so on. So I want for those countries to make alliances if their sole weight is much lower or at least lower than a certain threshold than the weight of the neighborhood tile (each sovereign is basically a primitive AI at that stage that is able to make decision to create the alliance). Here is couple of scenarios Here are the examples for bigger maps with possible alliances So my question is is there some kind of algorithm that allows to achieve that or I have to create it myself or use training sets for AI to gain the ability to form alliances?


How to generate random level from a seed? How would I go about using a random seed to generate a game level? The same seed should always generate the exact same level. For this example it would be a Worms style level. So each level would have a theme (grasslands, snow etc), base terrain, different objects such as trees. So where would I start to create this kind of level generator? What would be involved? What concepts does it use? Bonus points for any any good links (bonus bonus points for anything related to how it was done in worms or similar). Thanks.


Turn Based AI Algorithm (Small Board, Two Steps) This is my Game Board The Red Balls are the AI Controlled Actors. The Blue Balls are the Player Controlled Actors. The Yellow Cells are the locations, from which the Red Balls can attack. Each Red Ball can do 2 actions move move, move attack, attack attack. At no time there can be 2 minions on one cell, but a minion can arrive on a cell another just left. Its the AI's turn. Its planning the whole turn for all minions, each of them has the two moves. The objective is to maximize the number of melee attacks, which can performed in a single turn (2 actions) on the player balls. Problem I have in my current (brute force) implementation Sometimes it is advisable for a minion to move, although it is already in a melee position, to make space for another minion, which can then move into melee range aswell. Example In this situation its more effective for the front minion to move once, so another minion can move into melee range as well. Do you know an effective algorithm for this job? Thank you for your time!


Raycast algorithm fails to collide with diagonal walls in specific locations I'm having a problem with my ray cast algorithm in a 2D tile based universe. I feel the situation would be best explained with a picture, so here it is The ray, represented by the blue line, is passing "through" the wall to hit its target when the wall passes through a point where the quantized line moves diagonally and the wall is perpendicular to it. The raycast function is as such def raycast(pos, direction, level) dx, dy direction t 0 x, y pos obj None while not obj and t lt 5000 t 1 x dx y dy obj level.get at((round(x),round(y)),True) pass return obj Is there a simple, efficient way to eliminate this kind of edge case?


How to correctly solve a procedurally generated puzzle? I'm creating a puzzle game where the player must remove all colored blocks from a grid. When the player selects a block, all adjacent blocks of the same color are removed. Any blocks that have empty cells below them will then fall into those cells. Here's a simple illustration of the mechanic https imgur.com TBNrAUW The game will procedurally generate puzzles with varying degrees of difficulty. When the player completes a puzzle the game will then score the player based on how quickly and, more importantly, how efficiently they solved the puzzle. The problem I am having is implementing a method of determining the most efficient way of solving a puzzle (i.e. identifying the fewest number of moves possible). Here's an example of a puzzle that was generated https imgur.com RQcAgkH As a human, I could identify that the fewest number of moves that could be made to solve this puzzle was 11. Here is a gif of the solve https imgflip.com gif 463qck However, when I whipped up an application that just clicked blocks at random in order to solve this puzzle, the lowest number of moves that it was able to solve this in was 14. And this was over billions of iterations which took many minutes. Obviously that is not acceptable. I need to find the correct solution and it should be done within seconds. I also tried to reverse engineer the generation process but that doesn't work. For example, it could place a blue block in column 1, a bunch of other blocks, a red block in column 1, a bunch of other blocks, then another blue block in column 1. Column 1 could be resolved in 2 moves (by clicking the red block and then one of the blue blocks), which reverse engineering the generation would not detect. So, my question What kind of techniques or tricks can I implement that will allow the application to resolve this type of generated puzzle quickly and correctly? I'm sadly out of ideas.


Paint game level algorithm I have a game, and I have a level editor where you can build your level from blocks. Blocks positioned in cells. So blocks can have no neighbours or have one or few neighbours. My problem is that I need to put appropriate texture to block, based on block position related to another blocks. Is there some specific algorithms or methods that can help me? I want it to update textures after adding moving deleting each block so it should be fast. Levels can look like


How can I generate my puzzle game's result tables? I have a pattern game and it is almost done however I am stuck on the last part. I have a screen with 25 blocks (in a table format 5x5) and the user clicks on it to turn over the blocks, I need to see if the user has turned over a line of blocks. So I created a bunch of options and I am trying to compare it to the table of the current system (1 not turned over and 0 turned over). But the problem is my table looks like local level1o1 0,0,0,0,0, 0,1,1,1,1, 1,1,0,1,0, 1,1,1,1,1, 1,0,1,1,1 And when I do the compare it doesn't say it is the same because of the other random 0's in the table. I don't want to make every single possible result table, so any ideas of how I could do this? Compare function Table Compare local function deepcompare(t1,t2,ignore mt) local ty1 type(t1) local ty2 type(t2) if ty1 ty2 then return false end non table types can be directly compared if ty1 'table' and ty2 'table' then return t1 t2 end as well as tables which have the metamethod eq local mt getmetatable(t1) if not ignore mt and mt and mt. eq then return t1 t2 end for k1,v1 in pairs(t1) do local v2 t2 k1 if v2 nil or not deepcompare(v1,v2) then return false end end for k2,v2 in pairs(t2) do local v1 t1 k2 if v1 nil or not deepcompare(v1,v2) then return false end end return true end Example list of possible answers local level1o1 0,0,0,0,0, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1 local level1o2 0,1,1,1,1, 1,0,1,1,1, 1,1,0,1,1, 1,1,1,0,1, 1,1,1,1,0 .. etc


Help me please to choose proper path finding algorithm I am new to game development and just want to ask for advice. I need to know which path finding algoritm will be suitable for my scenario Units any shape. But in most cases rectangles of different sizes. I have random generated maze and destination point or area. Because of different maze borders not all unit can fit and move to the end. How to find path from unit to destination area and check that shape can move to this area?


Checking whether moving object has reached target position So I have a fast moving object in my game, let's say a bullet. At each iteration of the main loop I update the object's position based on the delta time value dt and draw it at the new position. I also check whether the object's new position is close to a target position. In that case the object will be removed S.... ... .... .... ...... ... .... .... ... ..T.. X The object starts from location S, moving towards target position T. Each dot . represents one ms time. The vertical bars represent a game loop iteration, in which I check whether the object has reached its target destination. At X the object will be removed. Since these checks (ie. game loop iterations) might take place before or after the 100 exact target position (even if only a few pixels off), I perform this check with a distance between a line segment from the last position to the current position, and whether the target position is on that line. This approach works well. There is one issue though Since the check in which I recognize that the target has been reached happens after the real position of the target, the object moves a little bit further than desired. That's becoming more severe when the object is moving very fast. Now my question Is there kind of a "best practice" how to deal with this issue? I assume this is a common problem in game development. PS The only solution I could think of is to re position the object to the real target position as soon as the check succeeds. However, that can look a bit like a "jump" back, which does not look great.


Implementing a color picker I'm making a paint program using applets in Java, and I want to create some sort of color palette where the colors blend into each other, similar to this However, I'm having trouble understanding the correlation between the R, G, B, values and the X, Y coordinates for both the outer circular color palette, and the inner hue selecting palette. Representation


Which is faster raycasting or shadowcasting? I'm looking to create an FoV implementation and I was wondering which algorithm is faster raycasting or shadowcasting?


What algorithm can I use to detect simple shapes in a 4x4 matrix? I'm working on a simple multiplayer game that receives a random 4x4 matrix from a server and extracts a shape from it. For example XXOO OXOO XXOX XXOO XOOX and XOOO XXXX OXXX So in the first matrix the shape I want to parse is oo o oo and the 2nd oo oo ooo I know there must be an algorithm for this because I saw this kind of behavior on some puzzle games but I have no idea how to go about to detecting them or even where to start. So my question is How do I detect what shape is in the matrix and how do I differentiate between multiple colors? (it doesn't come only in X and O, it comes in a maximum of 4). Additionally, the shape must be a minimum of 4 blocks.


Voronoi graph traversing from vertex to vertex I'm working on a Unity Project in C I've built a 3D Voronoi Diagram using the csDelaunay library from PouletFrit and using the X and Y values from a 2D diagram to instead setup some Vector3's with something like (x,0,y) Example My current task is to build a river, as a List of Vector3's I've so far been able to figure out most of the library code, and build retrieve lists of The north most Vertices, South most, East and West All Edges, and for each their left vertex (green) and right end vertex (red) All Sites Seeds To start the river I've picked one vertex at random from the North most list and then pick a suitable opposing vertex on the south list. I've been at this for many hours now, getting nowhere really, but I think my main problem is I can't focus. So I'm going to avoid splines, meshes, etc. for now and keep this simple, I just want to get a list of points the river will go through. as advised by 'Arcane Engineer' on a previous question (too broad), I'll just use the Voronoi cell boundaries for this, but I need to find the shortest or best path between my north river point and my south point. I've been assuming that either Dijkstra's Algorithm or A are the best way to do this but I'm really struggling now, and A seems to be more built for open space and determining the route around obstacles, rather than shortest path through fixed nodes ? as Dijkstra's would need a graph data structure (among other things), would I be correct in saying that The Voronoi class in the library I'm using is already a type of graph data structure ? or would I need to augment it a bit to perform Dijksta's algorithm My background is mainly in Java, and I hope I have a decent understanding of all the OOP principles I need here, and I have some data structure knowledge, at least at a high level. but if possible i'd like to use pre written stuff. I found a Priority Queue class from Microsoft that may help me in implementing Dijkstra's ? I tried working on a "simpler" recursive algorithm that checks from the first point (north most), what edges are connected, and then what direction vector they are going in and compares the angles for each edge vs the target direction, and the smallest angle wins. I haven't got it working yet. But I also get the feeling this is NOT the best way to do this. Any advice you could give is much appreciated!


Help me to fine tune my diamond square algorithm Check this map i generated I seeded a sine wave to act as a mountain range. The lower portion of the sine wave looks fine, but the upper side is thin, the algorithm did not do its magic there (expanding with some noise the seeded values to generate wider mountain ranges and then some hills (brown and light brown)). Also, the whole continent shape is not affected by the sine wave. Ideally, it should be like a "S" as the mountain range pretends to be. I bet this is how the diamond square algorithm takes the values it uses to make the average. If not seed the center point of the map, i can not generate a continent, it just makes a pelinesque noise of random hills. Basically, i'm having some hard time trying to control the noise with seeds and toying with amplitude and randomness reduction values. I need some experienced people in world generation and noise to help me out! Thanks! (PS red dots are rivers).


How to find a free patch of area in a tiled map? I've been trying to formulate the question and try to find some information on Google, but didn't managed to, so here it is... We've got a nice tropic themed game that is about to be released soon, that uses a tile map and an A pathfinding is utilized and everything works flawlessly. Until when it comes to the point where I need to somehow find unoccupied patch of area on the map that matches certain criteria, so that I can guide the player to place their just bought map objects on. The map is 200x200 tiled map and it holds instances of each tile that determine two things if it is occupied and if it is a water or a ground tile. These are already used for the A pathfinding algorithm that I've put into the game. Let's say the player buys a water placible map object from the store and the map object occupies 5x5 tiles for instance. I need to guide the player to a free patch of water tiles where they can place that map object. Any guidance and or reference to such algorithms will be highly appreciated ) Thanks EDIT It turns out that I need to find such a patch as close as possible to given point (centre of viewport for instance). This will improve user experience


GPU Spatial Clustering I have a around 100k points on the screen (that might update). 2D points. The goal is to cluster them into groups, by a constant distance. Meaning, finding groups of points that the distance between them is less than this distance. Instead of drawing those points, a big point will be drawn there with a number on it. The problem is the calculation time. Tried many algorithms on CPU, but didn't get the performances i wished for. I'm trying to find an algorithm to solve this problem in the GPU using WebGL GLSL, when texture contains all my locations. Can be single draw phase or multiple.. as long as i achieve better calculation time than i get with the CPU.


Locust Swarm algorithm for path finding (devour and move on) I need to model a locust swarm that devour food stacks and move on to next stacks. I searched for articles and found few articles. These papers is about optimization applications but I want to convert it to a path finding algorithm to reach multiple targets (like randomly seeded many food stack). Swarm should split when food stack is not enough to feed them( multiple objective problem). How can I do this? x position v velocity vector


How would one determine the length of a path? I have a game that requires each player to move along one specified path. I draw the path using B zier curves. How can I determine the total real (not linear) length of the path and the distance that each player had made? (The distance between the start point and a specified point on the path.) UPDATE The path is represented in a Cartesian plane (2D).


Split a grid into shapes that can be moved back from 4 directions Basically I have 4 grids Left, Right, Top, Bottom. Player can choose each of them and move all the blocks on that grid to the Middle grid to fulfill it, like tetris from 4 directions 0 0 0 0 0 0 (0 is empty, 1 is generated block) 0 0 1 Bottom gt Mid Right gt Mid Top gt Mid Left gt Mid 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 1 gt Win! Generate 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 another game. 0 0 0 1 0 0 1 0 0 The point here is to make sure there is at least 1 way for player to combine all 4 grids. What I've tried so far is generate the right order first (Left Right Top....), then generate all the blocks 1 by 1. When a block is generated, i perfomn a check with the generated order (move all the blocks in Left to Mid, then Right then Top...) to see if its still working, the code is similar to this (left gt right, top gt right gt botttom gt left, top... it doesn't have to be all 4 directions) Random the right direction order. Generate all possible coordinates from all the directions from the path above. Initialize an empty list to store all chosen coordinates. While(!(Generate enough x x block)) Get one coordinate from all possible coordinates if (Perform a check with the right order and the chosen list) Add it into the chosen list. The problem here is a block can be wrong at this point, but it can become right when another block is generated 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 At this point the logic is wrong But if I add 1 more block to the with Top gt Left gt Bottom order. top grid, it'll become right. There is no way to check if the each block is right or wrong without re calculate all the generated blocks logic So i want to ask if there a better way, algorithm to do it.


What are pros and cons of Voronoi shatter? I have seen some Voronoi shatter videos on Youtube. What is your experience with it? What are the pros and cons in time complexity, resource complexity, implementation difficulty...? Does it emulate how a real material would react?


Pathfinding with multiple random paths in a Tower Defense game I thought about random pathfinding for my Tower Defense game. A would not work for my puposes, because I specifically need random pathfinding. Imagine a map with routes, a starting point and a destination. I have multiple routes, which all lead from the starting point to the destination, one way or another. It could look like this Color description red starting point black destination grey route white free space (The numbers are used in the text as a reference to some tiles) I first thought about just calculating the next waypoint randomly, when an entity passes a tile. But that would not work. When an entity passes tile 1 it either can go up or down. When it comes to 2 it can either go down up (relative to it s position) or right. If it goes down up it would go to tile 1, which means that it goes backwards. Bad... I would really like to make it dynamic, but I can t figure out what I can do now. Anyone with ideas or experience in this?


How to implement a hint system for nearby matches (in a Match 3 puzzle game)? Taking Candy Crush as an example In a Match 3 game, how would you figure out which nearby tiles are 1 move away from creating a match? Do you basically have to do it by trial and error on every single possible moves (behind the scenes) to see which resulting matches it would create?


Algorithm to select all cells inside rooms regions I have a 2d game map consisting of several 'rooms' For example, here is a 2D map grid (Brown cells wall tiles) If I click on a tile (that isn't brown), I would like to obtain an array of all the cells in the region that I clicked. (If the region is bounded by brown tiles, otherwise do nothing) For example, there are two regions in the image above, both colored in grey. If I clicked cell (4,4) I would get a 4x5 array of cells starting at (3,3). Does anyone know a good performance efficient algorithm for this? I need to account for non square rooms ideally.


Solving maze without return ability I need to write a program that will solve maze. Maze has graph structure, where each node some room, and edges exits to other rooms Specification We start from a random room. Maze has dead ends, 0 or few exits. We don't know anything about all maze, only the number of current room and list of doors from it. When we enter new room we don't know where we came from (what door from current room leads us back to previous room). We can recognize when we reach exit. Each step we move from current room to some available door from it. If we are at room 6 for example, we can't just jump to begin. It's like robot movement. We know exactly ID of current room. We know ID of each door in current room (not in all maze). We control robot. I looked all known algorithms, but they all require at least additional ability to return to previous room. According to specification we can't use any algorithms that search for shortest path (actually, I don't need the shortest), because we know only about current room. We can't use Left (Right )hand following algorithms, because don't know direction of exits. Probably, the only solution that meets specification is choosing random exit in every room in hope that some time exit will be found... Any suggestion how to solve such maze in more smart way?


Turn based combat AI with multi turn planning My current AI system uses the now very common utility AI. I generate a list of possible actions, I then calculate fitness score for each action and generate a list of possible chains of actions (Move Attack Reload or Use Offensive Ability Leap backwards). The sum of those scores are then sorted and I pick the most (or not, depending on how smart I want the particular AI player to be) appropriate chain to execute. The issue that I've run into though is that I'm having issues with more complex interactions that require multi turn planning. To give an actual example one of my characters got two spells that can deal massive damage when used in the right order. 1) A buff ability that increases target's Mind attribute (cast on self) 2) A powerful spell that deals damage based on your Mind (cast on the enemy) Both of those actions cost a lot of Action Points and so you can't execute them both in one turn. A very obvious combo is to use the buff and then the damage spell, but if both of those actions are available to the AI, then it always chooses to open with the second action. The buff itself, when considered in isolation, produces a very low fitness score. A very obvious idea is to then to allow the AI to build chains of actions for two or even three turns ahead. However, this greatly increases the performance cost as I'd have to use similar heuristics for other players to get at least somewhat reasonable gamestate for the AI to go off of. I would also have to think of a fail safe mechanic for when the player does something unexpected, thus ruining this long term plan. Another idea that I had is to let the designer define interesting combos and have the AI see if it can execute one, but it feels messy and a bit hard to implement with the current generic system. How do the other games do it?


"Solve" a game algorithmically creating bots (and making them smart) EDIT at first I gave a lot of context for this question, explaining why I wanted to create a bot. I'm sorry it distracted people from my "actual" question. My question is pretty simple how does one create a bot for a game ? (Especially... on a mac, if it's possible though I can use a Linux virtual machine if needed). Is it interfaced with the application, or just "watching" the screen and extracting information from it (as if it was taking pictures and analyzing them to get informations such as your HP, your position, etc.) ? Could I use python to code it, or are there specific languages ? The forementioned context Since I started programming, I've wanted to try to create algorithms that would be able to "play" (or even "beat") video games. Many games require only logical choices, more and more complex as the difficulty grows, which seems perfect for algorithms. I currently enjoy the game "Pixel Dungeon" a lot (see here), but it's not always nice to you (and you die. A lot.). A few researches on the internet show that a lot can be achieved just by following simple guidelines. So I figured maybe this would be a good game to try and create bots to play it. In the long term, I would like to let bots play, extract data out of it, and modify my algorithms according to these data. I am really enthusiast about this, but also really novice. (maybe this belongs more to https stackoverflow.com ?)


How to calculate a score algorithm based on elapsed time? I'm trying to calculate an alogirthm based on elapsed time to calculate score based on a music beat. I have the music beat divided into 4 because that's the time measure of that beat. So If the user presses the correct key at the third beat, which is of course when the perfect beat would be, I'd like it to obtain the best score. I've tried doing this score percent(bpmt.elapsed,bpm 3) int scoref(int int1,int int2) return int1 100 int2 bpmt.elapsed being how much time was elapsed between the start of that beat and the time that the user pressed the key and bpm being the total number of milliseconds of that particular beat. Can anyone tell me a better way to do this please? I think it requires more advanced math and it's kind of beyond me.


User Leveling System I've already asked this before, but I just wanna encode this again with a new leveling format. What I want to do is that, the user will gain exp and once they leveled up, their previous experience will be added to their current exp. So, to put it in a Scenario it goes like this User1 is on a Level 1 with an exp needed of 1000 to reach level 2. He gained an exp of 1000, so he is now on level 2 with a current exp of 1000 and an exp needed of 1,400. Or if User1 gained an exp of 1,100 he is on level 2 with a current exp of 1,100 and 1,400 exp needed. And so on, depending on the algorithm. But I get a result of 900 1,400 if the user gains 1,100 exp. Here is the code below while( user gt curr exp gt user gt exp needed) user gt curr exp ( user gt exp needed) user gt prev exp user gt prev exp user gt exp needed if( user gt level lt 19) user gt exp needed user gt prev exp 1.4 elseif( user gt level gt 20 amp amp user gt level lt 39) user gt exp needed user gt prev exp 1.1 elseif( user gt level gt 40 amp amp user gt level lt 59) user gt exp needed user gt prev exp 1.05 elseif( user gt level gt 60 amp amp user gt level lt 79) user gt exp needed user gt prev exp 1.04 elseif( user gt level gt 80 amp amp user gt level lt 99) user gt exp needed user gt prev exp 1.03 elseif( user gt level 100) user gt exp needed user gt exp needed 0 user gt level 1 user gt save() Any ideas how to deal with this? Thanks.


Algorithm for querying linearly through a non linear list of questions For a multiplayers trivia game, I need to supply my users with a new quizz in a desired subject (Science, Maths, Litt. and such) at the start of every game. I've generated about 5K quizzes for each subject and filled my database with them. So my 'Quizzes' database looks like this ID Subject Question 23 Science What's water? 42 Maths What's 2 2? 99 Litt. Who wrote "Pride and Prejudice"? 123 Litt. Who wrote "On The Road"? 146 Maths What's 2 2? 599 Science You know what's cool? 1042 Maths What's the Fibonacci Sequence? 1056 Maths What's 42? And so on... (Much more detailed complex but I'll keep the exemple simple) As you can see, due to technical constraints (MongoDB), my IDs are not linear but I can use them as an increasing suite. So far, my algorithm to ensure two users get a new quizz when they play together is the following Take the last played quizzes by P1 and P2 var q one player one.getLastPlayedQuizz('Maths') var q two player two.getLastPlayedQuizz('Maths') If both of them never played in the subject, return first quizz in the list if ((q one NULL) amp amp (q two NULL)) return QuizzDB.findOne( subject 'Maths' ) If one of them never played, play the next quizz for the other player This quizz is found by asking for the first quizz in the desired subject where the ID is greater than the last played quizz's ID (if the last played quizz ID is 42, this will return 146 following the above example database) if (q one NULL) return QuizzDB.findOne( subject 'Maths', ID gt q two ) if (q two NULL) return QuizzDB.findOne( subject 'Maths', ID gt q one ) And if both of them have a lastPlayedQuizz, we return the next quizz for the player whose lastPlayedQuizz got the higher ID if (q one gt q two) return QuizzDB.findOne( subject 'Maths', ID gt q one ) else return QuizzDB.findOne( subject 'Maths', ID gt q two ) Now here comes the real problem Once I get to the end of my database (let's say, P1's last played quizz in 'Maths' is 1056, P2's is 146 and P3 is 1042), following my algorithm, P1's ID is the highest so I ask for the next question in 'Maths' where ID is superior to 1056. There is nothing, so I roll back to the beginning of my quizz list (with a random skipper to avoid having the first question always show up). P1 and P2's last played will then be 42 and they will start fresh from the beginning of the list. However, if P1 (42) plays against P3 (1042), the resulting ID will be 1056...which P1 already played two games ago. Basically, players who just "rolled back" to the beginning of the list will be brought back to the end of the list by players who still haven't rolled back. The rollback WILL happen in the end, but it'll take time and there'll be a "bottleneck" at the beginning and at the end. Thus my question What would be the best algorith to avoid this bottleneck and ensure players don't get stuck endlessly on the same quizzes? Also bear in mind that I've got some technical constraints I can't get a random question in a subject (ie no "QuizzDB.findOne( subject 'Maths' ).skip(random()) "). It's cool to skip on one to twenty records, but the MongoDB documentation warns against skipping too many documents. I would like to avoid building an array of every quizz played by each player and find the next non played in the database with a nin. Thanks for your help


How to generate Bayer matrix of arbitrary size? In ordered dithering Bayer matrix is used. How is that matrix generated? What algorithm can be used to generate matrix of arbitrary size?


Algorithm that cover one mesh by another mesh Suppose I have two meshes (Let call me first MeshShirt and second MeshBody) Meshes are aligned (if i render both MeshShirt "covers" MeshBody). But some parts of the body are not "under" the MeshShirt (because MeshShirt shape differs from MeshBody) How can i "pull up" parts of MeshShirt which are under MeshBody and hold other parts in their places? Of course i want save shape of MeshShirt if it possible I think about following algorithm mark all points of MeshShire which under MehsBody by tracing intersection of its normals and MeshBody. But if MeshShirt "hidden" parts have complex shape normal tracing will not work. So some way to detect bad points is needed move every marked point to the plane of its nearest triangle of MeshBody. But i afraid that these algoritm may produce significant deformation of MeshShirt. So some shape preserved deformation is needed too. Sorry for my poor English and fuzzy problem definition


Creating blur with an alpha channel, incorrect inclusion of black I'm trying to do a blur on a texture with an alpha channel. Using a typical approach (two pass, gaussian weighting) I end up with a very dark blur. The reason is because the blurring does not properly account for the alpha channel. It happily blurs in the invisible part of the image, whcih happens to be black, and thus results in a very dark blur. Is there a technique to blur that properly accounts for the alpha channel?


Prevent collisions between mobs npcs units piloted by computer AI How to avoid mobile obstacles? Lets says we have character a starting at point A and character b starting at point B. character a is headed to point B and character b is headed to point A. There are several simple ways to find the path(I will be using Dijkstra). The question is, how do I take preventative action in the code to stop the two from colliding with one another? case2 Characters a and b start from the same point in different times. Character b starts later and is the faster of the two. How do I make character b walk around character a without going through it? case3 Lets say we have m such characters in each side and there is sufficient room to pass through without the characters overlapping with one another. How do I stop the two groups of characters from "walking on top of one another" and allow them pass around one another in a natural organic way. A correct answer would be any algorithm, that given the path to the destination and a list of mobile objects that block the path, finds an alternative path or stops without stopping all units when there is sufficient room to traverse.


How does Hierarchical Pathfinding deal with obstructions in the same chunk? Aigamedev.com provides this visualization of HPA All the nodes within the same chunk connect to each other. What if there was an obstruction between nodes in the same chunk? For example What would the resulting visualization look like with an obstruction in the center bottom left chunk? How would this be detected?


Low CPU Memory Memory bandwith Pathfinding (maybe like in Warcraft 1) Dijkstra and A are all nice and popular but what kind of algorithm was used in Warcraft 1 for pathfinding? I remember that the enemy could get trapped in bowl like caverns which means there were (most probably) no full path calculations from "start to end". If I recall correctly, the algorithm could be something like this A) Move towards enemy until success or hitting a wall B) If blocked by a wall, follow the wall until you can move towards the enemy without being blocked and then do A) But I'd like to know, if someone knows ) edit As explained to Byte56, I'm searching for a low cpu mem mem bandwidth algo and wanted to know if Warcraft had some special secrets to deliver (never seen that kind of pathfinding elsewhere), I hope that that is more concordant with the stackexchange rules.


Non perfect maze generation algorithm I want to generate a maze with the following properties The maze is non perfect. Means it has loops and multiple ways to reach the exit. The maze should be random. The algorithm should output different mazes for different input parameters The maze doesn't have to be braided. Means dead ends are allowed and appreciated. I just can't find the right resources on google. The closest i found was this description of the different types of algorithms http www.astrolog.org labyrnth algrithm.htm. All other algorithms were for perfect mazes. Can anyone give me a website where i can look this up or maybe an algorithm directly?


How to implement auto aiming auto targeting We all know how auto aiming or auto targeting works in games. Now, I need to find how to implement it in my game. In fact I should implement it in UDK and I would be glad if anyone gave me more specific explanation for UDK. But conceptual explanation is also enjoyable and I'll implement it myself in my way.


Team matchmaking based on ELO score I'm looking for a very simple way to put up 2 teams out of unspecified amount of players. So its not actually a standard matchmaking since it only creates one match out of the whole pool of queued players. I do have pretty much only single variable and it is the ELO score for each player, which means it's the only available option to base calculations on. What I thought of is just simply go through every possible combination of a players(4 in each team) and the lowest difference between the average ELO of teams is the final rosters that get created. But it would be the most unoptimized way to do that. So I decided to ask a question in here, maybe you can help me with that in some way.


How to compute the area of an irregular shape? I have a room object defined by a collection of looping line segments that I need to calculate the area for. The classes can be described as follows (in pseudo code) class Point float x float y ... float distanceFrom(Point p) class Segment Point start Point end ... float length() class Room List lt Segment gt walls ... float area() The walls of a room can never intersect anywhere but at the endpoints of the segments and any "sub loops" created will also be separated into a new room. The solution does not need to be perfectly accurate (10 margin of error is acceptable) and is also not computed very often ( lt 1 s).


How can I calculate an octree node's depth from its location code? The article Advanced Octrees 2 node representations states The AABB (axis aligned bounding box) of the node can be stored explicitly as before, or it can be computed from the node s tree depth stored implicitly inside the locational code. To derive the tree depth at a node from its locational code a flag bit is required to indicate the end of the locational code. Without such a flag it wouldn t be possible to distinguish e.g. between 001 and 000 001. By using a 1 bit to mark the end of the sequence 1 001 can be easily distinguished from 1 000 001. Using such a flag is equivalent to setting the locational code of the Octree root to 1. The book Real Time Collision Detection, Volume 1 by Christer Ericson states The size of a node can be explicitly stored or it can be derived from the "depth" of the locational code. In the latter case, a sentinel bit is required in the locational code to be able to distinguish, say, 011 and 000000011, turning these into 1011 and 1000000011, respectively. Both offer the following algorithm for computing the depth of a node int node depth(unsigned int key) for (int d 0 key d) if (key 1) return d key gt gt 3 assert(false) How and why does this work? The location code is a 32 bit word. That is, ... 011 and ... 000 011 might be equal, depending on what the remaining bits of the first location code are. using a sentinel, one has ... xx1 011 and ... xx1 000 011 and now they are different location codes. What I don't understand is how can I get the depth of the nodes from the location codes and how does the sentinel help me with that. Going back to the example above, ... xx1 011 and ... xx1 000 011, these words could be ... 000 001 011 and ... 000 001 000 011, respectively. Both cases have the sentinel bit, but since 001 (and any other xx1 combination) is a valid triple, all triples are valid, and there is no way for me to tell what the depth of the nodes is. The only solution I've found is to store the depth of the node next to the location code, but that article and the book seem to indicate that the depth can be derived from the location code somehow.


which is the best approach or algorithm to calculate real time ranking I want to know the fastest and most efficient way to compute points and ranking in real time. I'm doing a betting football game (a game where users try to predict the outcome of a game before it). In my country is called "Quiniela". Players put "predictions" just before the match starts. My question is from the moment the game starts, which is the most efficient way (not just code level but to the database and server) to calculate the ranking for the players "real time" as their predictions regarding the actual outcome of the game. For example If a Team1 vs Team2 plays, the user U1 predicted that the game would end 0 0, U2 predicted the game would end 1 0, U3 predicted the game would would end 1 1. When starting the game, the U1 would be to first in the ranking because, if the match ends like this, his prediction would be correct, or at least the most accurate. Then the score switches to 1 0, and the user U1 would be the last of the ranking (because his prediction is not possible anymore), U2 would be the first and U3 second. If the score changes to 1 1, U2 would go first, U3 would be second (because he guessed part of the result) and U3 last. I thought about creating a tree of possibilities with one level (0 0 first node, with 1 0 and 0 1 as child nodes) as you change the score, changes the Ranking "temporarily" and I would keep it in cache. Once the game is over, I keep the latest Ranking in the database. There is a more optimal way to solve this problem? It has been proposed before and already solved? I'm using MySQL for database, PHP (Cake Php) for the server and a bunch of mobiles who ask for the ranking once in a while.


How can I generate a terrain heightmap from the perlin algorithm? How can I generate a terrain heightmap from the perlin algorithm? I am trying to make a terrain generator (like World Machine). This is the source code I have for the perlin. The only thing that I can't figure out is how to use the perlin algorithm to generate a heightmap image.


Algorithm for spreading labels in a visually appealing and intuitive way Short version Is there a design pattern for distributing vehicle labels in a non overlapping fashion, placing them as close as possible to the vehicle they refer to? If not, is any of the method I suggest viable? How would you implement this yourself? Extended version In the game I'm writing I have a bird eye vision of my airborne vehicles. I also have next to each of the vehicles a small label with key data about the vehicle. This is an actual screenshot Now, since the vehicles could be flying at different altitudes, their icons could overlap. However I would like to never have their labels overlapping (or a label from vehicle 'A' overlap the icon of vehicle 'B'). Currently, I can detect collisions between sprites and I simply push away the offending label in a direction opposite to the otherwise overlapped sprite. This works in most situations, but when the airspace get crowded, the label can get pushed very far away from its vehicle, even if there was an alternate "smarter" alternative. For example I get B label A label C label where it would be better ( label closer to the vehicle) to get B label label A C label EDIT It also has to be considered that beside the overlapping vehicles case, there might be other configurations in which vehicles'labels could overlap (the ASCII art examples show for example three very close vehicles in which the label of A would overlap the icon of B and C). I have two ideas on how to improve the present situation, but before spending time implementing them, I thought to turn to the community for advice (after all it seems like a "common enough problem" that a design pattern for it could exist). For what it's worth, here's the two ideas I was thinking to Slot isation of label space In this scenario I would divide all the screen into "slots" for the labels. Then, each vehicle would always have its label placed in the closest empty one (empty no other sprites at that location. Spiralling search From the location of the vehicle on the screen, I would try to place the label at increasing angles and then at increasing radiuses, until a non overlapping location is found. Something down the line of try 0 , 10px try 10 , 10px try 20 , 10px ... try 350 , 10px try 0 , 20px try 10 , 20px ...


What could I use to search tiles in a game I'm creating a tile based game similar to Minesweeper. When a user clicks on a tile and its not a mine or a number space I need to search and expose the adjacent tiles that are empty and stop when it hits a number or the edge of the board. I have it working right now so that it will clear the row of the tile clicked and stop at a numbered tile or the edge of the board. What I have is going to get ugly quickly and I am sure there is a easier way of doing this. Is there a searching algorithm I can use that will find all adjacent tiles to the one the player click only stopping once it hits the edge of the board or hit a numbered tile?


Why is my bullet disappearing after I release the shoot button? I'm making a game using DirectXTK for my university project. When I press space bullet moves forward like I wanted, but when I let go it stops my bullet from moving. How do I keep the bullet moving when space was pressed? void update shooting if (kb.Space) Shoot(true) else Shoot(false) void Render() if (draw) for (int i 0 i lt 10 i ) m projectile i gt Draw(m bullet i , m view, m proj, Colors Red) bool shoot(bool test) shoot test draw true bool isShot false if (!shoot) for (int i 0 i lt 10 i ) m bullet i Matrix CreateRotationY(m ship. 42) m ship else m bullet 0 Matrix CreateTranslation( Vector3 Forward float(1)) Matrix CreateRotationY(0.f) m bullet 0 m bullet Matrix CreateTranslation( Vector3 Forward) return draw


Static evaluation function for Checkers using Minimax I have correctly implemented Minimax for my checkers AI till depth of 3 ( well at least that is what I think ). However I am confused on evaluating my game boards at depth 3 with heuristics. Currently I just check ( no of blacks no of reds ) for my heuristics but then it gives duplicate values ( Tie Breaker ) for most of the game boards. I researched and found that in that case we can assign values to each position on the game board ( found on this link here here and add it to the heuristic. But how is it implemented exactly and how are those board values chosen? And do I have to apply it for each of my recursion or just at the top level for all the branch nodes? here is my code. int MaxMove(TreeNode currNode, int depth, List lt TreeNode gt pathNodes) if (depth 0) return StaticEvaluationFunction(currNode,depth) else depth int v 10000 List lt TreeNode gt allPossRedMoveNodes gameBoardScript.createNewRedBoardsFromCurrent(currNode.getCurrentBoard()) TreeNode bestNode null foreach (TreeNode RedNode in allPossRedMoveNodes) int v1 MinMove(RedNode, depth, pathNodes) if (v1 gt v) v v1 bestNode RedNode if the heuristic is equal then add the board piece values to the current heuristic ( I AM NOT SURE IF THIS IS CORRECT ) else if( v1 v) v1 RedNode.getBoardMove().getMovedToPiece().getTieBreakerValue() v v1 return v int MinMove(TreeNode currNode, int depth, List lt TreeNode gt pathNodes) if (depth 0) return StaticEvaluationFunction(currNode, depth) else depth int v 10000 List lt TreeNode gt allPossBlackMoveNodes gameBoardScript.createNewBlackBoardsFromCurrent(currNode.getCurrentBoard()) TreeNode bestNode null foreach (TreeNode BlackNode in allPossBlackMoveNodes) int v1 MaxMove(BlackNode, depth,pathNodes) if (v1 lt v) v v1 bestNode BlackNode when priorities are equal else if (v1 v) v1 BlackNode.getBoardMove().getMovedToPiece().getTieBreakerValue() v v1 return v private int StaticEvaluationFunction(TreeNode node, int depth) return node.getHeuristic() Black Red count at the last depth


Backtracking in A Star Hello, can anyone tell me how can i implement backtracking in a a star search algorithm? I've implemented the a star search according to wiki, but it does not backtrack, what i mean by backtrack is that if the open list(green cells) contains 2,0 and 3,3 as shown in the picture, upon reaching 2,0 the current node would "jump" to 3,3 since the cost is now more than 3,3 and continue the search from there, how can it be done so that it would backtrack from 2,0 2,1 2,2... all the way back to 3,3 and continue?


The best algorithm enhancing alpha beta? I'm studying AI. My teacher gave us source code of a chess like game and asked us to enhance it. My exercise is to improve the alpha beta algorithm implementing in that game. The programmer already uses transposition tables, MTD(f) with alpha beta memory (MTD(f) is the best algorithm I know by far). So is there any better algorithm to enhance alpha beta search or a good way to implement MTD(f) in coding a game?


Raycast algorithm fails to collide with diagonal walls in specific locations I'm having a problem with my ray cast algorithm in a 2D tile based universe. I feel the situation would be best explained with a picture, so here it is The ray, represented by the blue line, is passing "through" the wall to hit its target when the wall passes through a point where the quantized line moves diagonally and the wall is perpendicular to it. The raycast function is as such def raycast(pos, direction, level) dx, dy direction t 0 x, y pos obj None while not obj and t lt 5000 t 1 x dx y dy obj level.get at((round(x),round(y)),True) pass return obj Is there a simple, efficient way to eliminate this kind of edge case?


Algorithm for constructing the corners of a regular, n sided polygon I've googled this using a lot of keyword combinations, but to my great surprise I could not find an algorithm for constructing a regular, n sided polygon into a given circle, i.e., finding the coordinates for the n corner points. All I could find were instructions how to do it by physical compass and straightedge, or interactive browser plug ins without source. So where could I find such an algorithm?


Random enemy generation algorithm help I've been working on a program for my friends to use for a homebrewed roleplay system that we all use for our campaigns that can generate random enemy statlines with certain constraints. The program accepts a list of the statlines of the players, and then the user inputs a number that denotes a percentage of the player characters that this unit can beat on average in a 1v1. The issue I'm struggling with here is that combat involves different formulas for determining hit rate, critical hit rate, and damage The formulas I have to deal with are Physical damage strength enemy defense damage (multiplied by 2 if user's speed is 5 greater than enemy's) Magical damage magic enemy resistance damage (multiplied by 2 if user's speed is 5 greater than enemy's) Hit rate base hit floor(user dex 3) floor(user luck 5) enemy dodge rate hit rate (will always have a minimum of 5 ) Dodge rate base dodge floor(user speed 4) 2 floor(user luck 5) dodge Critical hit rate 5 floor((user dex enemy luck) 5) crit bonus critical hit rate (hit system is based on singular d20 with critical hit rate equivalent to number range on d20 that's considered a critical hit, meaning a 5 hit chance with a 5 or greater critical hit rate will result in every hit being a critical hit) I've been struggling to think of an algorithm that can generate enemy statlines based on these formulas as well as the percentage constraint but I have no idea how to go about it in a way that isn't just bruteforcing it until I get a desirable outcome. I've toyed around with ideas such as ranking the inputting players based on their damage, survivability, dodge hit, and determining upper lower bounds on stats to work with but the issue I have is trying to establish a relationship formula between each stat to make sure that when I tweak one stat, I can change the others accordingly while staying within the user defined constraints. EDIT After some thinking, I did come up with one possible solution, that being first determining the upper and lower bounds for the statline based on player stats, generating a random statline in between those bounds, and then generating tables that determine what effect on player and enemy DPS incrementing decrementing a stat will have, and using that to precisely tweak enemies. The only issue with this solution is that for very high diverse player stat values, this can take a long time, as well as figuring out a way to determine which stat to increment decrement in the algorithm.


Swept AABB vs Line Segment in 2D I've been trying to get a swept collision detection up and running now for almost a week and I can't for the life of me get it working. There is a answer on this linked here below Swept AABB vs Line Segment 2D I've translated this into Go which will be running the game server and needs this logic func SweepRectLine(rectX, rectY, rectW, rectH, rectHSpeed, rectVSpeed, lineX1, lineY1, lineX2, lineY2 float64) (bool, float64) outVel 2 float64 hitNormal 2 float64 lineNX, lineNY lineX2 lineX1, lineY2 lineY1 lineMinX, lineMaxX, lineMinY, lineMaxY math.Min(lineX1, lineX2), math.Max(lineX1, lineX2), math.Min(lineY1, lineY2), math.Max(lineY1, lineY2) var lineMinX, lineMaxX, lineMinY, lineMaxY float64 if lineNX gt 0 lineMinX, lineMaxX lineX1, lineX2 else lineMinX, lineMaxX lineX2, lineX1 if lineNY gt 0 lineMinY, lineMaxY lineY1, lineY2 else lineMinY, lineMaxY lineY2, lineY1 r (rectW 2) math.Abs(lineNX) (rectH 2) math.Abs(lineNY) radius to Line boxProj (lineX1 rectX) lineNX (lineY1 rectY) lineNY velProj rectHSpeed lineNX rectVSpeed lineNY if velProj lt 0 r 1 hitTime math.Max((boxProj r) velProj, 0) outTime math.Min((boxProj r) velProj, 1) log.Println( quot start quot , hitTime, outTime) rectXMax, rectXMin rectX rectW 2, rectX rectW 2 if rectHSpeed lt 0 left if rectXMax lt lineMinX return false, 0 hitTime math.Max((lineMaxX rectXMin) rectHSpeed, hitTime) outTime math.Min((lineMinX rectXMax) rectHSpeed, outTime) else if rectHSpeed gt 0 right if rectXMin gt lineMaxX return false, 0 hitTime math.Max((lineMinX rectXMax) rectHSpeed, hitTime) outTime math.Min((lineMaxX rectXMin) rectHSpeed, outTime) log.Println( quot right quot , hitTime, outTime) else if lineMinX gt rectXMax lineMaxX lt rectXMin return false, 0 if hitTime gt outTime return false, 0 rectYMax, rectYMin rectY rectH 2, rectY rectH 2 if rectVSpeed lt 0 up if rectYMax lt lineMinY return false, 0 hitTime math.Max((lineMaxY rectYMin) rectVSpeed, hitTime) outTime math.Min((lineMinY rectYMax) rectVSpeed, outTime) else if rectVSpeed gt 0 down if rectYMin gt lineMaxY return false, 0 hitTime math.Max((lineMinY rectYMax) rectVSpeed, hitTime) outTime math.Min((lineMaxY rectYMin) rectVSpeed, outTime) else if lineMinY gt rectYMax lineMaxY lt rectYMin return false, 0 if hitTime gt outTime return false, 0 outVel 0 rectHSpeed hitTime outVel 1 rectVSpeed hitTime return true, hitTime I also put up a Gist with a executable UI here https gist.github.com KidLinus 3f847c46b0e6dc1addac7252d9cb54ab I can't for the life of me figure out what all class variables stand for. I think that some of them are native to Unity but that's just a guess. I've come so far as to figure out that the extent is half of the width height in said direction. What the quot line.n quot stands for is anyones guess, I assume its the direction and have no idea if it's normalized or not. There are also a couple of dead variables just laying there.


Space nebula cloud generation? I found a cool kickstarter project called "Skywanders". It's an minecraft like space game with a lego like building system and pretty cool graphics. One thing I noticed are the "nebula clouds". They are procedurally generated 3D Objects and they look amazing. How do I generate such nebulas? I bet there's a way to do that. And is it possible to convert a 2D nebula into a 3D one? I didn't found any algorithm yet or other sources.


Mafia kill algorithm I'm making an Omerta clone mafia game and trying to work out a kill algorithm. Just a basic formula to decide how many bullets player A needs to kill player B. The inputs are players rank (out of 10), and a players kill skill (out of 100). The algorithm needs to return how many bullets are needed for that player to win. If you're shooting someone a higher rank, or higher kill skill, it should require more bullets. Anyone ever done anything like this and can offer some tips? Example chart


Integrating specular, diffuse reflection and refraction I am implementing an MLT bidirectional path tracer. I have a problem integrating diffuse, specular reflection and refraction. 1) The first problem is diffuse and specular reflection. Diffuse reflection is done by sampling ray in a hemishere. But specular reflection is done by finding the ray that have an angle to the normal equal to the incident ray with the normal. However, an object can have both diffuse and specular reflection. When to use specular reflection or diffuse reflection for a ray? 2) Same as the first question but this time integrating reflection with refraction. I've seen a few research papers and websites online where the scene have specular, diffuse reflection and refraction, but they have no tutorial on how to do this.


How to calculate area to fill in this Snake Qix game variant? I have a game which is a Snake Qix variant. The player controls a line which is moving on an island. Player has possibility to leave the island in order to connect that island to itself. Once the connection is made, the new area formed by the connection becomes part of the island (see picture red line is the path the snake has made while outside the island, dark red pixels are the area island). I am trying to find a algorithm (even bruteforce) how to fill the new area (in other words how to do transition between first and second line on the picture). What I have in mind is to run a path finding algorithm between the enter exit points. If there is a path, it means the snake connect the island to itself. The path (in green) and red line together forms a closed polygon which can then be filled (how ?) As it is now, the data is simply defined a 2D array of pixels (eg 0 empty, 1 island, 2 player snake)


How do people implement pathfinding movement? I understand how A works, but I don't understand how movement is implemented, e.g. creating a list of directions and then going through that list until every direction is empty. How does that work? EDIT Node based.


How can I develop a Lights Out solving algorithm? I am programming the game that named Lights Out. The purpose of this game is turning all the lights out. There's a flash version of the game here. I want to develop a way of solving the game. How can I do this?


What algorithm can I use to detect simple shapes in a 4x4 matrix? I'm working on a simple multiplayer game that receives a random 4x4 matrix from a server and extracts a shape from it. For example XXOO OXOO XXOX XXOO XOOX and XOOO XXXX OXXX So in the first matrix the shape I want to parse is oo o oo and the 2nd oo oo ooo I know there must be an algorithm for this because I saw this kind of behavior on some puzzle games but I have no idea how to go about to detecting them or even where to start. So my question is How do I detect what shape is in the matrix and how do I differentiate between multiple colors? (it doesn't come only in X and O, it comes in a maximum of 4). Additionally, the shape must be a minimum of 4 blocks.


How control probability of win lose in tile matching games? In a random puzzle game, such as a match three game, how can you control the probability of a winnable starting condition?


Filling in gaps in a grid I have a set of terrain sprites available to represent terrain Flat North South Straight Cliff (x 2 allowing for slope direction either way) West East Straight Cliff (x 2 allowing for slope direction either way) Convex North West Cliff Convex North East Cliff Convex South East Cliff Convex South West Cliff Concave North West Cliff Concave North East Cliff Concave South East Cliff Concave South West Cliff There source for my terrain is a height map that I am looking to represent with contours made up from above sprites. The cliff tiles would be placed on the below threshold tiles that border the above threshold ones. However when I split the height map by threshold I get terrain features that are impossible to represent with the tile set, for example ..... ... 1 1 1 ... ... 0 0 0 ... ... 1 1 1 ... ..... Where 1's represent tiles that are above the threshold and 0 tiles are below. My sprite set lacks the tile to represent either immediate neighbors (in this case North and South neighbors) being above threshold. I am looking for a good approach to get rid of these cases. I have already tried just looping through all columns rows looking for 1 0 1 combinations and changing the height map value to be above the threshold. In the end, I don't really mind the way the "gaps" are filled in, as long as the end result can be represented with my tile set. Remember cases with diagonal gaps must be considered. For example ..... ... 0 0 1 ... ... 0 0 0 ... ... 1 0 0 ... ..... Also cannot be represented with my tiles set. Finally, I'm also looking for a scalable solution to this problem. If I require to use and even more restrictive tile set that requires 1 (0 x n) 1 gaps to be filled in, as in the two above threshold tiles can be n below threshold tiles away from each other. P.S. Apologies for my previous poorly worded question.


Dynamic Tilemap size changer I have started coding this project using the library SFML a few months ago. I have implemented a random map generation everytime I load the game thanks to Biome and the Perlin noise Algorithm. I wish i could increase the TileMap size on the border of the map according to the player position (Chunk system in minecraft) . I have managed to do it on the bottom and the right of the map But this isn't dynamic. There is a snap of my code where i add a new "chunck" void TileMap AddChunckToTileSet(sf Vector2i PlayerTile, char direction) int previousWidth width int previousHeight height height height 24 width width 24 m vertices.resize( width height 4) int tileNumber 384 ToDO on en d duit sa position dans la texture du tileset int tu tileNumber (m tileset.getSize().x tileSize.x) int tv tileNumber (m tileset.getSize().x tileSize.x) if (direction "Down") for (int i previousWidth i lt width i) for (int j previousHeight j lt height j) on r cup re un pointeur vers le quad d finir dans le tableau de vertex sf Vertex quad amp m vertices (i j width) 4 on d finit ses quatre coins quad 0 .position sf Vector2f((i previousWidth) PlayerTile.x tileSize.x, j tileSize.y) quad 1 .position sf Vector2f(((i previousWidth) PlayerTile.x 1) tileSize.x, j tileSize.y) quad 2 .position sf Vector2f(((i previousWidth) PlayerTile.x 1) tileSize.x, (j 1) tileSize.y) quad 3 .position sf Vector2f((i previousWidth) PlayerTile.x tileSize.x, (j 1) tileSize.y) on d finit ses quatre coordonn es de texture quad 0 .texCoords sf Vector2f(tu tileSize.x, tv tileSize.y) quad 1 .texCoords sf Vector2f((tu 1) tileSize.x, tv tileSize.y) quad 2 .texCoords sf Vector2f((tu 1) tileSize.x, (tv 1) tileSize.y) quad 3 .texCoords sf Vector2f(tu tileSize.x, (tv 1) tileSize.y) I call the function AddChunckToTileSet like this void TileMap Update(sf Vector2i PlayerTile) if (PlayerTile.y 15 gt height) Increase map on Down according to our X printf("Add Chunck Down n") AddChunckToTileSet(PlayerTile, "Down") Do you have any hints on how I could achieve this correctly ?


How to implement view bobbing? I'm developing a First Person shooter game. Everything is just fine but I've a little problem with my camera moving. My FPS camera is moving smoothly! But the camera should move like a human is walking and his head is doing up and down. Now I'm stuck! So what kind of algorithm can I use for that purpose? Any kind of help is appreciated.


Room Detection on a Tilemap I am working on a 2D top down game inspired by Prison Architect. What I just can't wrap my head around is recognizing rooms built by the player. The game is built on a tilemap, meaning the map is always a rectangle, while the rooms can be of any shape. I'd like to be able to detect whenever walls amp doors create a new wall, like in the example below. Since I have no formal education in CS (yet), I can't think of any algorithm or class of algorithms that might be of use here and also can't figure out one by myself. So if you have any ideas, suggestions or resources, I'd be very thankful! In case this is relevant, I am using a custom implementation of a tilemap using Monogame, a reimplementation of XNA and Nez.


How can I divide a 3D mesh into small pieces? I'm considering a manufacturing game. A player should assemble parts of an object in given time. The object will be a 3D mesh model. I want to automatically split the 3D mesh into many small pieces to be provided to players. Each divided piece is needed to have area as similar as possible. And I want to control the number of pieces too within range about 2 6. How can I do this? I know the method to modify a given mesh like adjusting values of vertices, indices. All I need is the algorithm.


Algorithm for chase by multiple enemies If I have one enemy that should chase the player, I can use a path finding algorithm such as BFS to find the shortest path from the enemy to the player (taking into account obstacles along the way), and advance the enemy along the path. But if there are two enemies, this is not necessarily the most efficient strategy. For example, if there is a large obstacle, instead of both enemies chasing the player from the east, it may be more efficient for tnem to cooperate, one of them should go chase the player from the east while the other blocks the player's escape route from the west. My question is what is an algorithm for efficiently coordinating the chase behavior of two enemies?


Generating random values, keep trying till value within bounds are generated Sorry for the strange topic name, couldn t think of a good way to describe it. I m basically trying to achieve the following I'm placing items randomly on the screen, but these items shouldn't be placed near eachother at a given distance. This is the process I have in my head right now generate a random location check if this location is not near any other objects it is near start the process over to generate a new item (till it is not near anymore) I've run into this scenario multiple times but could never think of a way to efficiently do this, while I do feel that there is a simple way to do it. Here is the implementation I have right now. I feel like I should use a while loop but I can't get my around how to do it. The code is in AS3 but that shouldn't matter. public function generatePlanetsFromXML(xml XML) void planets new Array() for (var i int 0 i lt xml.projects.project.length() i ) var planet Planet new Planet() planet.data xml.projects.project i planet.radius (Math.random() 20) 20 addChild(planet) addObject(planet) planets.push(planet) calculatePlanetLocation(planet, i) private function calculatePlanetLocation(planet Planet, i int) void var randomX int (Math.random() (worldwidth planet.width)) 20 var randomY int (Math.random() (worldheight planet.height)) 20 get a location that isn't close to another planet keep looping till the distance is higher than minimum distance for (var j int 0 j lt planets.length j ) if (i ! j) var dx int planets j .x randomX var dy int planets j .y randomY var distance int Math.sqrt((dx dx) (dy dy)) if (distance lt minPlanetDistance) trace("retry getting location..") planet.alpha 0.3 calculatePlanetLocation(planet, i) else distance is fine, planet can be placed! planet.x randomX planet.y randomY else if (i 0) first planet should always be placed planet.x randomX planet.y randomY


Need help creating points in an array I'm creating a lightning geometry shader using hlsl that creates an array of points based on an arbitrary number of generations. The gist of what I want to accomplish is here http drilian.com 2009 02 25 lightning bolts The problem is the fact that the pseudo code uses a dynamic array which deletes the current generations line segment and then resizes to add new line segments. I can only use fixed sized arrays in hlsl. My current code is as stands int generations 4 int pointsarraysize pow(2, generations) 1 float3 points pointsarraysize points 0 startpoint points pointsarraysize 1 endpoint for(int currentgeneration 0 currentgeneration lt genetations currentgeneration) for(int i 0 i lt pointsarraysize i) if (i pow(2, currentgeneration)) So what i've got creates an array of the size of points I want to end up with and sets the start point and end point. How do I fill the array so that each iteration over the array creates the points in the right place in the array? I can't simply iterate linearly and calculate points depending on the index position because calculating, for example, the first point in an array with 4 generations requires the start point point 0 and a generation 3 point, point 2 . Is this even the best way to fill the array or am I missing something that could simplify the problem? I want to be able to change the number of generations rather than hard coding a certain amount.


Logic behind a bejeweled like game In a prototype I am doing, there is a minigame similar to bejeweled. Using a grid that is a 2d array (int , ) how can I go about know when the user formed a match? I only care about horizontally and vertically. Off the top of my head I was thinking I would just look each direction. Something like int item grid x,y if(grid x 1,y item) int step x int matches 2 while(grid step 1,y item) step matches if(matches gt 2) remove all matching items else if(grid x 1,y item .... else if(grid x,y 1 item) ... else if(grid x,y 1 item) ... It seems like there should be a better way. Is there?


Detecting a sequence of nodes in a grid Given the image below, I need to detect the most optimal sequence on the board (the green line). The blue red lines represent possible, but not the best moves. Here are the rules You can move to any tile that is the same, and is your neighbor (diagonal is valid) Once you have visited a tile, you can't visit it again. I have thought about looping through each node, and looking at its neighbors, then recursively going through. Once I find a possible move I can put it into a structure. Once all possible moves are found I just pick the move with the highest count of node. It becomes more difficult when a node has more than one neighbor that matches. So, is there some algorithm that I can use? I was thinking some sort of flood fill, but that doesn't meet rules 2. As requested, here is a video of similar gameplay. http youtube.com watch?v eumnCTG0AE8


Finding equivalent axial coordinates for a wrapping hexagonal map of radius n I'm creating a wrap around hexagonal map that will potentially render infinatly. With the method I'm using, I have an x y coordinate I use to find it's equivalent axial coordinate with the equations Q (sqrt(3) 3 x 1. 3 y) hexSize R (2. 3 y) hexSize the problem is, my map is of radius n and it's possible for the Q R coordinate to be far outside that radius. How can I find the equivalent Q R coordinate within the radius n? I know methods for a single radius outside, but I'm talking the potential of having a radius of 15 but a Q R something like (9999999,99999999). What would that coordinate be in relation to the center of the 15 radius hex region it'd be in?


Better streaming economy algorithm? Does anyone here have experience making games with streaming economies? I am working on a game and am looking for a better way to handle the economy. I feel like there must be a better algorithm than what I am using. Background ResourceBin objects contain resources Settlement objects contain ResourceBin objects Settlement objects have three queues of Building objects in arrays (Low, Medium, and High priorities) Building objects have a nextTick() method that accepts a ResourceBin and modifies it Right now on every tick the Settlement class will loop through all of the Building arrays starting with High and working towards Low. On each Building object it calls the nextTick() method and passes its ResourceBin. After making sure that the transforms won't cause any Resource to become negative, the nextTick() method modifies the ResourceBin and exits. If any of its transformations would cause a Resource to become negative it just exits. The issue with this is that the entire system depends heavily on the order in which the buildings are processed. I also can't have it proportionally affect the resource transformations if you are low on resources (like what is done in Total Annihilation). Does anyone know how other games implement streaming economies? Is there a better way to do this? Also let me know in the comments if a code example would be useful. I can pastebin one if need be.


How should a circuit or power system (like redstone in Minecraft) be implemented I want to implement a power system like the redstone system in minecraft. I have n power sources and m cables. If I disconnect the power source or a cable the circuit should turn off. How do I avoid circles? If each cable with the status "on" powers the nearby cables I can create infinite circles where there is no power source involved (see image). Plus site is that it runs in T m I could send power burst through the graph starting at every power source and in each update call I turn every cable off. Problem is it runs in T n m. Is there a best practice? In Minecraft the redstone system was very slow so I think I overlooked something. EDIT The system should work without a distance based decay.


3 in a row or more logic This is a bit more difficult than it seems and the one other post on here isn't sufficient. You have a row of n items, and each item could be any one of 5 colors. You need to find if there are any runs of 3 or more items together of the same color and destroy them. Yellow, Red, Blue, Green, Red, Red destroy nothing Red, Red, Red, Green, Yellow, Red destroy the first set of 3 Red, but not the 6th red Red, Purple, Red, Red, Red, Red destroy only the set of 4 Red You can't simply check each item to see if the item previous to it has the same color, and destroy them when that happens twice in a row (meaning 3 matching items), because then you are not accounting for the fact that there could be 4 or more in a row. Are there any robust algorithms out there for this?


Algorithm for generating a 2d maze What algorithm have you used in the past to generate a simple 2d maze?


What's the best way to deal with platformer tile collisions? I am starting with game development and creating a basic platformer game. I already have searched a lot and found some ways to implement the platformer aspect to the game, like apply a gravity, velocity and so on. Everything is good, but always when I implement a way to deal with the collisions, a bug appears. If I fix it, it appears at other side, etc. The main problem is when the player intersects a tile and I need push him up back. The most simple way that I found is this player.Y tile.Y player.height The most problems comes when you also need verify the X axis, the player is pushed out from the tile, or it is thrown at other tile position, like this issue I had when trying to implement the XNA Platformer Example. Or even pass through the tiles if you are going too fast. After some research I found a good way to avoid all this problems instead of move the player to the next position and deal with the tiles to push him back, calculate a safe distance and move the player following this. The "safe distance" is for example, the player.Y player.Velocity.Y, but if any tile is at the way, the safe distance is decreased to the player don't enter in the tile. I read this excelent article and it's what is said about the algoritm The total movement of the player along that direction is then the minimum between the distance to closest obstacle, and the amount that you wanted to move in the first place. Move player to the new position. With this new position, step the other coordinate, if still not done. So, the best way is use the "safe distance" method?