/** * calculate destination location given from location and a distance. PRECONDITION: distance is in * range 1..6. PRECONDITION: from is not a bear off location. * * @param p the color of the player * @param from the location to move from * @param distance the distance to move * @return location where a checker will land given color, from location, and a distance. */ public static Location findLocation(Color p, Location from, int distance) { int _to; if (from == Location.B_BAR) { _to = distance; } else if (from == Location.R_BAR) { _to = 25 - distance; } else { _to = from.index + p.getSign() * distance; } if (_to <= 0) { _to = Location.R_BEAR_OFF.index; } else if (_to >= 25) { _to = Location.B_BEAR_OFF.index; } Location to = indexToEnum[_to]; return to; }