- /* Bounds check for locations
- */
- if ( valgame.chloc < -1 || valgame.chloc > NLOCATIONS ||
- valgame.chloc < -1 || valgame.chloc > NLOCATIONS ||
- valgame.loc < -1 || valgame.loc > NLOCATIONS ||
- valgame.newloc < -1 || valgame.newloc > NLOCATIONS ||
- valgame.oldloc < -1 || valgame.oldloc > NLOCATIONS ||
- valgame.oldloc < -1 || valgame.oldloc > NLOCATIONS) {
- return false;
- }
- /* Bounds check for location arrays
- */
+ /* Prevent division by zero */
+ if (valgame.abbnum == 0) {
+ return false; // LCOV_EXCL_LINE
+ }
+
+ /* Check for RNG overflow. Truncate */
+ if (valgame.lcg_x >= LCG_M) {
+ valgame.lcg_x %= LCG_M; // LCOV_EXCL_LINE
+ }
+
+ /* Check for RNG underflow. Transpose */
+ if (valgame.lcg_x < LCG_M) {
+ valgame.lcg_x = LCG_M + (valgame.lcg_x % LCG_M);
+ }
+
+ /* Bounds check for locations */
+ if ( valgame.chloc < -1 || valgame.chloc > NLOCATIONS ||
+ valgame.chloc2 < -1 || valgame.chloc2 > NLOCATIONS ||
+ valgame.loc < 0 || valgame.loc > NLOCATIONS ||
+ valgame.newloc < 0 || valgame.newloc > NLOCATIONS ||
+ valgame.oldloc < 0 || valgame.oldloc > NLOCATIONS ||
+ valgame.oldlc2 < 0 || valgame.oldlc2 > NLOCATIONS) {
+ return false; // LCOV_EXCL_LINE
+ }
+ /* Bounds check for location arrays */