Hot answers tagged

6

The easiest way is giving a variable "conected = false" to every electric item and then, starting from a energy source, do the following: function adjacents(tile){ return [ getTile(tile.x-1,tile.y-1), getTile(tile.x,tile.y-1), getTile(tile.x+1,tile.y-1), getTile(tile.x-1,tile.y), tile, getTile(tile.x+1,tile.y), ...


5

As Vector57 noted, the problem is you are using the wrong coordinate system. The algorithm described is meant to be used with cube coordinates, which have x, y and z components: This may not be obvious from the algorithm's pseudocode, but that's because it's a simplification of this: var results = [] for each -N ≤ dx ≤ N: for each -N ≤ dy ≤ N: ...


4

First of all, for uniformly distributed data, Knuth’s function i * 2654435761 >> 16 is definitely better than i * 2654435761 >> 8 because it shuffles more bits. An explanation follows. Consider the multiplication of numbers WXYZ and PQRS (all these letters representing arbitrary digits in any base) and see how the digits get added together in ...


3

D* Lite if you want AI that behaves in the way that a human might when exploring a completely new and unknown area, needing no prior knowledge of the map except for the coordinates of start and goal, and which can adapt to a changing map. This algorithm is both conceptually simpler and more efficient than the original D*, effectively obsoleting D*. It's been ...


3

Prison Architect uses "pieces" of cables, it is not all one long cable, it is a sum of lots of "pieces" (or squares, not sure how to define it): Image here (The bright green conected pieces are cables) I don´t know how they do it, and I bet they are not going to tell us, but I can tell you how I would do it. Assign each "piece" of cable an state (an ...


2

So upon further inspection your problem actually has nothing to do with coordinate system conversions. This could have been made more clear by not naming your axial coordinates X and Y but rather Q and R. The problem you're actually having is bad loop conditions. The original code sample produces delta q's and r's which you try to convert, in your for loops, ...


2

As people have said in comments section, A* or (AStar) is a viable algorithm for this, and a good waypoint. Here you have a generic AStar implementation in Java so you can start with something. Please, ask if you have any question. import java.util.*; public class AStar { public static class PriorityList extends LinkedList { public void ...


2

I understand you also had problems drawing a line from point to point. I recommend you look into "Bresenham's Line Algorithm" as it typically gives the best result. Here is a Wikipedia article about it. The article includes pseudocode for the algorithm, including one that only relies on integer arithmetic. I won't be posting it here as I encourage you to ...


1

You're not getting the angles properly, the sum of the internal angle of a simple polygon can be calculated with the formula: π(n-2). We then need the external angle which is the angle from point to point, this can be calculated with : π-internalAngle. Assuming the first point is in the lower left and there's no rotation this code should work. void ...



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