'2D array - making it "torus" like
I am facing following problem:
I have a board of size MxN squares. In Java, what is the best way to make it such that when there are coordinates given which are out of bounds (or with negative values), it will return square from the other side of the board? I am looking for some cleaver use of math. Probably modulus operator, but I'd like it to work for negative values. How to do it right?
For example:
when M = N = 10
//Pseudocode of course
int[10][10] board
//Counting elements from 0, so 10 would normally generate array OOB exception
//I want it to work like this:
board[-1][10] == board[9][0]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
