Emre
function evaluate(debugmode) { var x,y,i,full,empty,btype,well,blocked,lblock,rblock; // Intermediate Results var HorizontalTransitions = 0; var FilledLines = 0; var HighestBlock = -1; var VerticalTransitions = 0; var BlockedCells = 0; var Wells = 0; // Copy to eField, Calculate HorizontalTransitions, FilledLines and HighestBlock for(i=y=this.height-1;y>=0;y--) { btype=1; full=1; empty=1; for(x=this.width-1;x>=0;x--) { if(this.data[x+y*this.width]==0) this.efield[x+i*this.width]=0; else empty=!(this.efield[x+i*this.width]=1); if(btype!=this.efield[x+i*this.width]) { btype = this.efield[x+i*this.width]; full=0; HorizontalTransitions++; } } if(!empty) HighestBlock = -1; if(empty && HighestBlock==-1) HighestBlock = this.height-(y+1); if(!full) i--; else for(x=this.width-1;x>=0;x--) this.efield[x+y*this.width]=0; if(!btype) HorizontalTransitions++; } if(HighestBlock==-1) HighestBlock = this.height; FilledLines=i+1; HighestBlock -= FilledLines; // Calculate VerticalTransitions, Wells, BurriedCells for(x=0;x<this.width;x++) { btype=0; blocked=0; for(y=(this.height-HighestBlock);y<this.height;y++) { if(btype!=this.efield[x+y*this.width]) { blocked=1; btype=this.efield[x+y*this.width]; VerticalTransitions++; } if(blocked&&!this.efield[x+y*this.width]) { BlockedCells++; } if(x==0) lblock=1; else lblock = this.efield[(x-1)+y*this.width]; if(x==this.width-1) rblock=1; else rblock = this.efield[(x+1)+y*this.width]; if(lblock&&rblock) { for(i=y;i<this.height&&(this.efield[x+i*this.width]==0);i++) Wells++; } } if(!btype) VerticalTransitions++; } // Calculate Final Score FinalScore = (-1.00 * HighestBlock)+ (-1.00 * HorizontalTransitions)+ (-1.00 * VerticalTransitions)+ (-4.00 * BlockedCells)+ (-0.90 * Wells)+ ( 0.10 * FilledLines); return FinalScore; }
Variables
this.height
Height of the field
this.width
Width of the field
this.data[
n
]
Element in the field where
n
is between 0 and width*height