protected int checkForDraw() {
    //db.a(includeImages,"Rules checkForDraw: with no images included");

    //db.a(boardImagesStored > 0, "Rules checkForDraw: no board images stored");

//		db.pr("Rules: stag count is "+stagnateCount);

    // Check for stagnation.
    if (stagnateCount == maxStagnationMoves * 2 - 1) {
      return STATE_DRAWNSTAG;
    }

    int currBoard = (boardImagesStored - 1) * boardImageLength;

    // Compare this board image with those that came before to see if it
    // repeats.

    int repCount = 0;

    int compBoard = currBoard;
    while (true) {
      // examine only those positions for the current player.
      compBoard -= boardImageLength * 2;

      if (compBoard < 0) {
        break;
      }

      // Compare last int first, since it contains the checksum.
      int i;
      for (i = boardImageLength - 1; i >= 0; i--) {
        if (boardImages[compBoard + i] != boardImages[currBoard + i]) {
          break;
        }
      }

      if (i >= 0) {
        continue;
      }

      repCount++;
      if (repCount == repeatCountForDraw) {
        return STATE_DRAWNREP;
      }
    }

//		boardRepCount = repCount;

    if (
        maxMovesPerGame != 0
        && moveNumber == maxMovesPerGame
        ) {
      return STATE_DRAWNMAXMOVES;
    }

    return STATE_PLAYING;
  }