image source1; source1.open("go.png"); textbuffer output; output.open("output.txt"); output.clear(); int count[16,16]; int colour[16,16]; double r_max = 0; double r_min = 256; double b_max = 0; double b_min = 256; for x from 0 to 19 for y from 0 to 19 { color col; for xi from 3 to 8 for yi from 3 to 8 col += source1.getColor(xi+10*x,yi+10*y); if (col.r < r_min) r_min = col.r; if (col.r > r_max) r_max = col.r; if (col.b < b_min) b_min = col.b; if (col.b > b_max) b_max = col.b; } output.append(format("%f-%f %f-%f\n", r_min, r_max, b_min, b_max)); for y from 0 to 19 { for x from 0 to 19 { color col; for xi from 3 to 8 for yi from 3 to 8 col += source1.getColor(xi+10*x,yi+10*y); double r = (col.r - r_min)/(r_max - r_min); double b = (col.b - b_min)/(b_max - b_min); count[round(r*16),round(b*16)]++; } } for r from 0 to 4 for b from 0 to 4 if (count[r,b] != 0) colour[r,b] = 1; for r from 12 to 16 for b from 12 to 16 if (count[r,b] != 0) colour[r,b] = 2; int max; int max_r; int max_b; for r from 0 to 16 for b from 0 to 16 if (colour[r,b] == 0 && count[r,b] > max) { max = count[r,b]; max_r = r; max_b = b; } colour[max_r, max_b] = 3; bool go = true; while (go) { go = false; for r from 0 to 16 for b from 0 to 16 if (colour[r,b] == 0 && count[r,b] > 0) { int colcount[4]; for i from 0 to 4 colcount[i] = 0; for ri from (r == 0 ? 0 : -1) to (r < 15 ? 2 : 1) for bi from (b == 0 ? 0 : -1) to (b < 15 ? 2 : 1) colcount[colour[r+ri,b+bi]]++; int max = 0; int max_col = 0; for col from 1 to 4 if (colcount[col] > max) { max = colcount[col]; max_col = col; } if (max_col > 0) { colour[r,b] = max_col; go = true; } } } for y from 0 to 19 { output.append(y == 0 ? "[\"" : ",\""); for x from 0 to 19 { color col; for xi from 3 to 8 for yi from 3 to 8 col += source1.getColor(xi+10*x,yi+10*y); double r = (col.r - r_min)/(r_max - r_min); double b = (col.b - b_min)/(b_max - b_min); double dist_b = sqrt((r - 0)*(r - 0)+(b - 0)*(b - 0)); double dist_w = sqrt((r - 1)*(r - 1)+(b - 1)*(b - 1)); double dist_e = sqrt((r - rb)*(r - rb)+(b - bb)*(b - bb)); int rv = round(r*16); int rb = round(b*16); if (colour[rv,rb] == 1) output.append("*"); else if (colour[rv,rb] == 2) output.append("O"); else if (colour[rv,rb] == 3) output.append(" "); else output.append("?"); } output.append("\"\n"); } output.append("]\n"); for r from 0 to 16 { for b from 0 to 16 output.append(format("%3d-%d", count[r,b], colour[r,b])); output.append("\n"); }