Unit.java
// Mate method that averages the genes, and then randomizes the gender

Mate method that averages the genes, and then randomizes the gender
Mate method that averages the genes and then randomizes the gender
public Unit mate(Unit o) {
          int newstr;
          int newsp;
          int newl;
          int stmutate = (int)(Math.random()*10);
          int spmutate = (int)(Math.random()*10);
          int lmutate = (int)(Math.random()*10);
          if (this.strength > o.strength)
               newstr = (int)(Math.random()*(this.strength - o.strength))+o.strength;
          else if (this.strength < o.strength)
               newstr = (int)(Math.random()*(o.strength - this.strength))+this.strength;
          else
               newstr = this.strength;
          if (this.speed > o.speed)
               newsp = (int)(Math.random()*(this.speed - o.speed))+o.speed;
          else if (this.speed < o.speed)
               newsp = (int)(Math.random()*(o.speed - this.speed))+this.speed;
          else
               newsp = this.speed;
          if (this.longevity > o.longevity)
               newl = (int)(Math.random()*(this.longevity - o.longevity))+o.longevity;
          else if (this.longevity < o.longevity)
               newl = (int)(Math.random()*(o.longevity - this.longevity))+this.longevity;
          else
               newl = this.longevity;
          if (stmutate == 0)
               newstr += (int)(Math.random()*5);
          if (spmutate == 0)
               newsp += (int)(Math.random()*5);
          if (lmutate == 0)
               newl += (int)(Math.random()*5);
          boolean newg;
          int r = (int)(Math.random()*2);
          if (r==0)
               newg = true;
          else
               newg = false;
          Unit child = new Unit(newstr,newsp,newl,newg);
          return child;
     }
public Unit mate ( Unit o ) { int newstr ; int newsp ; int newl ; int stmutate = ( int ) ( Math . random ( ) * 10 ) ; int spmutate = ( int ) ( Math . random ( ) * 10 ) ; int lmutate = ( int ) ( Math . random ( ) * 10 ) ; if ( this . strength > o . strength ) newstr = ( int ) ( Math . random ( ) * ( this . strength - o . strength ) ) + o . strength ; else if ( this . strength < o . strength ) newstr = ( int ) ( Math . random ( ) * ( o . strength - this . strength ) ) + this . strength ; else newstr = this . strength ; if ( this . speed > o . speed ) newsp = ( int ) ( Math . random ( ) * ( this . speed - o . speed ) ) + o . speed ; else if ( this . speed < o . speed ) newsp = ( int ) ( Math . random ( ) * ( o . speed - this . speed ) ) + this . speed ; else newsp = this . speed ; if ( this . longevity > o . longevity ) newl = ( int ) ( Math . random ( ) * ( this . longevity - o . longevity ) ) + o . longevity ; else if ( this . longevity < o . longevity ) newl = ( int ) ( Math . random ( ) * ( o . longevity - this . longevity ) ) + this . longevity ; else newl = this . longevity ; if ( stmutate == 0 ) newstr += ( int ) ( Math . random ( ) * 5 ) ; if ( spmutate == 0 ) newsp += ( int ) ( Math . random ( ) * 5 ) ; if ( lmutate == 0 ) newl += ( int ) ( Math . random ( ) * 5 ) ; boolean newg ; int r = ( int ) ( Math . random ( ) * 2 ) ; if ( r == 0 ) newg = true ; else newg = false ; Unit child = new Unit ( newstr , newsp , newl , newg ) ; return child ; }
Mate method that averages the genes, and then randomizes the gender
Mate method that averages the genes and then randomizes the gender
// Strength genes
 // Speed genes
 // Longevity genes
 // Mutators
