I am working on a 2d arcade game where I have 5 types of circles with different sizes: The ship, the missiles, and 3 types of monsters.  This is what it looks like:    Currently I'm using brute force collision detection where I check every missile vs. every monster without taking probability of collision into account. Sadly, this makes the process REALLY slow.  This here is my Grid class, but it's incomplete. I'd greatly appreciate your help.      public class Grid {      int rows;     int cols;     double squareSize;     private ArrayList&lt;Circle&gt;[][] grid;      public Grid(int sceneWidth, int sceneHeight, int squareSize) {         this.squareSize = squareSize; // Calculate how many rows and cols for the grid.         rows = (sceneHeight + squareSize) / squareSize;         cols = (sceneWidth + squareSize) / squareSize; // Create grid         this.grid = (ArrayList[][]) new ArrayList[cols][rows]; //Generic array creation error workaround     }  The addObject method inside the Grid class.     public void addObject(Circle entity) { // Adds entity to every cell that it's overlapping with.         double topLeftX = Math.max(0, entity.getLayoutX() / squareSize);         double topLeftY = Math.max(0, entity.getLayoutY() / squareSize);         double bottomRightX = Math.min(cols - 1, entity.getLayoutX() + entity.getRadius() - 1) / squareSize;         double bottomRightY = Math.min(rows - 1, entity.getLayoutY() + entity.getRadius() - 1) / squareSize;          for (double x = topLeftX; x &lt; bottomRightX; x++) {             for (double y = topLeftY; y &lt; bottomRightY; y++) {                 grid[(int) x][(int) y].add(entity); //Cast types to int to prevent loosy conversion type error.             }         }     }   But that's where I am at a complete loss. I'm not even sure the source code I provided is correct. Please let me know how to make the grid based collision work. I've read basically every tutorial I could get my hands on but without much effect.  Thanks.
Up until now, I implemented all-against-all collision detection in my games. It worked fine.  But I reached a point where implementing this kind of collision detection, makes the game run poorly, because there are two many objects to iterate through and check for collision.  I have searched this site and found something about 'uniform grids'. But I didn't completely understand what it is and how to implement it. Tried to Google it but nothing easy enough to understand came up.  I am a beginner to 2D-game programming. Do you mind trying to explain to uniform-grids, or link me to some good tutorial?  Thanks a lot
Do there exist general conditions under which we can conclude that continuity on a topological space is detected by $\mathbb{R}$? Whenever $X$ is a topological space, let us say that continuity on $X$ is detected by $\mathbb{R}$ iff for all functions $f : X \rightarrow Y$ where $Y$ is another topological space, we have that if every continuous function $c : \mathbb{R} \rightarrow X$ satisfies "$f \circ c$ is continuous", then $f$ is itself continuous.   Clearly, continuity on $\mathbb{R}$ is detected by $\mathbb{R}$ It is shown  that continuity on $\mathbb{R}^2$ is detected by $\mathbb{R}$. Clearly, it is not the case that continuity on $\mathbb{Q}$ is detected by $\mathbb{R}$, since every continuous mapping $\mathbb{R} \rightarrow \mathbb{Q}$ is constant.      Question. Do there exist general conditions underwhich we can conclude that continuity on a topological space is detected by $\mathbb{R}$? I've been reading through a lot of the rookie Java questions on finalize() and find it kind of bewildering that no one has really made it plain that finalize() is an unreliable way to clean up resources.  I saw someone comment that they use it to clean up Connections, which is really scary since the only way to come as close to a guarantee that a Connection is closed is to implement try (catch) finally.    I was not schooled in CS, but I have been programming in Java professionally for close to a decade now and I have never seen anyone implement finalize() in a production system ever.  This still doesn't mean that it doesn't have its uses, or that people I've worked with have been doing it right.  So my question is, what use cases are there for implementing finalize() that cannot be handled more reliably via another process or syntax within the language?    Please provide specific scenarios or your experience, simply repeating a Java text book, or finalize's intended use is not enough, as is not the intent of this question. Find the number of ways in distributing $8$ distinct balls into $6$ distinct boxes such that there is at least $1$ ball in each box.  We are well acquainted with the traditional Inclusion-Exclusion principle in solving this and it will come up as $191520$ ways.  I tried in this way:  When we distribute $8$ balls into $6$ boxes we have two possible cases  Case $1.$ There are exactly $2$ boxes with $2$ balls each  Case $2.$ There is exactly $1$ Box with $3$ balls in it.  For Case $1$, the distribution is done by choosing $2$ boxes from $6$ boxes and $2$ balls from $8$ balls and those two balls can be arranged in $2!$ ways. But I require another two balls from remaining $6$ balls to be placed in each of these two boxes which can be done in $\binom{6}{2} \times 2!$ ways. Finally remaining $4$ balls can be distributed in remaining $4$ boxes in $4!$ ways. So total number of ways for Case $1.$ is  $$\binom{6}{2} \times \binom{8}{2} \times 2! \times \binom{6}{2} \times 2! \times 4!=604800$$  For Case $2$, the number of ways is  $$\binom{6}{1} \times \binom{8}{3} \times 5!=40320$$  I am pretty sure the value obtained for Case $2.$ is correct. but I could not find where I went wrong in Case $1.$ I want to advance in the ranks of Senator Lavigny-Duval. How can I get merit points? I know I can participate in expansion goals, but is there a better way than that? Can a US citizen leave and enter the US using a foreign passport? Prove $2^b-1$ does not divide $2^a + 1$ for $a,b>2$ I'm trying to prove $2^b-1$ does not divide $2^a + 1$ for $a,b&gt;2$. Can someone give a hint in the right direction for this? I've heard that i can travel to the US any time before my tourist visa expiry.  Is that true?  (please advise) EJB Transactions in local method-calls In the following setup, does method B run in a (new) transaction?  An EJB, having two methods, method A and method B  public class MyEJB implements SessionBean     public void methodA() {        doImportantStuff();        methodB();        doMoreImportantStuff();     }      public void methodB() {        doDatabaseThing();     } }   The EJB is container managed, with methodB in requires_new transaction, and method A in required transaction. thus:  &lt;container-transaction id="MethodTransaction_1178709616940"&gt;   &lt;method id="MethodElement_1178709616955"&gt;     &lt;ejb-name&gt;MyName&lt;/ejb-name&gt;     &lt;method-name&gt;*&lt;/method-name&gt;   &lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;   &lt;/method&gt;   &lt;method id="MethodElement_1178709616971"&gt;     &lt;ejb-name&gt;MyName&lt;/ejb-name&gt;     &lt;method-name&gt;methodB&lt;/method-name&gt;   &lt;/method&gt;   &lt;trans-attribute&gt;RequiresNew&lt;/trans-attribute&gt; &lt;/container-transaction&gt;   Now let another EJB call methodA with an EJB method call. methodA now runs in an transaction. Will the subsequent call to methodB from methodA run in the same transaction, or does it run in a new transaction? (mind, it's the actual code here. There is no explicit ejb-call to method B) Why is variance squared? I have added a background image to the world settings. However, it has disappeared from my 3D view and only shows when I view the scene from the camera. Does anyone know if there is something I can do to make it reappear? I bought a new MacBook Air and was able to connect to the internet at first but now it won't connect.  I have other devices as well as other computers on wifi but my Mac won't connect.  When I try and click on the wifi, it tells me that it can't be joined.  How can I troubleshoot? Is it fair to buy a return ticket I know I will never use just because it's cheaper? In sysctl, the /proc/sys/net/ipv[46]/conf/ keys have the following subkeys: all, default, and a key for each network interface. For example, on a machine with a single network interface eth0, it will look like this:  iserv ~ # ll /proc/sys/net/ipv[46]/conf/ /proc/sys/net/ipv4/conf/: insgesamt 0 dr-xr-xr-x 0 root root 0 12. Sep 23:30 all/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 default/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 eth0/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 lo/  /proc/sys/net/ipv6/conf/: insgesamt 0 dr-xr-xr-x 0 root root 0 12. Sep 23:30 all/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 default/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 eth0/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 lo/   All the respective settings exist in each key separately. For example, if I want to disable IPv6 Router Advertisements with the accept_ra value, this value exists four times:  iserv ~ # sysctl -a 2&gt;/dev/null | grep "accept_ra " net.ipv6.conf.all.accept_ra = 1 net.ipv6.conf.default.accept_ra = 1 net.ipv6.conf.lo.accept_ra = 1 net.ipv6.conf.eth0.accept_ra = 1   My question now is: which of these values do I need to change? I figured all (to change all existing interfaces) and default (to change all new interfaces that may appear later), but changing these still leaves the value at 1 for lo and eth0:  iserv ~ # sysctl -w net.ipv6.conf.all.accept_ra=0 net.ipv6.conf.all.accept_ra = 0 iserv ~ # sysctl -w net.ipv6.conf.default.accept_ra=0 net.ipv6.conf.default.accept_ra = 0 iserv ~ # sysctl -a 2&gt;/dev/null | grep "accept_ra "   net.ipv6.conf.all.accept_ra = 0 net.ipv6.conf.default.accept_ra = 0 net.ipv6.conf.lo.accept_ra = 1 net.ipv6.conf.eth0.accept_ra = 1   Will the machine now accept Router Advertisements on eth0, or will it not? What's the opposite word for "sin"? I would like to know if there is an opposite word for sin in English.  I mean, how could I say the opposite of     I committed a sin   other than using a negation? "...his parents' dream of *him* achieving a Cambridge degree." What is the function of "him" here? I have a problem analysing this sentence from the point of finite/nonfinite clauses, clause elements and their functions:     He does not want to destroy his parents' dream of him achieving a Cambridge degree.   I am especially interested in the: dream of him achieving a Cambridge degree.  I know that 'achieving a Cambridge degree' is a non-finite -ing participle clause. However what is its function? And what is the function of 'of him'? Is it a postmodification? 9 pirates have to divide 1000 coins... A band of 9 pirates have just finished their latest conquest - looting, killing and sinking a ship. The loot amounts to 1000 gold coins.  Arriving on a deserted island, they now have to split up the loot. You, as the captain of the band, have to propose a distribution plan (who gets what). What's your proposal?  Consider that this bunch is a democratic lot. If your proposal is accepted by half of the group, then everybody adheres to it. However, if folks feel you are getting greedy, and less than half of the band agrees to your proposal, then they kill you, and then your First Mate gets to make a proposal. And so it goes in decreasing order of hierarchy/seniority. When to use RSA and when ElGamal asymmetric encryption How to run a program on a remote pc via command line? How can I run a program on a remote Windows PC in our network without the need of killing an existing remote-desktop-connection? I only need a command line for running the program and getting its results. Thank you! iMac disk partion FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF and fusion drive unlinked GSC: How to move a site from a domain to sub domain, sub folder or new domain with a sub folder? Is it possible to tell Google's Webmaster Tools that our site hosted on www. has moved to a sub folder, sub domain or a new domain with sub folder?