示例#1
0
 /**
  * A recursive function that converts a string into a genotype.
  *
  * @param g The current node.
  * @param s The string (array to pass by reference).
  * @return The filled node.
  */
 private Genotype decodeString(Genotype g, String[] s) {
   char in = s[0].charAt(0);
   if (in == ';') {
     s[0] = s[0].substring(1);
     return null;
   }
   int token = Integer.parseInt(s[0].substring(0, 2));
   int amount = Integer.parseInt(s[0].substring(2, 4));
   if (g != null) g.token = new Token(TokenMap.get(token), amount);
   else g = new Genotype(new Token(TokenMap.get(token), amount));
   s[0] = s[0].substring(4);
   g.left = decodeString(g.left, s);
   g.right = decodeString(g.right, s);
   return g;
 }
示例#2
0
 private void tryMutate(Genotype g) {
   if (Random.getRandom(1, 100) <= TBedford_Robot.mutationChance) g.token = new Token(true);
   if (g.left != null) tryMutate(g.left);
   if (g.right != null) tryMutate(g.right);
 }