Fix fitness function bug (hopefully)
The shader rounds to the nearest color when rendering, sometimes it rounds up. I made it only round down,
This commit is contained in:
parent
c281026b53
commit
fc0840d79d
2 changed files with 12 additions and 12 deletions
|
|
@ -34,10 +34,10 @@ void main(void)
|
||||||
|
|
||||||
// encode to rgba channels in current pixel
|
// encode to rgba channels in current pixel
|
||||||
vec4 col = vec4(0.0, 0.0, 0.0, 1.0);
|
vec4 col = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
// total = total/200.0;
|
// total = total/255.0;
|
||||||
col.r = mod(total, 256.0/255.0);
|
col.r = floor(mod(total*255.0, 256.0))/255.0;
|
||||||
col.g = mod(total/256.0, 256.0/255.0);
|
col.g = floor(mod(total*255.0/256.0, 256.0))/255.0;
|
||||||
col.b = mod(total/65536.0, 256.0/255.0);
|
col.b = floor(mod(total*255.0/65536.0, 256.0))/255.0;
|
||||||
// color.g = 0.0;
|
// color.g = 0.0;
|
||||||
// color.b = 0.0;
|
// color.b = 0.0;
|
||||||
// color.g = mod(total, 256.0/255.0);
|
// color.g = mod(total, 256.0/255.0);
|
||||||
|
|
|
||||||
|
|
@ -81,10 +81,10 @@ unsigned long long Fitness::of(Chromosome chr)
|
||||||
for (unsigned int y=0; y<size.y; ++y) {
|
for (unsigned int y=0; y<size.y; ++y) {
|
||||||
sf::Color col = image.getPixel(0, y);
|
sf::Color col = image.getPixel(0, y);
|
||||||
// std::cout<<(int)col.r<<"|"<<(int)col.g<<"|"<<(int)col.b<<"|"<<(int)col.a<<std::endl;
|
// std::cout<<(int)col.r<<"|"<<(int)col.g<<"|"<<(int)col.b<<"|"<<(int)col.a<<std::endl;
|
||||||
fitness += ((unsigned long int)col.r); // 2^(8*0)
|
fitness += ((unsigned long long)col.r); // 2^(8*0)
|
||||||
fitness += ((unsigned long int)col.g)*256; // 2^(8*1)
|
fitness += ((unsigned long long)col.g)*256; // 2^(8*1)
|
||||||
fitness += ((unsigned long int)col.b)*65536; // 2^(8*2)
|
fitness += ((unsigned long long)col.b)*65536; // 2^(8*2)
|
||||||
// fitness += (unsigned int)col.a*16777216; // 2^(8*3)
|
// fitness += (unsigned long long)col.a*16777216; // 2^(8*3)
|
||||||
// col = image.getPixel(1, y);
|
// col = image.getPixel(1, y);
|
||||||
// fitness += col.r*4294967296; // 2^(8*4)
|
// fitness += col.r*4294967296; // 2^(8*4)
|
||||||
// fitness += col.g*1099511627776; // 2^(8*5)
|
// fitness += col.g*1099511627776; // 2^(8*5)
|
||||||
|
|
@ -95,9 +95,9 @@ unsigned long long Fitness::of(Chromosome chr)
|
||||||
for (unsigned int x=0; x<size.x; ++x) {
|
for (unsigned int x=0; x<size.x; ++x) {
|
||||||
sf::Color col = image.getPixel(x, 0);
|
sf::Color col = image.getPixel(x, 0);
|
||||||
// std::cout<<(int)col.r<<"|"<<(int)col.g<<"|"<<(int)col.b<<"|"<<(int)col.a<<std::endl;
|
// std::cout<<(int)col.r<<"|"<<(int)col.g<<"|"<<(int)col.b<<"|"<<(int)col.a<<std::endl;
|
||||||
fitness += (unsigned long int)col.r; // 2^(8*0)
|
fitness += (unsigned long long)col.r; // 2^(8*0)
|
||||||
fitness += ((unsigned long int)col.g)*256; // 2^(8*1)
|
fitness += ((unsigned long long)col.g)*256; // 2^(8*1)
|
||||||
fitness += ((unsigned long int)col.b)*65536; // 2^(8*2)
|
fitness += ((unsigned long long)col.b)*65536; // 2^(8*2)
|
||||||
// fitness += ((unsigned long int)col.a)*16777216; // 2^(8*3)
|
// fitness += ((unsigned long int)col.a)*16777216; // 2^(8*3)
|
||||||
// col = image.getPixel(x, 1);
|
// col = image.getPixel(x, 1);
|
||||||
// fitness += col.r*4294967296; // 2^(8*4)
|
// fitness += col.r*4294967296; // 2^(8*4)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue