Tests About Natural Selection In Virtual Environment
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

genome.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. Copyright (C) 2011 Weber Yann, Schuck Clement
  3. This file is part of Tansive.
  4. Tansive is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Tansive is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Tansive. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef _GENOME_H
  16. #define _GENOME_H
  17. #include<stdlib.h>
  18. #include<stdio.h>
  19. #include"config.h"
  20. /*
  21. genome.h :
  22. Define struct, constantes and function for creature's genome management.
  23. */
  24. //what does the creature eat
  25. #define GNOME_VEGAN 1
  26. #define GNOME_CARNI 2
  27. //Various genome caracteristic's limit
  28. #define GNOME_MIN_WEIGHT 0
  29. #define GNOME_MAX_WEIGHT 100
  30. #define GNOME_MAX_STRENGHT 100
  31. #define GNOME_MIN_LIFE 10
  32. #define GNOME_MAX_LIFE 100
  33. #define GNOME_MIN_SPEED 2
  34. #define GNOME_MAX_SPEED 6
  35. #define GNOME_MAX_ENERGY 100
  36. #define GNOME_MAX_AGGRESSION 100
  37. #define GNOME_MAX_PERCEP 10
  38. #define GNOME_MAX_LIFETIME 500
  39. #define GNOME_MIN_LIFETIME 100
  40. #define GNOME_MIN_NBCHILD 1
  41. #define GNOME_MAX_NBCHILD 5
  42. #define GNOME_MIN_REPROFREQ 10
  43. #define GNOME_MAX_REPROFREQ 100
  44. //Memorie limits
  45. #define GNOME_MAX_MEM_SIZE 100
  46. #define GNOME_MEMORYCAP_FOOD 1
  47. #define GNOME_MEMORYCAP_DANGER 2
  48. #define GNOME_MEMORYCAP_TARGET 4
  49. #define GNOME_MEMORY_ELTTYPE_FOOD 1
  50. #define GNOME_MEMORY_ELTTYPE_DANGER 2
  51. #define GNOME_MEMORY_ELTTYPE_TARGET 3
  52. #define GNOME_MEMORYTYPE_RAND 1
  53. #define GNOME_MEMORYTYPE_BOUCLE 2
  54. #define GNOME_MEMORYTYPE_INT 3
  55. //Mutation constants
  56. #define GNOME_MUTATION_CHANCE 500
  57. #define GNOME_MUTATION_MIN 3
  58. #define GNOME_MUTATION_MAX 10
  59. #define GNOME_MUTATION_GNOM_MODIF 10
  60. //Name limits
  61. #define GNOME_MAX_NAMESIZE 10
  62. #define GNOME_MIN_NAMESIZE 3
  63. //Store one element of memorie
  64. typedef struct _t_mem_element
  65. {
  66. char type;//take value in GNOME_MEMORYTYPE_*
  67. int x;
  68. int y;
  69. }t_mem_element;
  70. //Represent the memory of the creature
  71. typedef struct _t_memory
  72. {
  73. t_mem_element* mem;
  74. }t_memory;
  75. /*
  76. This structure defined the caracteristics of a creature
  77. */
  78. typedef struct _t_genome
  79. {
  80. int weight; //take value in [0..GNOME_MAX_WEIGHT]
  81. int strenght; //take value in [0..GNOME_MAX_STRENGHT]
  82. int life; //take value in [0..GNOME_MAX_LIFE]
  83. int speed; //take value in [0..GNOME_MAX_SPEED]
  84. int energy; //take value in [0..GNOME_MAX_ENERGY]
  85. int aggression; //take value in [0..GNOME_MAX_AGGRESSION]
  86. int perception; //take value in [0..GNOME_MAX_PERCEPT]
  87. int lifetime; //take value in [GNOME_MIN_LIFETIME..GNOME_MAX_LIFETIME]
  88. int nbchild; //take value in [GNOME_MIN_NBCHILD..GNOME_MAX_NBCHILD]
  89. int reprofreq; //take value in [GNOME_MIN_REPROFREQ..GNOME_MAX_REPROFREQ]
  90. char mem_capabilities;
  91. char mem_type;
  92. char mem_size;
  93. char food; //take value in GNOME_VEGAN or GNOME_CARNI
  94. char* name;
  95. //Stats about the genome
  96. unsigned long nb_creat;
  97. unsigned long nb_nat_dead;
  98. unsigned long nb_star_dead;
  99. unsigned long nb_figt_dead;
  100. unsigned long nb_eat_dead;
  101. }t_genome;
  102. //Store a node of a genome tree
  103. typedef struct _t_tree_genome
  104. {
  105. struct _t_tree_genome* parent;
  106. struct _t_tree_genome** child;
  107. unsigned long nb_child;
  108. t_genome gnome;
  109. }t_tree_genome;
  110. //Generate a random genome
  111. t_genome rand_genome();
  112. //Return a genome with mutations
  113. t_genome mutation(t_genome orig);
  114. //Add a child to a node
  115. t_tree_genome* add_child_treegnome(t_tree_genome* t, t_tree_genome* child);
  116. //Initialize a node with a genome
  117. t_tree_genome* create_new_gnometree_node(t_genome gnome);
  118. //Print the genome tree on stdout
  119. void disp_genome_tree_info(t_tree_genome* t, char eq_zero);
  120. //Write the genome tree in graphviz's format on file
  121. void write_graphviz_genome_tree(FILE* file, t_tree_genome* t);
  122. //Return a random char, vowel or consonant
  123. char rand_char(char type);
  124. //return a random name
  125. char* rand_name();
  126. //return !(rand()%proba)
  127. char calc_proba(int proba);
  128. #endif