*/
#include "alife.h"
-#include <QtCore/qdatetime.h>
+#include <QDateTime>
#include <KDebug>
+#include <KRandom>
#define VIRUS_GENOME_SIZE 38
#define MAX_AGE 8
//create the needed viruses so that we have in total "amount" viruses
void Alife::createViruses(int amount){
for(int i = m_livingCells.size(); i < amount; i++) {
- int x = rand() % m_width;
- int y = rand() % m_height;
+ int x = KRandom::randomMax(m_width);
+ int y = KRandom::randomMax(m_height);
struct cell *temp = &m_cells[x][y];
//cell already alive
//initial code
for(int i = 0; i < 7; i++) {
- temp->code[i] = rand()%12;
+ temp->code[i] = KRandom::randomMax(12);
}
- temp->code[rand()%7] = 7; //cheating, jumpstart evolution
+ temp->code[KRandom::randomMax(7)] = 7; //cheating, jumpstart evolution
/*temp->code[0] = 4;
temp->code[1] = 12;
//REMINDER: Update if a new op is added
uchar Alife::randomCode()
{
- return rand() % 20;
+ return KRandom::randomMax(20);
}
//Executes the code of a certain living cell
stop = true;
break;
case 1://random value
- reg = rand() % 4;
+ reg = KRandom::randomMax(4);
break;
case 2: //change direction
facing = reg & 3;
//give a unfair advantage to darker places
int prob = (((qRed(color) + qGreen(color) + qBlue(color))/ 255.)+1);// 0 - 765
- if(rand() % prob != 0){
+ if(KRandom::randomMax(prob) != 0){
return false;
}
memcpy(newCell->code,cell->code,VIRUS_GENOME_SIZE);
- int mutate = rand() % 3;
+ int mutate = KRandom::randomMax(3);
if(mutate) {
//normal mutation
- int mutations = rand() % 5;
+ int mutations = KRandom::randomMax(5);
for(int i = 0; i < mutations; i++) {
- int index = rand() % VIRUS_GENOME_SIZE;
+ int index = KRandom::randomMax(VIRUS_GENOME_SIZE);
newCell->code[index] = randomCode();
}
- int duplication = rand() % 3;
+ int duplication = KRandom::randomMax(3);
for(int i = 0; i < duplication; i++) {
- int start = rand() % VIRUS_GENOME_SIZE;
- int end = start + rand() % ( VIRUS_GENOME_SIZE - start);
+ int start = KRandom::randomMax(VIRUS_GENOME_SIZE);
+ int end = start + KRandom::randomMax( VIRUS_GENOME_SIZE - start);
memcpy(&newCell->code[end],&cell->code[start],VIRUS_GENOME_SIZE - end);
}
- int deletion = rand() % 3;
+ int deletion = KRandom::randomMax(3);
for(int i = 0; i < deletion; i++) {
- int start = rand() % VIRUS_GENOME_SIZE;
- int end = start + rand() % ( VIRUS_GENOME_SIZE - start);
+ int start = KRandom::randomMax(VIRUS_GENOME_SIZE);
+ int end = start + KRandom::randomMax( VIRUS_GENOME_SIZE - start);
memcpy(&newCell->code[start],&cell->code[end],VIRUS_GENOME_SIZE - end);
memset(&newCell->code[end], 0, VIRUS_GENOME_SIZE - end);
}