Assignment - More Randomness

Hi Filip and everyone else!

I have found a bug in your code. It was not an issue years ago, but now it is.

The problem is in Breeding function in this part of the code (loop):

for(i = 1; i <= 128; i=i*2){

          /* We are */
          if(random & i != 0){
              geneArray[index] = uint8(Mumgenes % 100);
          } else {
              geneArray[index] = uint8(Dadgenes % 100);
          }
          Mumgenes /= 100;
          Dadgenes /= 100;
          index -= 1;

The problem is the last line:

index -= 1;

Now the issue is underflow. You reduce the index and on the last iteration, it goes 0=0-1, which is not possible nowadays.

A few years ago (I can see you coded in pragma solidity 0.5.0) you could go underflow. However today in pragma solidity 0.8.17 underflow and overflow are fixed and it will revert a function. No exact errors are given so I had to debug it and realized that this is the problem. It can cause some serious pain to newbies. I hope this will help new students.

Solution: replace the index -=1 with this:

          if (index == 0) {
              break;
          }
          else {
              index--;
          }

Peace!