/*{"DESCRIPTION":"Concurrent chess entirely in GLSL, with high-contrast boards and state-driven glitch memory art. Grid side selects 1x1 to 20x20. Opening matrix forces 400 boards: White opening across columns, Black reply down rows, then random legal play. Focus row/column selects manual controls and inspection. Each board retains its own history, random stream and W/B/D counts; master pixels aggregate the grid. Auto-play starts enabled in Fastest mode at 8 moves per board per frame; timed speed defaults to 60 moves/second. Auto-repeat immediately starts the next game from the assigned opening and preserves counts. Restart all preserves counts; Reset statistics clears them. Changing grid or opening mode resets the cohort. Resize/recompile/seek clears buffers. 400 boards need 569200 pixels and 64x64 minimum dimensions; use 960x640 or larger.","ISFVSN":"2","CATEGORIES":["Game","Chess","Interactive"],"INPUTS":[{"NAME":"uOpeningMatrix","TYPE":"bool","LABEL":"Opening matrix: 20x20 White/Black first moves","DEFAULT":false},{"NAME":"uGridSide","TYPE":"long","LABEL":"Grid side (ordinary mode)","DEFAULT":4,"MIN":1,"MAX":20},{"NAME":"uFocusRow","TYPE":"long","LABEL":"Selected row / Black opening","DEFAULT":1,"MIN":1,"MAX":20},{"NAME":"uFocusColumn","TYPE":"long","LABEL":"Selected column / White opening","DEFAULT":1,"MIN":1,"MAX":20},{"NAME":"uFrom","TYPE":"long","LABEL":"From","DEFAULT":12,"VALUES":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63],"LABELS":["a1","b1","c1","d1","e1","f1","g1","h1","a2","b2","c2","d2","e2","f2","g2","h2","a3","b3","c3","d3","e3","f3","g3","h3","a4","b4","c4","d4","e4","f4","g4","h4","a5","b5","c5","d5","e5","f5","g5","h5","a6","b6","c6","d6","e6","f6","g6","h6","a7","b7","c7","d7","e7","f7","g7","h7","a8","b8","c8","d8","e8","f8","g8","h8"]},{"NAME":"uTo","TYPE":"long","LABEL":"To","DEFAULT":28,"VALUES":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63],"LABELS":["a1","b1","c1","d1","e1","f1","g1","h1","a2","b2","c2","d2","e2","f2","g2","h2","a3","b3","c3","d3","e3","f3","g3","h3","a4","b4","c4","d4","e4","f4","g4","h4","a5","b5","c5","d5","e5","f5","g5","h5","a6","b6","c6","d6","e6","f6","g6","h6","a7","b7","c7","d7","e7","f7","g7","h7","a8","b8","c8","d8","e8","f8","g8","h8"]},{"NAME":"uPromotion","TYPE":"long","LABEL":"Promote to","DEFAULT":5,"VALUES":[5,4,3,2],"LABELS":["Queen","Rook","Bishop","Knight"]},{"NAME":"uMove","TYPE":"event","LABEL":"Move"},{"NAME":"uAutoPlay","TYPE":"bool","LABEL":"Auto-play","DEFAULT":true},{"NAME":"uAutoSpeed","TYPE":"float","LABEL":"Auto-play speed (moves / second)","DEFAULT":60.0,"MIN":0.25,"MAX":60.0},{"NAME":"uAutoFast","TYPE":"bool","LABEL":"Fastest (use moves / frame)","DEFAULT":true},{"NAME":"uAutoBatch","TYPE":"long","LABEL":"Fastest moves / frame","DEFAULT":8,"MIN":1,"MAX":8},{"NAME":"uAutoRepeat","TYPE":"bool","LABEL":"Auto-repeat games (immediate)","DEFAULT":true},{"NAME":"uNewGame","TYPE":"event","LABEL":"Restart all boards"},{"NAME":"uResetStats","TYPE":"event","LABEL":"Reset all statistics"},{"NAME":"uBoardPixels","TYPE":"float","LABEL":"Board pixel emphasis","DEFAULT":1.4,"MIN":0.3,"MAX":3.0},{"NAME":"uMasterPixels","TYPE":"float","LABEL":"Master pixel emphasis","DEFAULT":2.0,"MIN":0.3,"MAX":3.0},{"NAME":"uFlip","TYPE":"bool","LABEL":"Flip board","DEFAULT":false},{"NAME":"uClaim","TYPE":"event","LABEL":"Claim draw / arm next move"},{"NAME":"uResign","TYPE":"event","LABEL":"Resign"},{"NAME":"uDrawAgreement","TYPE":"event","LABEL":"Both players agree to draw"}],"PASSES":[{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"moveState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"legalMoves","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"facts","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"gameState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"masterState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"masterState","PERSISTENT":true,"FLOAT":true,"FILTER":"NEAREST"},{"TARGET":"textAtlas","PERSISTENT":true,"FLOAT":false,"FILTER":"LINEAR"},{}]}*/ #ifdef GL_ES precision highp float;precision highp int; #endif const int STATE_TEXELS=1423;const int LEGAL_TEXELS=1024;const int FACT_TEXELS=257;int gBoard=0;int gridSide(){return uOpeningMatrix?20:int(clamp(float(uGridSide),1.0,20.0));}int requestedBoardCount(){int side=gridSide();return side*side;}int storageCapacity(){return int(min(floor(RENDERSIZE . x*RENDERSIZE . y/float(STATE_TEXELS)),400.0));}bool gridStorageReady(){return RENDERSIZE . x>=64.0&&RENDERSIZE . y>=64.0&&storageCapacity()>=requestedBoardCount();}int activeBoardCount(){return gridStorageReady()?requestedBoardCount():0;}int boardConfiguration(){return uOpeningMatrix?120:gridSide();}int focusBoard(){int side=gridSide();int row=int(clamp(float(uFocusRow),1.0,float(side)))-1;int column=int(clamp(float(uFocusColumn),1.0,float(side)))-1;return row*side+column;}bool boardUsesOpeningPair(){return uOpeningMatrix;}int boardWhiteOpening(){return gBoard-(gBoard/20)*20;}int boardBlackOpening(){return gBoard/20;}int boardSeedIndex(){return gBoard;}bool boardManualTarget(){return gBoard==focusBoard();}vec2 linearPixel(int index){float coordinate=(float(index)+0.5)/RENDERSIZE . x;return vec2(fract(coordinate),(floor(coordinate)+0.5)/RENDERSIZE . y);}vec2 dataPixel(int index){return linearPixel(gBoard*STATE_TEXELS+index);}vec4 gameDataAt(int board,int index){return IMG_NORM_PIXEL(gameState,linearPixel(board*STATE_TEXELS+index));}bool boardConfigurationChanged(){return int(gameDataAt(0,34). x)!=boardConfiguration();}vec4 gameData(int index){return IMG_NORM_PIXEL(gameState,dataPixel(index));}vec4 moveData(int index){return IMG_NORM_PIXEL(moveState,linearPixel(gBoard*91+index));}vec4 factData(int index){return IMG_NORM_PIXEL(facts,linearPixel(gBoard*FACT_TEXELS+index));}vec4 legalGroup(int from,int group){return IMG_NORM_PIXEL(legalMoves,linearPixel(gBoard*LEGAL_TEXELS+from*16+group));}int packedPiece(vec4 sampleValue,int component){vec4 mask=vec4(equal(vec4(float(component)),vec4(0.0,1.0,2.0,3.0)));return int(dot(sampleValue,mask));}int rulesBasePiece(int square){if(square<0||square>=64)return 0;int column=square/4;return packedPiece(moveData(column),square-column*4);}int rulesBaseKing(int side){vec4 kings=moveData(28);return int(side==1?kings . x:kings . y);}float storedLegal(int from,int to){if(from<0||from>=64||to<0||to>=64)return 0.0;int group=to/4;return float(packedPiece(legalGroup(from,group),to-group*4)>0);}vec4 masterData(int index){return IMG_NORM_PIXEL(masterState,linearPixel(index));}ivec4 masterExactCounts(){return ivec4(masterData(0))+1024*ivec4(masterData(1))+1048576*ivec4(masterData(2));}int masterTotal(){return masterExactCounts(). w;}int masterPly(){vec4 p=masterData(5);return int(p . x)+1024*int(p . y)+1048576*int(p . z);}float autoSliderSpeedCode(){return floor(clamp(uAutoSpeed,0.25,60.0)*100.0+0.5);}float autoSpeedCode(){return uAutoFast?65535.0:autoSliderSpeedCode();}float autoSpeedValue(){return autoSliderSpeedCode()*0.01;}float autoMoveInterval(){return 100.0/autoSliderSpeedCode();}int autoBatchSize(){return int(clamp(float(uAutoBatch),1.0,8.0));}int simulationSubstep(){return PASSINDEX/4;}float autoFiniteElapsed(vec2 currentTime,vec2 anchor){float whole=mod(currentTime . x-anchor . x+512.0,1024.0)-512.0;return whole+currentTime . y-anchor . y;}float uiAutoElapsed(vec2 currentTime){vec4 clock=gameData(26);vec4 detail=gameData(33);vec2 anchor=vec2(clock . y,clock . z+detail . x/1024.0);return autoFiniteElapsed(currentTime,anchor)-detail . y*autoMoveInterval();}vec4 uiGameStats(){vec3 counts=gameData(29). xyz+1024.0*gameData(30). xyz;return vec4(counts,counts . x+counts . y+counts . z);}int uiPiece(int square){if(square<0||square>=64)return 0;int column=square/4;return packedPiece(gameData(column),square-column*4);}int uiData(int key){ivec4 meta=ivec4(gameData(17));ivec4 last=ivec4(gameData(18));int side=int(gameData(16). x);if(key==0)return side;if(key==1)return boardManualTarget()&&meta . w==0&&uiPiece(uFrom)*side>0?uFrom:-1;if(key==2||key==3)return-1;if(key==4)return meta . w;if(key==5)return last . x;if(key==6)return last . y;if(key==7)return last . w;if(key==8)return int(gameData(19). w);if(key==9)return uFlip?1:0;if(key==10)return uTo;if(key==11)return last . z+1024*int(gameData(22). z);if(key==12)return uPromotion;if(key==13)return gameData(22). w>122.0?1:0;if(key==14)return int(gameData(20). x);if(key==15)return int(gameData(21). x);return 0;}float uiLegal(int from,int to){return storedLegal(from,to);}int rulesBasePiece(int square);int rulesBaseKing(int side);int ruleAbs(int value){return value<0?-value:value;}int ruleSide(int value){return value>0?1:(value<0?-1:0);}int ruleFile(int square){return square-(square/8)*8;}int ruleRank(int square){return square/8;}bool ruleInside(int file,int rank){return file>=0&&file<8&&rank>=0&&rank<8;}bool ruleHasRight(int rights,int bitValue){return mod(floor(float(rights)/float(bitValue)),2.0)>0.5;}int ruleRemoveRight(int rights,int bitValue){return ruleHasRight(rights,bitValue)?rights-bitValue:rights;}struct RulePosition{int fromSquare;int toSquare;int movingPiece;int epVictim;int rookFrom;int rookTo;int rookPiece;};RulePosition ruleCurrent(){return RulePosition(-1,-1,0,-1,-1,-1,0);}int ruleOverlayPiece(RulePosition position,int square,int basePiece){vec4 mask=vec4(equal(vec4(float(square)),vec4(float(position . toSquare),float(position . rookTo),float(position . fromSquare),float(position . epVictim))));float clearRook=float(square==position . rookFrom);float replaced=max(max(mask . x,mask . y),max(max(mask . z,mask . w),clearRook));return int(float(basePiece)*(1.0-replaced)+float(position . movingPiece)*mask . x+float(position . rookPiece)*mask . y);}int rulePiece(RulePosition position,int square){if(square<0||square>=64)return 0;return ruleOverlayPiece(position,square,rulesBasePiece(square));}RulePosition ruleMoveOverlay(int moving,int target,int from,int to,int promotion,int ep){int side=ruleSide(moving);int kind=ruleAbs(moving);RulePosition move=RulePosition(from,to,moving,-1,-1,-1,0);if(kind==1&&to==ep&&target==0&&ruleAbs(ruleFile(to)-ruleFile(from))==1&&ruleRank(to)-ruleRank(from)==side){move . epVictim=to-side*8;}if(kind==6&&ruleAbs(to-from)==2){move . rookFrom=to>from?from+3:from-4;move . rookTo=to>from?from+1:from-1;move . rookPiece=side*4;}if(kind==1&&(ruleRank(to)==0||ruleRank(to)==7)){int promotedKind=promotion>=2&&promotion<=5?promotion:5;move . movingPiece=side*promotedKind;}return move;}ivec2 ruleKnightStep(int direction){int odd=direction-2*(direction/2);int verticalSign=direction/2-2*(direction/4);return ivec2((1+odd)*(direction<4?1:-1),(2-odd)*(1-2*verticalSign));}ivec2 ruleRayStep(int direction){int odd=direction-2*(direction/2);int signValue=1-2*odd;if(direction<4)return direction<2?ivec2(signValue,0):ivec2(0,signValue);return ivec2(direction<6?1:-1,signValue);}vec4 ruleThreatCell(RulePosition position,int side,int king,int group){if(king<0||king>=64)return group==2?vec4(0.0,-1.0,float(king),float(side)):vec4(0.0);int file=ruleFile(king),rank=ruleRank(king);if(group==2){int count=0,only=-1;for(int source=0;source<10;++source){ivec2 offset=source<2?ivec2(source*2-1,side):ruleKnightStep(source-2);ivec2 p=ivec2(file,rank)+offset;if(!ruleInside(p . x,p . y))continue;int square=p . y*8+p . x;int piece=ruleOverlayPiece(position,square,uiPiece(square));if(piece==-side*(source<2?1:2)){++count;only=square;}}return vec4(float(count>1?2:count),float(count==1?only:-1),float(king),float(side));}vec4 result=vec4(0.0);for(int lane=0;lane<4;++lane){int direction=group*4+lane;ivec2 stepValue=ruleRayStep(direction);int pin=0,code=0;for(int distance=1;distance<=7;++distance){ivec2 p=ivec2(file,rank)+stepValue*distance;if(!ruleInside(p . x,p . y))break;int square=p . y*8+p . x;int piece=ruleOverlayPiece(position,square,uiPiece(square));if(piece==0)continue;if(piece*side>0){if(pin!=0)break;pin=distance;continue;}int kind=ruleAbs(piece);if(kind==5||(direction<4&&kind==4)||(direction>=4&&kind==3)||(pin==0&&distance==1&&kind==6))code=pin+8*distance;break;}result+=float(code)*vec4(equal(vec4(float(lane)),vec4(0.0,1.0,2.0,3.0)));}return result;}bool ruleThreatValid(vec4 info,int side,int king){return(side==1||side==-1)&&info . z==float(king)&&info . w==float(side);}bool attacked(RulePosition position,int square,int bySide){if(square<0||square>=64)return false;int file=ruleFile(square);int rank=ruleRank(square);for(int source=0;source<10;++source){ivec2 offset=source<2?ivec2(source*2-1,-bySide):ruleKnightStep(source-2);ivec2 p=ivec2(file,rank)+offset;int expected=bySide*(source<2?1:2);if(ruleInside(p . x,p . y)&&rulePiece(position,p . y*8+p . x)==expected)return true;}for(int direction=0;direction<8;++direction){ivec2 step=ruleRayStep(direction);for(int distance=1;distance<=7;++distance){ivec2 p=ivec2(file,rank)+step*distance;if(!ruleInside(p . x,p . y))break;int piece=rulePiece(position,p . y*8+p . x);if(piece==0)continue;if(ruleSide(piece)==bySide){int kind=ruleAbs(piece);if(distance==1&&kind==6)return true;if(kind==5)return true;if(direction<4&&kind==4)return true;if(direction>=4&&kind==3)return true;}break;}}return false;}int kingSquare(RulePosition position,int side){return position . movingPiece==side*6?position . toSquare:rulesBaseKing(side);}bool inCheck(RulePosition position,int side){int king=kingSquare(position,side);return king<0||attacked(position,king,-side);}bool rulePathClear(RulePosition position,int from,int to){int df=ruleFile(to)-ruleFile(from);int dr=ruleRank(to)-ruleRank(from);int step=ruleSide(df)+8*ruleSide(dr);for(int distance=1;distance<=7;++distance){int square=from+step*distance;if(square==to)return true;if(square<0||square>=64||rulePiece(position,square)!=0)return false;}return false;}bool legalMove(RulePosition position,int side,int rights,int ep,int from,int to){if(from<0||from>=64||to<0||to>=64||from==to)return false;if(side!=1&&side!=-1)return false;int moving=rulePiece(position,from);int target=rulePiece(position,to);if(ruleSide(moving)!=side||ruleSide(target)==side||ruleAbs(target)==6)return false;int kind=ruleAbs(moving);int ff=ruleFile(from);int fr=ruleRank(from);int tf=ruleFile(to);int tr=ruleRank(to);int df=tf-ff;int dr=tr-fr;bool shape=false;bool castle=false;if(kind==1){int homeRank=side==1?1:6;if(df==0&&target==0){shape=dr==side||(fr==homeRank&&dr==2*side&&rulePiece(position,from+side*8)==0);}else if(ruleAbs(df)==1&&dr==side){bool ordinaryCapture=ruleSide(target)==-side;bool enPassant=to==ep&&target==0&&tr==(side==1?5:2)&&rulePiece(position,to-side*8)==-side;shape=ordinaryCapture||enPassant;}}else if(kind==2){shape=(ruleAbs(df)==1&&ruleAbs(dr)==2)||(ruleAbs(df)==2&&ruleAbs(dr)==1);}else if(kind>=3&&kind<=5){bool diagonal=ruleAbs(df)==ruleAbs(dr);bool straight=df==0||dr==0;shape=((kind!=4&&diagonal)||(kind!=3&&straight))&&rulePathClear(position,from,to);}else if(kind==6){shape=ruleAbs(df)<=1&&ruleAbs(dr)<=1;int base=side==1?0:56;if(from==base+4&&tr==fr&&ruleAbs(df)==2){bool kingside=df>0;int neededRight=side==1?(kingside?1:2):(kingside?4:8);int rookSquare=base+(kingside?7:0);bool empty=kingside?(rulePiece(position,base+5)==0&&rulePiece(position,base+6)==0):(rulePiece(position,base+1)==0&&rulePiece(position,base+2)==0&&rulePiece(position,base+3)==0);castle=ruleHasRight(rights,neededRight)&&empty&&rulePiece(position,rookSquare)==side*4;shape=castle;}}if(!shape)return false;int originalKing=kingSquare(position,side);if(originalKing<0)return false;for(int stage=0;stage<3;++stage){if(stage>0&&!castle)break;int testTo=stage==0?to:(stage==1?from:from+(to>from?1:-1));RulePosition trial=ruleMoveOverlay(moving,target,from,testTo,5,ep);int king=kind==6?testTo:originalKing;if(attacked(trial,king,-side))return false;}return true;}vec4 ruleSafeDestinations4(int side,int from,int king,vec4 destinations,vec4 legal,vec4 epCaptures,int epVictim){if(king<0)return vec4(0.0);if(king>=64)return legal;int file=ruleFile(king),rank=ruleRank(king);int bySide=-side;for(int source=0;source<10;++source){ivec2 offset=source<2?ivec2(source*2-1,-bySide):ruleKnightStep(source-2);ivec2 p=ivec2(file,rank)+offset;if(!ruleInside(p . x,p . y))continue;int square=p . y*8+p . x;int expected=bySide*(source<2?1:2);if(rulesBasePiece(square)!=expected)continue;vec4 removed=vec4(equal(destinations,vec4(float(square))));if(square==epVictim)removed=max(removed,epCaptures);legal*=removed;if(!any(greaterThan(legal,vec4(0.5))))return vec4(0.0);}for(int direction=0;direction<8;++direction){ivec2 stepValue=ruleRayStep(direction);vec4 open=legal;for(int distance=1;distance<=7;++distance){ivec2 p=ivec2(file,rank)+stepValue*distance;if(!ruleInside(p . x,p . y))break;int square=p . y*8+p . x;open*=vec4(notEqual(destinations,vec4(float(square))));if(!any(greaterThan(open,vec4(0.5))))break;if(square==from)continue;int piece=rulesBasePiece(square);if(piece==0)continue;vec4 removed=square==epVictim?epCaptures:vec4(0.0);vec4 blocked=open*(vec4(1.0)-removed);int kind=ruleAbs(piece);bool attacks=ruleSide(piece)==bySide&&(kind==5||(distance==1&&kind==6)||(direction<4&&kind==4)||(direction>=4&&kind==3));if(attacks)legal*=vec4(1.0)-blocked;if(!any(greaterThan(legal,vec4(0.5))))return vec4(0.0);open*=removed;if(!any(greaterThan(open,vec4(0.5))))break;}}return legal;}vec4 ruleThreatSafe4(int from,int king,vec4 destinations,vec4 legal,vec4 info){if(info . x>1.5)return vec4(0.0);if(info . x>0.5){legal*=vec4(equal(destinations,vec4(info . y)));if(!any(greaterThan(legal,vec4(0.5))))return vec4(0.0);}vec4 firstRays=moveData(37),lastRays=moveData(38);if(!any(greaterThan(firstRays+lastRays,vec4(0.5))))return legal;vec4 df=mod(destinations,8.0)-float(ruleFile(king));vec4 dr=floor(destinations/8.0)-float(ruleRank(king));vec4 distance=max(abs(df),abs(dr));for(int group=0;group<2;++group){vec4 codes=group==0?firstRays:lastRays;for(int lane=0;lane<4;++lane){int code=packedPiece(codes,lane);if(code==0)continue;int attacker=code/8,pin=code-attacker*8;ivec2 ray=ruleRayStep(group*4+lane);if(pin>0&&from!=king+pin*(ray . x+8*ray . y))continue;legal*=vec4(equal(df,distance*float(ray . x)))*vec4(equal(dr,distance*float(ray . y)))*step(vec4(0.5),distance)*vec4(lessThanEqual(distance,vec4(float(attacker))));if(!any(greaterThan(legal,vec4(0.5))))return vec4(0.0);}}return legal;}bool ruleThreatInCheck(int side){int king=rulesBaseKing(side);if(king<0)return true;if(king>=64)return false;vec4 info=moveData(39);if(!ruleThreatValid(info,side,king))return inCheck(ruleCurrent(),side);if(info . x>0.5)return true;for(int group=0;group<2;++group){vec4 codes=moveData(37+group);vec4 direct=step(vec4(0.5),codes)*vec4(equal(mod(codes,8.0),vec4(0.0)));if(any(greaterThan(direct,vec4(0.5))))return true;}return false;}vec4 ruleLegalNonKing4(int side,int ep,int moving,int from,int firstTo,vec4 targets,vec4 possible){if(side!=1&&side!=-1)return vec4(0.0);int kind=ruleAbs(moving);vec4 destinations=vec4(float(firstTo))+vec4(0.0,1.0,2.0,3.0);vec4 epCaptures=vec4(0.0);if(kind==1){int fr=ruleRank(from),tr=ruleRank(firstTo);int dr=tr-fr;vec4 df=vec4(float(ruleFile(firstTo)-ruleFile(from)))+vec4(0.0,1.0,2.0,3.0);vec4 straight=vec4(equal(df,vec4(0.0)));vec4 diagonal=vec4(equal(abs(df),vec4(1.0)));vec4 empty=vec4(equal(targets,vec4(0.0)));if(dr==side){if(tr==(side==1?5:2)&&ep>=0&&ep<64&&rulesBasePiece(ep-side*8)==-side){epCaptures=diagonal*empty*vec4(equal(destinations,vec4(float(ep))));}vec4 ordinary=diagonal*vec4(lessThan(targets*float(side),vec4(0.0)));possible*=max(straight*empty,max(ordinary,epCaptures));}else if(dr==side*2&&fr==(side==1?1:6)){if(rulesBasePiece(from+side*8)!=0)return vec4(0.0);possible*=straight*empty;}else return vec4(0.0);}else if(kind>=3&&kind<=5){RulePosition position=ruleCurrent();for(int lane=0;lane<4;++lane){vec4 mask=vec4(equal(vec4(float(lane)),vec4(0.0,1.0,2.0,3.0)));if(dot(possible,mask)<0.5)continue;if(!rulePathClear(position,from,firstTo+lane))possible*=vec4(1.0)-mask;}}else if(kind!=2)return vec4(0.0);if(!any(greaterThan(possible,vec4(0.5))))return vec4(0.0);int king=rulesBaseKing(side);if(king<0)return vec4(0.0);if(king>=64)return possible;vec4 info=moveData(39);if(!any(greaterThan(epCaptures,vec4(0.5)))&&ruleThreatValid(info,side,king))return ruleThreatSafe4(from,king,destinations,possible,info);return ruleSafeDestinations4(side,from,king,destinations,possible,epCaptures,ep-side*8);}int nextCastlingRights(int rights,int moving,int captured,int from,int to){if(moving==6){rights=ruleRemoveRight(rights,1);rights=ruleRemoveRight(rights,2);}if(moving==-6){rights=ruleRemoveRight(rights,4);rights=ruleRemoveRight(rights,8);}if((moving==4&&from==7)||(captured==4&&to==7))rights=ruleRemoveRight(rights,1);if((moving==4&&from==0)||(captured==4&&to==0))rights=ruleRemoveRight(rights,2);if((moving==-4&&from==63)||(captured==-4&&to==63))rights=ruleRemoveRight(rights,4);if((moving==-4&&from==56)||(captured==-4&&to==56))rights=ruleRemoveRight(rights,8);return rights;}bool insufficientMaterial(RulePosition position){int whiteKings=0;int blackKings=0;int minors=0;int knights=0;int bishopColor=-1;bool bishopsSameColor=true;for(int square=0;square<64;++square){int piece=rulePiece(position,square);int kind=ruleAbs(piece);if(kind==0)continue;if(kind==6){if(piece>0)++whiteKings;else++blackKings;}else if(kind==2){++minors;++knights;}else if(kind==3){++minors;int sum=ruleFile(square)+ruleRank(square);int color=sum-2*(sum/2);if(bishopColor<0)bishopColor=color;else if(bishopColor!=color)bishopsSameColor=false;}else{return false;}}if(whiteKings!=1||blackKings!=1)return false;return minors<=1||(knights==0&&bishopsSameColor);}int initialPiece(int square){int rank=ruleRank(square),file=ruleFile(square);if(rank==1)return 1;if(rank==6)return-1;if(rank!=0&&rank!=7)return 0;int p=6;if(file==0||file==7)p=4;if(file==1||file==6)p=2;if(file==2||file==5)p=3;if(file==3)p=5;return rank==0?p:-p;}vec4 initialPacked(int column){return vec4(float(initialPiece(column*4)),float(initialPiece(column*4+1)),float(initialPiece(column*4+2)),float(initialPiece(column*4+3)));}ivec2 openingMove(int side,int opening){if(opening<16){int file=opening-(opening/8)*8;int from=(side==1?8:48)+file;return ivec2(from,from+side*8*(1+opening/8));}int knight=opening-16;int from=(side==1?0:56)+(knight<2?1:6);int file=knight<2?knight*2:(knight==2?5:7);return ivec2(from,(side==1?16:40)+file);}vec4 openingPacked(int column,int plies){vec4 pieces=initialPacked(column);vec4 squares=vec4(float(column*4))+vec4(0.0,1.0,2.0,3.0);for(int ply=0;ply<2;++ply){if(ply>=plies)break;ivec2 move=openingMove(ply==0?1:-1,ply==0?boardWhiteOpening():boardBlackOpening());vec4 source=vec4(equal(squares,vec4(float(move . x))));vec4 target=vec4(equal(squares,vec4(float(move . y))));pieces=pieces*(vec4(1.0)-source-target)+float(initialPiece(move . x))*target;}return pieces;}vec4 historyPack(vec4 first,vec4 second){return 13.0*(first+6.0)+(second+6.0);}vec4 historyInput(int index){if(index>=91)return gameData(index);return moveData(index);}vec4 compactHistoryBoard(int column){return historyPack(moveData(column*2),moveData(column*2+1));}vec4 openingHistoryBoard(int column,int plies){return historyPack(openingPacked(column*2,plies),openingPacked(column*2+1,plies));}vec4 positionPacked(RulePosition position,int column){vec4 previous=gameData(column);return vec4(float(ruleOverlayPiece(position,column*4,int(previous . r))),float(ruleOverlayPiece(position,column*4+1,int(previous . g))),float(ruleOverlayPiece(position,column*4+2,int(previous . b))),float(ruleOverlayPiece(position,column*4+3,int(previous . a))));}vec4 currentEventInputs(){return vec4(uMove?1.0:0.0,uNewGame?1.0:0.0,uClaim?1.0:0.0,uResign?1.0:0.0);}vec2 autoTimestamp(){float seconds=max(TIME,0.0);return vec2(mod(floor(seconds),1024.0),fract(seconds));}vec2 autoFractionParts(float fraction){float scaled=fraction*1024.0;return vec2(floor(scaled)/1024.0,fract(scaled));}float autoFiniteAllowance(){return(1.0/4194304.0)+max(abs(TIME),1.0)*(1.0/8388608.0);}bool autoFiniteDue(vec2 currentTime,vec2 anchor,float ordinal,float interval){return TIMEDELTA>=2.0*interval||autoFiniteElapsed(currentTime,anchor)+autoFiniteAllowance()>=(ordinal+1.0)*interval;}vec2 autoShiftTimestamp(vec2 anchor,float seconds){float fraction=anchor . y+fract(seconds);float whole=anchor . x+floor(seconds)+floor(fraction);return vec2(mod(whole,1024.0),fract(fraction));}vec2 autoNextSeed(vec2 bytes){float seed=bytes . x+bytes . y*256.0;float next=mod(seed*253.0+17.0,65536.0);return vec2(mod(next,256.0),floor(next/256.0));}vec2 autoInitialSeed(){float seed=mod(floor(mod(max(TIME,0.0),64.0)*1024.0)+31821.0+40503.0*float(boardSeedIndex()),65536.0);return vec2(mod(seed,256.0),floor(seed/256.0));}ivec3 autoChooseMove(vec2 randomBytes,int total){if(total<=0)return ivec3(-1,-1,5);float randomValue=randomBytes . x+randomBytes . y*256.0;int ticket=int(floor(randomValue*float(total)/65536.0));int chosenFrom=-1;for(int from=0;from<64;++from){int weight=int(factData(from). g);if(ticket<weight){chosenFrom=from;break;}ticket-=weight;}if(chosenFrom<0)return ivec3(-1,-1,5);for(int group=0;group<16;++group){vec4 codes=legalGroup(chosenFrom,group);vec4 weights=codes*codes;int groupWeight=int(dot(weights,vec4(1.0)));if(ticket>=groupWeight){ticket-=groupWeight;continue;}for(int lane=0;lane<4;++lane){vec4 mask=vec4(equal(vec4(float(lane)),vec4(0.0,1.0,2.0,3.0)));int weight=int(dot(weights,mask));if(ticket<weight)return ivec3(chosenFrom,group*4+lane,weight==4?ticket+2:5);ticket-=weight;}}return ivec3(-1,-1,5);}vec4 advanceGame(int index){vec4 oldValue=gameData(index);if(index>=35&&index<64&&(index<36||index>39))return oldValue;bool extraSubstep=simulationSubstep()>0;int batchSize=autoBatchSize();vec4 frameGuard=gameData(32);if(extraSubstep&&(!uAutoPlay||!uAutoFast||simulationSubstep()>=batchSize||frameGuard . x>0.5||(gameData(17). w!=0.0&&!uAutoRepeat))){return index==22?vec4(0.0,oldValue . yzw):oldValue;}ivec4 system=ivec4(gameData(22));vec4 previousEvents=gameData(23);bool fresh=system . w!=123||boardConfigurationChanged()||int(gameData(34). x)!=boardConfiguration();bool newGameNow=uNewGame&&previousEvents . y<0.5;if(index==36){if(fresh||newGameNow)return vec4(0.0);float dt=extraSubstep?0.0:clamp(TIMEDELTA,0.0,0.10);float pulse=oldValue . y*exp(-3.0*dt);return vec4(oldValue . x,pulse<0.001?0.0:pulse,0.0,0.0);}bool manualTarget=boardManualTarget();bool moveNow=manualTarget&&uMove&&previousEvents . x<0.5;bool claimNow=manualTarget&&uClaim&&previousEvents . z<0.5;bool resignNow=manualTarget&&uResign&&previousEvents . w<0.5;bool agreeNow=manualTarget&&uDrawAgreement&&gameData(24). x<0.5;ivec4 ui=ivec4(gameData(17));vec4 statsLow=gameData(29);vec4 statsHigh=gameData(30);vec4 cycle=gameData(31);vec4 previousAuto=gameData(26);vec4 previousRandom=gameData(27);vec4 clockDetail=gameData(33);bool resetStatsNow=uResetStats&&statsLow . w<0.5;bool manualAction=newGameNow||moveNow||claimNow||resignNow||agreeNow;vec2 now=autoTimestamp();float speedCode=autoSpeedCode();vec2 speedBytes=vec2(mod(speedCode,256.0),floor(speedCode/256.0));bool speedChanged=previousAuto . w!=speedBytes . x||previousRandom . w!=speedBytes . y;bool autoplayChanged=previousAuto . x!=(uAutoPlay?1.0:0.0);bool batchChanged=uAutoFast&&int(frameGuard . y)!=batchSize;bool repeatEnabled=uAutoPlay&&uAutoRepeat;bool repeatWasEnabled=previousAuto . x>0.5&&cycle . w>0.5;if(fresh||!repeatEnabled||!repeatWasEnabled||manualAction||speedChanged||batchChanged||TIMEDELTA<0.0)cycle . yz=now;cycle . w=uAutoRepeat?1.0:0.0;if(fresh||resetStatsNow){statsLow . xyz=vec3(0.0);statsHigh=vec4(0.0);if(!fresh&&ui . w!=0)cycle . x=1.0;}statsLow . w=uResetStats?1.0:0.0;bool repeatNow=!fresh&&repeatEnabled&&ui . w!=0&&cycle . x>0.5&&!manualAction;bool resetNow=fresh||newGameNow||repeatNow;bool blockExtraSubsteps=fresh||manualAction||speedChanged||autoplayChanged||batchChanged||(ui . w!=0&&!repeatEnabled)||TIMEDELTA<0.0;if(resetNow){bool pair=boardUsesOpeningPair();int plies=pair?2:0;int halfmove=pair&&boardBlackOpening()>=16?(boardWhiteOpening()>=16?2:1):0;ivec2 blackMove=openingMove(-1,boardBlackOpening());int ep=pair&&boardBlackOpening()>=8&&boardBlackOpening()<16?(blackMove . x+blackMove . y)/2:-1;if(index<16)return openingPacked(index,plies);if(index==16)return vec4(1.0,15.0,float(ep),float(halfmove));if(index==17)return vec4(-1.0,-1.0,-1.0,0.0);if(index==18)return pair?vec4(vec2(blackMove),2.0,0.0):vec4(-1.0,-1.0,0.0,0.0);if(index==19)return vec4(float(halfmove),float(halfmove+1),1.0,0.0);if(index==20)return pair?vec4(3.0,float(initialPiece(blackMove . x)),0.0,0.0):vec4(0.0);if(index==22)return vec4(1.0,0.0,0.0,123.0);if(index==23)return currentEventInputs();if(index==24)return vec4(uDrawAgreement?1.0:0.0,0.0,0.0,0.0);if(index==26)return vec4(uAutoPlay?1.0:0.0,now . x,autoFractionParts(now . y). x,speedBytes . x);if(index==27)return vec4(fresh?autoInitialSeed():previousRandom . xy,0.0,speedBytes . y);if(index==28)return vec4(4.0,60.0,0.0,0.0);if(index==29)return statsLow;if(index==30)return statsHigh;if(index==31)return vec4(0.0,now,uAutoRepeat?1.0:0.0);if(index==32)return vec4(blockExtraSubsteps?1.0:0.0,float(batchSize),0.0,0.0);if(index==33)return vec4(autoFractionParts(now . y). y,0.0,0.0,0.0);if(index==34)return vec4(float(boardConfiguration()),0.0,0.0,0.0);if(index==39)return vec4(0.0,-1.0,4.0,1.0);if(index>=64){int slot=(index-64)/9;int column=index-64-slot*9;if(slot<=halfmove){int stage=plies-halfmove+slot;if(column<8)return openingHistoryBoard(column,stage);return vec4(stage==1?-1.0:1.0,15.0,-1.0,0.0);}return oldValue;}return vec4(0.0);}if(index>=34&&(index<37||index>39))return oldValue;if(index==23)return currentEventInputs();if(index==24)return vec4(uDrawAgreement?1.0:0.0,0.0,0.0,0.0);if(index==29)return statsLow;if(index==30)return statsHigh;if(index==31)return cycle;if(index==32)return extraSubstep?frameGuard:vec4(blockExtraSubsteps?1.0:0.0,float(batchSize),0.0,0.0);ivec4 rules=ivec4(gameData(16));ivec4 last=ivec4(gameData(18));ivec4 hist=ivec4(gameData(19));ivec4 event=ivec4(gameData(20));ivec4 claim=ivec4(gameData(21));vec4 glow=gameData(25);vec4 autoClock=previousAuto;autoClock . z+=clockDetail . x/1024.0;vec4 randomState=previousRandom;autoClock . w=speedBytes . x;randomState . w=speedBytes . y;vec4 kings=gameData(28);float dt=extraSubstep?0.0:clamp(TIMEDELTA,0.0,0.10);glow=vec4(glow . xyz*exp(-dt*vec3(2.8,1.8,4.0)),mod(glow . w+dt,4.0));glow . xyz*=step(vec3(0.001),glow . xyz);system . x=0;bool committed=false;bool automaticMoveNow=false;RulePosition position=ruleCurrent();int chosenFrom=uFrom;int chosenTo=uTo;int chosenPromotion=uPromotion;bool restartClock=!uAutoPlay||autoClock . x<0.5||ui . w!=0||manualAction||speedChanged||batchChanged||TIMEDELTA<0.0;autoClock . x=uAutoPlay?1.0:0.0;if(restartClock){autoClock . yz=now;clockDetail . y=0.0;}else if(uAutoFast||autoFiniteDue(now,autoClock . yz,clockDetail . y,autoMoveInterval())){float interval=autoMoveInterval();float sinceScheduled=autoFiniteElapsed(now,autoClock . yz)-clockDetail . y*interval;if(uAutoFast||TIMEDELTA>=2.0*interval||sinceScheduled>=2.0*interval){autoClock . yz=now;clockDetail . y=0.0;}else{clockDetail . y+=1.0;float scheduled=clockDetail . y*interval;if(scheduled>=16.0){autoClock . yz=autoShiftTimestamp(autoClock . yz,scheduled);clockDetail . y=0.0;}}if(randomState . z>0.5){vec4 cachedChoice=gameData(35);ivec3 choice=ivec3(cachedChoice . xyz);if(cachedChoice . w>0.5&&choice . x>=0&&choice . y>=0){chosenFrom=choice . x;chosenTo=choice . y;chosenPromotion=choice . z;moveNow=true;automaticMoveNow=true;}}}if(ui . w==0){if(claimNow){if(hist . w>0)ui . w=ruleHasRight(hist . w,1)?7:8;else{claim . x=1-claim . x;event . x=claim . x==1?5:0;}}else if(resignNow){bool opponentHasMaterial=false;for(int square=0;square<64;++square){int p=uiPiece(square);if(p*rules . x<0&&ruleAbs(p)!=6)opponentHasMaterial=true;}ui . w=opponentHasMaterial?(rules . x==1?10:9):4;}else if(agreeNow)ui . w=11;else if(moveNow){if(storedLegal(chosenFrom,chosenTo)<0.5){event . x=2;glow . z=1.0;}else{int moving=uiPiece(chosenFrom);int target=uiPiece(chosenTo);int captured=target;if(ruleAbs(moving)==1&&chosenTo==rules . z&&captured==0&&ruleFile(chosenFrom)!=ruleFile(chosenTo))captured=-rules . x;bool irreversible=ruleAbs(moving)==1||captured!=0;int rights=nextCastlingRights(rules . y,moving,target,chosenFrom,chosenTo);position=ruleMoveOverlay(moving,target,chosenFrom,chosenTo,chosenPromotion,rules . z);if(moving==6)kings . x=float(chosenTo);if(moving==-6)kings . y=float(chosenTo);int ep=ruleAbs(moving)==1&&ruleAbs(chosenTo-chosenFrom)==16?(chosenTo+chosenFrom)/2:-1;rules=ivec4(-rules . x,rights,ep,irreversible?0:rules . w+1);int low=last . z+1;if(low>=1024){low=0;system . z+=1;}last=ivec4(chosenFrom,chosenTo,low,0);int cursor=irreversible?0:hist . x+1;if(cursor>=151)cursor=0;int count=irreversible?1:hist . y+1;if(count>151)count=151;hist=ivec4(cursor,count,0,0);event=ivec4(3,moving,captured,ruleAbs(moving)==1&&(ruleRank(chosenTo)==0||ruleRank(chosenTo)==7)?chosenPromotion:0);claim=ivec4(0,claim . x,0,0);system . x=1;committed=true;if(automaticMoveNow)randomState . xy=autoNextSeed(randomState . xy);float capturePulse=captured!=0?1.0:0.0;if(extraSubstep)capturePulse=max(capturePulse,glow . y);glow . xyz=vec3(1.0,capturePulse,0.0);if(!automaticMoveNow){autoClock . yz=now;clockDetail . y=0.0;}}}}if(ui . w!=0){claim=ivec4(0);hist . w=0;}if(index>=37&&index<=39){int king=int(rules . x==1?kings . x:kings . y);if(committed||!ruleThreatValid(gameData(39),rules . x,king))return ruleThreatCell(position,rules . x,king,index-37);return oldValue;}if(index<16)return committed?positionPacked(position,index):oldValue;if(index==16)return vec4(rules);if(index==17)return vec4(ui);if(index==18)return vec4(last);if(index==19)return vec4(hist);if(index==20)return vec4(event);if(index==21)return vec4(claim);if(index==22)return vec4(system);if(index==25)return glow;if(index==26)return vec4(autoClock . xy,autoFractionParts(autoClock . z). x,autoClock . w);if(index==27)return randomState;if(index==28)return kings;if(index==33)return vec4(autoFractionParts(autoClock . z). y,clockDetail . y,0.0,0.0);return oldValue;}vec4 calculateLegal(ivec2 pixel){if(moveData(22). x<0.5)return legalGroup(pixel . y,pixel . x);int from=pixel . y;ivec4 rules=ivec4(moveData(16));int moving=rulesBasePiece(from);if(moving*rules . x<=0)return vec4(0.0);RulePosition position=ruleCurrent();int firstTo=pixel . x*4;int kind=ruleAbs(moving);int rankFrom=ruleRank(from);int rankTo=ruleRank(firstTo);int dr=rankTo-rankFrom;int rankDistance=ruleAbs(dr);vec4 files=abs(vec4(float(ruleFile(firstTo)-ruleFile(from)))+vec4(0.0,1.0,2.0,3.0));vec4 sameFile=vec4(equal(files,vec4(0.0)));vec4 possible=vec4(0.0);if(kind==1){if(dr==rules . x)possible=vec4(lessThanEqual(files,vec4(1.0)));else if(dr==rules . x*2&&rankFrom==(rules . x==1?1:6))possible=sameFile;}else if(kind==2){if(rankDistance==1)possible=vec4(equal(files,vec4(2.0)));else if(rankDistance==2)possible=vec4(equal(files,vec4(1.0)));}else if(kind>=3&&kind<=5){vec4 diagonal=vec4(equal(files,vec4(float(rankDistance))));vec4 straight=dr==0?vec4(1.0):sameFile;possible=max(kind==4?vec4(0.0):diagonal,kind==3?vec4(0.0):straight);}else if(kind==6){if(rankDistance<=1)possible=vec4(lessThanEqual(files,vec4(1.0)));if(dr==0&&from==(rules . x==1?4:60))possible=max(possible,vec4(equal(files,vec4(2.0))));}if(!any(greaterThan(possible,vec4(0.5))))return vec4(0.0);vec4 targets=moveData(pixel . x);possible*=vec4(lessThanEqual(targets*float(rules . x),vec4(0.0)));possible*=vec4(notEqual(abs(targets),vec4(6.0)));if(!any(greaterThan(possible,vec4(0.5))))return vec4(0.0);bool promotion=kind==1&&(rankTo==0||rankTo==7);if(kind!=6)return(promotion?2.0:1.0)*ruleLegalNonKing4(rules . x,rules . z,moving,from,firstTo,targets,possible);vec4 result=vec4(0.0);for(int lane=0;lane<4;++lane){vec4 mask=vec4(equal(vec4(float(lane)),vec4(0.0,1.0,2.0,3.0)));if(dot(possible,mask)<0.5)continue;if(legalMove(position,rules . x,rules . y,rules . z,from,firstTo+lane))result+=(promotion?2.0:1.0)*mask;}return result;}vec4 historyResidual(int slot,int column,vec4 currentHigh,float alive){if(alive<0.5)return vec4(7.0);return historyInput(64+slot*9+column)-currentHigh;}float cachedHistoryMatch(int slot){if(slot<0||slot>=151)return 0.0;int group=slot/4;return float(packedPiece(factData(64+group),slot-group*4));}vec4 calculateFacts(int index){if(moveData(22). x<0.5)return factData(index);if(index<64){if(rulesBasePiece(index)*int(moveData(16). x)<=0)return vec4(0.0);vec4 destinations=vec4(0.0);vec4 moveWeights=vec4(0.0);for(int group=0;group<16;++group){vec4 codes=legalGroup(index,group);destinations+=step(vec4(0.5),codes);moveWeights+=codes*codes;}return vec4(dot(destinations,vec4(1.0)),dot(moveWeights,vec4(1.0)),0.0,0.0);}if(index<102){int firstSlot=(index-64)*4;ivec4 hist=ivec4(moveData(19));if(firstSlot>=hist . y)return vec4(0.0);ivec4 rules=ivec4(moveData(16));if(rules . z>=0)return vec4(0.0);vec4 key=vec4(float(rules . x),float(rules . y),-1.0,0.0);vec4 alive=vec4(0.0);for(int lane=0;lane<4;++lane){int slot=firstSlot+lane;if(slot>=151||slot>=hist . y||slot==hist . x)continue;if(all(equal(historyInput(64+slot*9+8),key)))alive+=vec4(equal(vec4(float(lane)),vec4(0.0,1.0,2.0,3.0)));}for(int column=0;column<8;++column){if(!any(greaterThan(alive,vec4(0.5))))break;vec4 currentHigh=13.0*(moveData(column*2)+6.0)+6.0;mat4 residuals=mat4(historyResidual(firstSlot,column,currentHigh,alive . x),historyResidual(firstSlot+1,column,currentHigh,alive . y),historyResidual(firstSlot+2,column,currentHigh,alive . z),historyResidual(firstSlot+3,column,currentHigh,alive . w));alive*=vec4(bvec4(all(lessThanEqual(abs(residuals[0]),vec4(6.0))),all(lessThanEqual(abs(residuals[1]),vec4(6.0))),all(lessThanEqual(abs(residuals[2]),vec4(6.0))),all(lessThanEqual(abs(residuals[3]),vec4(6.0)))));if(!any(greaterThan(alive,vec4(0.5))))break;vec4 currentLow=moveData(column*2+1);alive*=vec4(bvec4(all(equal(residuals[0],currentLow)),all(equal(residuals[1],currentLow)),all(equal(residuals[2],currentLow)),all(equal(residuals[3],currentLow))));}return alive;}if(index==256){RulePosition position=ruleCurrent();return vec4(ruleThreatInCheck(int(moveData(16). x))?1.0:0.0,insufficientMaterial(position)?1.0:0.0,0.0,0.0);}return vec4(0.0);}int cachedEffectiveEp(int side,int ep){if(ep<0||ep>=64||(side!=1&&side!=-1))return-1;if(ruleRank(ep)!=(side==1?5:2)||rulesBasePiece(ep)!=0||rulesBasePiece(ep-side*8)!=-side)return-1;for(int direction=-1;direction<=1;direction+=2){int file=ruleFile(ep)+direction;if(file<0||file>=8)continue;int from=(ruleRank(ep)-side)*8+file;if(rulesBasePiece(from)==side&&storedLegal(from,ep)>0.5)return ep;}return-1;}vec4 finishGame(int index){vec4 value=historyInput(index);bool statisticsPixel=(index>=29&&index<=31)||index==36;bool outcomePixel=(index>=17&&index<=21)||statisticsPixel;if(index<64&&!outcomePixel&&index!=27&&index!=35)return value;ivec4 hist=ivec4(moveData(19));int historyStart=64+hist . x*9;if(index>=64&&(index<historyStart||index>=historyStart+9))return value;bool changed=moveData(22). x>0.5;if(!changed&&!statisticsPixel)return value;if(index==18){value . w=factData(256). r>0.5?1.0:0.0;return value;}if(index==20&&moveData(21). y==0.0)return value;if(index==21&&all(equal(value,vec4(0.0))))return value;if(changed&&(index==27||index==35)){float total=0.0;for(int from=0;from<64;++from)total+=factData(from). g;if(index==27){value . z=total;return value;}ivec3 choice=autoChooseMove(autoNextSeed(moveData(27). xy),int(total));return vec4(vec3(choice),choice . x>=0&&choice . y>=0?1.0:0.0);}if(changed&&index>=historyStart&&index<historyStart+9){int column=index-historyStart;if(column<8)return compactHistoryBoard(column);ivec4 rules=ivec4(moveData(16));int ep=cachedEffectiveEp(rules . x,rules . z);return vec4(float(rules . x),float(rules . y),float(ep),0.0);}if((index<17||index>21)&&!statisticsPixel)return value;ivec4 ui=ivec4(moveData(17));ivec4 last=ivec4(moveData(18));ivec4 event=ivec4(moveData(20));ivec4 claim=ivec4(moveData(21));ivec4 rules=ivec4(moveData(16));if(changed){float available=0.0;for(int from=0;from<64;++from){available+=factData(from). r;if(available>0.5)break;}vec4 matches=vec4(0.0);for(int group=0;group<38;++group){if(group*4>=hist . y)break;matches+=factData(64+group);}int repeats=1+int(dot(matches,vec4(1.0)));hist . z=repeats;hist . w=(repeats>=3?1:0)+(rules . w>=100?2:0);vec4 factsNow=factData(256);last . w=factsNow . r>0.5?1:0;if(ui . w==0){if(claim . y!=0&&hist . w>0)ui . w=ruleHasRight(hist . w,1)?7:8;else if(available<0.5)ui . w=last . w!=0?(rules . x==1?2:1):3;else if(factsNow . g>0.5)ui . w=4;else if(repeats>=5)ui . w=5;else if(rules . w>=150)ui . w=6;if(claim . y!=0&&ui . w==0)event . x=6;}}claim . y=0;if(ui . w!=0){claim=ivec4(0);hist . w=0;}if(index==17)return vec4(ui);if(index==18)return vec4(last);if(index==19)return vec4(hist);if(index==20)return vec4(event);if(index==21)return vec4(claim);vec4 statsLow=moveData(29);vec4 statsHigh=moveData(30);vec4 cycle=moveData(31);vec4 resultRecord=moveData(36);if(ui . w==0)cycle . x=0.0;else if(cycle . x<0.5){vec3 counts=statsLow . xyz+1024.0*statsHigh . xyz;float total=counts . x+counts . y+counts . z;if(total<1048575.0&&statsHigh . w<0.5){bool whiteWin=ui . w==1||ui . w==9;bool blackWin=ui . w==2||ui . w==10;counts+=vec3(whiteWin?1.0:0.0,blackWin?1.0:0.0,!whiteWin&&!blackWin?1.0:0.0);statsLow . xyz=mod(counts,1024.0);statsHigh . xyz=floor(counts/1024.0);statsHigh . w=total+1.0>=1048575.0?1.0:0.0;}else statsHigh . w=1.0;cycle . x=1.0;cycle . yz=autoTimestamp();resultRecord=vec4(float(ui . w),1.0,0.0,0.0);}if(index==29)return statsLow;if(index==30)return statsHigh;if(index==31)return cycle;if(index==36)return resultRecord;return value;}vec4 masterCountLimb(ivec4 counts,int limb){if(limb==1)counts/=1024;if(limb==2)counts/=1048576;return vec4(counts-(counts/1024)*1024);}vec4 masterPlyRecord(int total,float halfmove){int middle=total/1024;int high=middle/1024;return vec4(float(total-middle*1024),float(middle-high*1024),float(high),halfmove);}vec4 masterRows(int index){if(index<64)return masterData(index);int count=activeBoardCount();if(index>=256){int board=index-256;if(board>=count)return vec4(0.0);return vec4(gameDataAt(board,17). w,gameDataAt(board,16). x,gameDataAt(board,27). z,gameDataAt(board,25). x);}if(index>=224)return vec4(0.0);int row=(index-64)/8;int field=index-64-row*8;if(row>=gridSide()||count==0)return vec4(0.0);ivec4 counts=ivec4(0);vec4 total=vec4(0.0);int plies=0;for(int column=0;column<20;++column){if(column>=gridSide())break;int board=row*gridSide()+column;if(field<3){ivec3 value=ivec3(gameDataAt(board,29). xyz)+1024*ivec3(gameDataAt(board,30). xyz);counts+=ivec4(value,value . x+value . y+value . z);}else if(field==3){bool running=gameDataAt(board,17). w==0.0;total+=vec4(running?1.0:0.0,running&&gameDataAt(board,16). x>0.0?1.0:0.0,running&&gameDataAt(board,18). w>0.5?1.0:0.0,1.0);}else if(field==4){int result=int(gameDataAt(board,17). w);bool white=result==1||result==9;bool black=result==2||result==10;total+=vec4(white?1.0:0.0,black?1.0:0.0,result!=0&&!white&&!black?1.0:0.0,gameDataAt(board,30). w>0.5?1.0:0.0);}else if(field==5){plies+=int(gameDataAt(board,18). z)+1024*int(gameDataAt(board,22). z);total . w=max(total . w,gameDataAt(board,16). w);}else if(field==7)total=max(total,gameDataAt(board,25));}if(field<3)return masterCountLimb(counts,field);if(field==5)return masterPlyRecord(plies,total . w);return total;}vec4 masterFinish(int index){if(index>=64)return masterData(index);if(index==6)return vec4(float(boardConfiguration()),float(gridSide()),float(storageCapacity()),123.0);if(index==7){float speed=autoSpeedCode();return vec4(uAutoPlay?1.0:0.0,mod(speed,256.0),floor(speed/256.0),float(autoBatchSize()));}if(index>9)return vec4(0.0);ivec4 counts=ivec4(0);vec4 total=vec4(0.0);int plies=0;for(int row=0;row<20;++row){if(row>=gridSide())break;int base=64+row*8;if(index<3||index==9){counts+=ivec4(masterData(base))+1024*ivec4(masterData(base+1))+1048576*ivec4(masterData(base+2));}else if(index==3||index==4)total+=masterData(base+index);else if(index==5){vec4 value=masterData(base+5);plies+=int(value . x)+1024*int(value . y)+1048576*int(value . z);total . w=max(total . w,value . w);}else if(index==8)total=max(total,masterData(base+7));}if(index<3)return masterCountLimb(counts,index);if(index==5)return masterPlyRecord(plies,total . w);if(index==9){int previous=masterTotal();bool same=int(masterData(6). x)==boardConfiguration();int increase=counts . w-previous;float newlyFinished=same&&increase>0?float(increase):0.0;return vec4(newlyFinished,float(focusBoard()),float(requestedBoardCount()),gridStorageReady()?1.0:0.0);}return total;}const float INSET=0.055;const float BOARD_SIZE=0.89;float gRenderSize=1.0;float gPixelSeed=0.0;vec4 gLastResult=vec4(0.0);bool gridDashboard(){return gridSide()>1;}float gridMargin(){return max(10.0,min(RENDERSIZE . x,RENDERSIZE . y)*0.012);}float gridTop(){return RENDERSIZE . y-gridMargin()-30.0;}vec4 gridMatrixRect(){float margin=gridMargin();float width=RENDERSIZE . x-2.0*margin-22.0;float height=gridTop()-margin;float size=max(1.0,min(width,height-122.0));float groupWidth=size+22.0;float groupHeight=size+152.0;return vec4((RENDERSIZE . x-groupWidth)*0.5+22.0,(RENDERSIZE . y-groupHeight)*0.5+122.0,size,size);}vec4 gridInfoRect(){vec4 matrix=gridMatrixRect();return vec4(matrix . x-22.0,matrix . y-122.0,matrix . z+22.0,110.0);}vec4 gridFocusRect(){vec4 info=gridInfoRect();return vec4(info . xy+10.0,(info . z-32.0)*0.47,info . w-20.0);}vec4 gridMasterRect(){vec4 info=gridInfoRect(),local=gridFocusRect();float left=local . x+local . z+12.0;return vec4(left,info . y+10.0,info . x+info . z-10.0-left,info . w-20.0);}bool chessWide(){return RENDERSIZE . x>=RENDERSIZE . y*1.36;}float chessLayoutSize(){if(gridDashboard())return max(1.0,min(RENDERSIZE . x,RENDERSIZE . y));if(chessWide())return min(RENDERSIZE . x*0.54,RENDERSIZE . y*0.70);return min(RENDERSIZE . x*0.91,RENDERSIZE . y*0.56);}float chessSize(){return gRenderSize;}vec2 chessOrigin(){if(gridDashboard())return gridMatrixRect(). xy;float size=chessSize();if(!chessWide())return vec2((RENDERSIZE . x-size)*0.5,(RENDERSIZE . y-1.72*size)*0.5+0.600*size);return vec2((RENDERSIZE . x-size)*0.5,(RENDERSIZE . y-1.39*size)*0.5+0.270*size);}vec2 chessPoint(vec2 pixel){return(pixel-chessOrigin())/chessSize();}float sdBox(vec2 p,vec2 b){vec2 q=abs(p)-b;return length(max(q,0.0))+min(max(q . x,q . y),0.0);}float sdRoundBox(vec2 p,vec2 b,float r){return sdBox(p,b-r)-r;}float sdCircle(vec2 p,float r){return length(p)-r;}float sdCapsule(vec2 p,vec2 a,vec2 b,float r){vec2 pa=p-a,ba=b-a;return length(pa-ba*clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0))-r;}float sdTrapezoid(vec2 p,float bottom,float top,float height){vec2 k1=vec2(top,height);vec2 k2=vec2(top-bottom,2.0*height);p . x=abs(p . x);vec2 ca=vec2(max(0.0,p . x-((p . y<0.0)?bottom:top)),abs(p . y)-height);vec2 cb=p-k1+k2*clamp(dot(k1-p,k2)/dot(k2,k2),0.0,1.0);float signValue=(cb . x<0.0&&ca . y<0.0)?-1.0:1.0;return signValue*sqrt(min(dot(ca,ca),dot(cb,cb)));}float sdEllipse(vec2 p,vec2 radii){float k0=length(p/radii);float k1=length(p/(radii*radii));if(k0<0.00001)return-min(radii . x,radii . y);return k0*(k0-1.0)/max(k1,0.00001);}void polygonEdge(vec2 p,vec2 a,vec2 b,inout float d,inout float side){vec2 e=b-a;vec2 w=p-a;vec2 q=w-e*clamp(dot(w,e)/dot(e,e),0.0,1.0);d=min(d,dot(q,q));bool up=p . y>=a . y;bool down=p . y<b . y;bool crossPositive=e . x*w . y>e . y*w . x;if((up&&down&&crossPositive)||(!up&&!down&&!crossPositive))side=-side;}float knightOutline(vec2 p){float d=1.0e5;float side=1.0;polygonEdge(p,vec2(-0.174,-0.218),vec2(0.184,-0.218),d,side);polygonEdge(p,vec2(-0.135,-0.106),vec2(-0.174,-0.218),d,side);polygonEdge(p,vec2(-0.101,-0.021),vec2(-0.135,-0.106),d,side);polygonEdge(p,vec2(-0.156,0.049),vec2(-0.101,-0.021),d,side);polygonEdge(p,vec2(-0.218,0.035),vec2(-0.156,0.049),d,side);polygonEdge(p,vec2(-0.277,0.082),vec2(-0.218,0.035),d,side);polygonEdge(p,vec2(-0.253,0.146),vec2(-0.277,0.082),d,side);polygonEdge(p,vec2(-0.158,0.221),vec2(-0.253,0.146),d,side);polygonEdge(p,vec2(-0.097,0.255),vec2(-0.158,0.221),d,side);polygonEdge(p,vec2(-0.078,0.347),vec2(-0.097,0.255),d,side);polygonEdge(p,vec2(-0.017,0.292),vec2(-0.078,0.347),d,side);polygonEdge(p,vec2(0.059,0.299),vec2(-0.017,0.292),d,side);polygonEdge(p,vec2(0.148,0.232),vec2(0.059,0.299),d,side);polygonEdge(p,vec2(0.206,0.124),vec2(0.148,0.232),d,side);polygonEdge(p,vec2(0.217,-0.036),vec2(0.206,0.124),d,side);polygonEdge(p,vec2(0.146,-0.189),vec2(0.217,-0.036),d,side);polygonEdge(p,vec2(0.184,-0.218),vec2(0.146,-0.189),d,side);return side*sqrt(d)-0.006;}float queenCrown(vec2 p){float d=1.0e5;float side=1.0;polygonEdge(p,vec2(-0.147,0.082),vec2(0.147,0.082),d,side);polygonEdge(p,vec2(-0.217,0.273),vec2(-0.147,0.082),d,side);polygonEdge(p,vec2(-0.163,0.218),vec2(-0.217,0.273),d,side);polygonEdge(p,vec2(-0.118,0.331),vec2(-0.163,0.218),d,side);polygonEdge(p,vec2(-0.060,0.230),vec2(-0.118,0.331),d,side);polygonEdge(p,vec2(0.000,0.305),vec2(-0.060,0.230),d,side);polygonEdge(p,vec2(0.060,0.230),vec2(0.000,0.305),d,side);polygonEdge(p,vec2(0.118,0.331),vec2(0.060,0.230),d,side);polygonEdge(p,vec2(0.163,0.218),vec2(0.118,0.331),d,side);polygonEdge(p,vec2(0.217,0.273),vec2(0.163,0.218),d,side);polygonEdge(p,vec2(0.147,0.082),vec2(0.217,0.273),d,side);d=side*sqrt(d);d=min(d,sdCircle(p-vec2(-0.217,0.273),0.028));d=min(d,sdCircle(p-vec2(-0.118,0.331),0.028));d=min(d,sdCircle(p-vec2(0.000,0.305),0.028));d=min(d,sdCircle(p-vec2(0.118,0.331),0.028));d=min(d,sdCircle(p-vec2(0.217,0.273),0.028));return d;}float pieceDistance(vec2 p,int type){float d=sdRoundBox(p-vec2(0.0,-0.313),vec2(0.245,0.041),0.021);d=min(d,sdRoundBox(p-vec2(0.0,-0.250),vec2(0.205,0.028),0.015));d=min(d,sdTrapezoid(p-vec2(0.0,-0.213),0.181,0.155,0.022));if(type==1){d=min(d,sdTrapezoid(p-vec2(0.0,-0.094),0.158,0.065,0.111));d=min(d,sdRoundBox(p-vec2(0.0,0.033),vec2(0.124,0.027),0.012));d=min(d,sdCircle(p-vec2(0.0,0.166),0.110));}else if(type==2){d=min(d,knightOutline(p));}else if(type==3){d=min(d,sdTrapezoid(p-vec2(0.0,-0.071),0.158,0.062,0.137));d=min(d,sdRoundBox(p-vec2(0.0,0.061),vec2(0.133,0.025),0.012));float mitre=sdEllipse(p-vec2(0.0,0.197),vec2(0.108,0.143));mitre=min(mitre,sdCircle(p-vec2(0.0,0.333),0.030));mitre=max(mitre,-sdCapsule(p,vec2(-0.027,0.176),vec2(0.106,0.300),0.017));d=min(d,mitre);}else if(type==4){d=min(d,sdTrapezoid(p-vec2(0.0,-0.080),0.157,0.131,0.132));d=min(d,sdRoundBox(p-vec2(0.0,0.046),vec2(0.163,0.023),0.008));float tower=sdTrapezoid(p-vec2(0.0,0.135),0.140,0.182,0.087);tower=min(tower,sdRoundBox(p-vec2(0.0,0.211),vec2(0.205,0.081),0.006));tower=max(tower,-sdBox(p-vec2(-0.071,0.285),vec2(0.033,0.065)));tower=max(tower,-sdBox(p-vec2(0.071,0.285),vec2(0.033,0.065)));d=min(d,tower);}else if(type==5){d=min(d,sdTrapezoid(p-vec2(0.0,-0.072),0.170,0.101,0.140));d=min(d,sdRoundBox(p-vec2(0.0,0.073),vec2(0.155,0.024),0.010));d=min(d,queenCrown(p));}else if(type==6){d=min(d,sdTrapezoid(p-vec2(0.0,-0.077),0.169,0.091,0.136));d=min(d,sdRoundBox(p-vec2(0.0,0.061),vec2(0.145,0.024),0.010));d=min(d,sdEllipse(p-vec2(0.0,0.135),vec2(0.133,0.088)));d=min(d,sdRoundBox(p-vec2(0.0,0.217),vec2(0.069,0.020),0.009));d=min(d,sdRoundBox(p-vec2(0.0,0.294),vec2(0.027,0.085),0.004));d=min(d,sdRoundBox(p-vec2(0.0,0.322),vec2(0.082,0.024),0.004));}return d;}float pieceDetail(vec2 p,int type){float d=sdCapsule(p,vec2(-0.200,-0.286),vec2(0.200,-0.286),0.0050);d=min(d,sdCapsule(p,vec2(-0.160,-0.228),vec2(0.160,-0.228),0.0045));if(type==1){d=min(d,sdCapsule(p,vec2(-0.097,0.026),vec2(0.097,0.026),0.004));}else if(type==2){d=min(d,sdCircle(p-vec2(-0.105,0.182),0.016));d=min(d,sdCapsule(p,vec2(-0.238,0.100),vec2(-0.191,0.112),0.006));d=min(d,sdCapsule(p,vec2(0.055,0.247),vec2(0.120,0.171),0.005));d=min(d,sdCapsule(p,vec2(0.120,0.171),vec2(0.151,0.065),0.005));d=min(d,sdCapsule(p,vec2(0.151,0.065),vec2(0.139,-0.050),0.005));}else if(type==3){d=min(d,sdCapsule(p,vec2(-0.102,0.054),vec2(0.102,0.054),0.004));}else if(type==4){d=min(d,sdCapsule(p,vec2(-0.135,0.058),vec2(0.135,0.058),0.0045));d=min(d,sdCapsule(p,vec2(-0.157,0.153),vec2(0.157,0.153),0.004));}else if(type==5){d=min(d,sdCapsule(p,vec2(-0.122,0.087),vec2(0.122,0.087),0.005));}else if(type==6){d=min(d,sdCapsule(p,vec2(-0.115,0.057),vec2(0.115,0.057),0.0045));}return d;}float coverage(float d,float aa){return 1.0-smoothstep(-aa,aa,d);}vec3 drawPiece(vec3 under,vec2 p,int piece,float aa){int type=piece<0?-piece:piece;float shadow=pieceDistance(p-vec2(0.022,-0.034),type);under*=1.0-0.34*(1.0-smoothstep(-0.015,0.052,shadow));float d=pieceDistance(p,type);float white=piece>0?1.0:0.0;vec3 outline=mix(vec3(1.00,0.53,0.11),vec3(0.010,0.023,0.030),white);under=mix(under,outline,coverage(d-0.016,aa));vec3 material=mix(vec3(0.018,0.042,0.054),vec3(0.995,0.982,0.900),white);material+=(p . y+0.15)*mix(0.036,0.030,white);material-=p . x*0.055;material+=0.027*exp(-90.0*pow(p . x+0.065+0.11*p . y,2.0));float bevel=exp(-max(-d,0.0)*80.0);material+=bevel*(0.023+0.065*p . y-0.068*p . x);float detail=coverage(pieceDetail(p,type),aa*0.8);vec3 engraving=mix(vec3(0.22,0.65,0.69),vec3(0.15,0.20,0.22),white);material=mix(material,engraving,detail*mix(0.55,0.45,white));return mix(under,material,coverage(d,aa));}vec2 atlasFontBits(int glyph){if(glyph==1)return vec2(1033777.0,14897.0);if(glyph==2)return vec2(1001022.0,31281.0);if(glyph==3)return vec2(541199.0,15888.0);if(glyph==4)return vec2(575038.0,31281.0);if(glyph==5)return vec2(999967.0,32272.0);if(glyph==6)return vec2(999952.0,32272.0);if(glyph==7)return vec2(771631.0,15888.0);if(glyph==8)return vec2(1033777.0,17969.0);if(glyph==9)return vec2(135327.0,31876.0);if(glyph==10)return vec2(84556.0,7234.0);if(glyph==11)return vec2(807505.0,18004.0);if(glyph==12)return vec2(541215.0,16912.0);if(glyph==13)return vec2(706097.0,18293.0);if(glyph==14)return vec2(708209.0,18233.0);if(glyph==15)return vec2(575022.0,14897.0);if(glyph==16)return vec2(999952.0,31281.0);if(glyph==17)return vec2(579149.0,14897.0);if(glyph==18)return vec2(1004113.0,31281.0);if(glyph==19)return vec2(459838.0,15888.0);if(glyph==20)return vec2(135300.0,31876.0);if(glyph==21)return vec2(575022.0,17969.0);if(glyph==22)return vec2(574788.0,17969.0);if(glyph==23)return vec2(710314.0,17969.0);if(glyph==24)return vec2(141873.0,17962.0);if(glyph==25)return vec2(135300.0,17962.0);if(glyph==26)return vec2(139807.0,31778.0);if(glyph==27)return vec2(714286.0,14899.0);if(glyph==28)return vec2(135310.0,4484.0);if(glyph==29)return vec2(69919.0,14881.0);if(glyph==30)return vec2(459838.0,30753.0);if(glyph==31)return vec2(621634.0,2250.0);if(glyph==32)return vec2(984126.0,32272.0);if(glyph==33)return vec2(1001006.0,14864.0);if(glyph==34)return vec2(139528.0,31778.0);if(glyph==35)return vec2(476718.0,14897.0);if(glyph==36)return vec2(492590.0,14897.0);if(glyph==37)return vec2(139792.0,1058.0);if(glyph==38)return vec2(1015808.0,0.0);if(glyph==39)return vec2(198.0,0.0);if(glyph==40)return vec2(6336.0,198.0);if(glyph==41)return vec2(1020032.0,132.0);if(glyph==42)return vec2(69904.0,16644.0);if(glyph==43)return vec2(270466.0,2184.0);if(glyph==44)return vec2(67720.0,8322.0);if(glyph==45)return vec2(139974.0,26436.0);return vec2(0.0);}vec4 atlasLabelPack(int label,int part){vec4 value=vec4(0.0);if(label==1){if(part==0)value=vec4(5280279.0,4014085.0,5829440.0,5.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==2){if(part==0)value=vec4(791298.0,4014091.0,5829440.0,5.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==3){if(part==0)value=vec4(5280279.0,3706885.0,1343680.0,707.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==4){if(part==0)value=vec4(791298.0,3706891.0,1343680.0,707.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==5){if(part==0)value=vec4(5280279.0,2453509.0,1230.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==6){if(part==0)value=vec4(791298.0,2453515.0,1230.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==7){if(part==0)value=vec4(6034564.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==8){if(part==0)value=vec4(807427.0,5247819.0,5.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==9){if(part==0)value=vec4(3151123.0,5247813.0,5.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==10){if(part==0)value=vec4(1052996.0,5043200.0,3970313.0,14.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==11){if(part==0)value=vec4(1401414.0,1098694.0,4215936.0,5281029.0);if(part==1)value=vec4(58313.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==12){if(part==0)value=vec4(3409954.0,21903.0,1361234.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==13){if(part==0)value=vec4(6034564.0,311488.0,1069897.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==14){if(part==0)value=vec4(94542.0,1364039.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==15){if(part==0)value=vec4(4231942.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==16){if(part==0)value=vec4(2364163.0,4734989.0,1473.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==17){if(part==0)value=vec4(3470480.0,21775.0,3764304.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==18){if(part==0)value=vec4(843843.0,773.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==19){if(part==0)value=vec4(1332561.0,14.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==20){if(part==0)value=vec4(2946002.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==21){if(part==0)value=vec4(2175554.0,1039.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==22){if(part==0)value=vec4(1872779.0,1288.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==23){if(part==0)value=vec4(3470470.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==24){if(part==0)value=vec4(980.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==25){if(part==0)value=vec4(3470480.0,3970319.0,14.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==26){if(part==0)value=vec4(3994115.0,1573203.0,54226.0,4014117.0);if(part==1)value=vec4(57920.0,5301187.0,5030866.0,4196736.0);if(part==2)value=vec4(5058898.0,5829440.0,5.0,0.0);}if(label==27){if(part==0)value=vec4(5002384.0,1368083.0,290839.0,2359629.0);if(part==1)value=vec4(3944462.0,4007182.0,5244108.0,1384463.0);if(part==2)value=vec4(4723987.0,20.0,0.0,0.0);}if(label==28){if(part==0)value=vec4(62932.0,6558480.0,787589.0,5058888.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==29){if(part==0)value=vec4(6034564.0,102528.0,1384897.0,3691333.0);if(part==1)value=vec4(20.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==30){if(part==0)value=vec4(2437458.0,5247879.0,58313.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==31){if(part==0)value=vec4(3409632.0,21903.0,1361234.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==32){if(part==0)value=vec4(1384980.0,3207557.0,1384452.0,2441552.0);if(part==1)value=vec4(3732052.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==33){if(part==0)value=vec4(6034564.0,352320.0,529161.0,2359628.0);if(part==1)value=vec4(3944462.0,4007182.0,1228.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==34){if(part==0)value=vec4(1360649.0,49223.0,1401805.0,5245312.0);if(part==1)value=vec4(263762.0,1872384.0,1872648.0,1070344.0);if(part==2)value=vec4(5575872.0,21633.0,0.0,0.0);}if(label==35){if(part==0)value=vec4(6034564.0,311488.0,262985.0,1069906.0);if(part==1)value=vec4(4983168.0,807685.0,3985428.0,262486.0);if(part==2)value=vec4(4194574.0,5058898.0,5829440.0,5.0);}if(label==36){if(part==0)value=vec4(1049550.0,94290.0,2364163.0,5771277.0);if(part==1)value=vec4(311873.0,21250.0,74694.0,5018132.0);if(part==2)value=vec4(5043200.0,3970313.0,14.0,0.0);}if(label==37){if(part==0)value=vec4(324358.0,5513236.0,4739462.0,1384467.0);if(part==1)value=vec4(4756817.0,261.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==38){if(part==0)value=vec4(5018132.0,5042688.0,274452.0,5305230.0);if(part==1)value=vec4(4015296.0,5243218.0,786760.0,5058888.0);if(part==2)value=vec4(5043200.0,3970313.0,14.0,0.0);}if(label==39){if(part==0)value=vec4(529285.0,1573196.0,5247948.0,4723968.0);if(part==1)value=vec4(5062983.0,62720.0,6558480.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==40){if(part==0)value=vec4(807504.0,1363973.0,6628301.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==41){if(part==0)value=vec4(4720732.0,4231.0,8261669.0,3151232.0);if(part==1)value=vec4(78165.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==42){if(part==0)value=vec4(291148.0,8261644.0,8652288.0,31.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==43){if(part==0)value=vec4(3470470.0,5245568.0,15.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==44){if(part==0)value=vec4(291148.0,274444.0,20995.0,3981349.0);if(part==1)value=vec4(1069763.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==45){if(part==0)value=vec4(1401170.0,562386.0,2097484.0,4015305.0);if(part==1)value=vec4(1618.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==46){if(part==0)value=vec4(116764.0,5305107.0,19.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==47){if(part==0)value=vec4(5055811.0,1167.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==48){if(part==0)value=vec4(3756995.0,20.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==49){if(part==0)value=vec4(2388306.0,4740371.0,19.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==50){if(part==0)value=vec4(1327699.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==51){if(part==0)value=vec4(103184.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==52){if(part==0)value=vec4(1622088.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==53){if(part==0)value=vec4(1376594.0,1281.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==54){if(part==0)value=vec4(1029.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==55){if(part==0)value=vec4(5320771.0,1892940.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==56){if(part==0)value=vec4(2364163.0,13.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==57){if(part==0)value=vec4(5280279.0,5.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==58){if(part==0)value=vec4(791298.0,11.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==59){if(part==0)value=vec4(4015425.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==60){if(part==0)value=vec4(4015425.0,788800.0,3212111.0,21765.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==61){if(part==0)value=vec4(4015425.0,312320.0,151577.0,1106002.0);if(part==1)value=vec4(3146575.0,3150277.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==62){if(part==0)value=vec4(5321028.0,5247881.0,5039049.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==63){if(part==0)value=vec4(5320774.0,83141.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==64){if(part==0)value=vec4(336293.0,333.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==65){if(part==0)value=vec4(727.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==66){if(part==0)value=vec4(1111.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==67){if(part==0)value=vec4(706.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==68){if(part==0)value=vec4(1090.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==69){if(part==0)value=vec4(1376594.0,1281.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==70){if(part==0)value=vec4(1760.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==71){if(part==0)value=vec4(5583186.0,1292.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==72){if(part==0)value=vec4(5248275.0,8765445.0,7604608.0,31.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==73){if(part==0)value=vec4(2441409.0,342.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==74){if(part==0)value=vec4(3699283.0,4194565.0,1323337.0,19.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==75){if(part==0)value=vec4(4793667.0,82821.0,352293.0,16972.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==76){if(part==0)value=vec4(18.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==77){if(part==0)value=vec4(7.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==78){if(part==0)value=vec4(2.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==79){if(part==0)value=vec4(1.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==80){if(part==0)value=vec4(1401420.0,6329344.0,4981509.0,1392724.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==81){if(part==0)value=vec4(3745108.0,0.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==82){if(part==0)value=vec4(5321288.0,103567.0,1388882.0,20.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==83){if(part==0)value=vec4(6292436.0,1575232.0,54226.0,25.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==84){if(part==0)value=vec4(95180.0,2367523.0,9700564.0,554112.0);if(part==1)value=vec4(1.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==85){if(part==0)value=vec4(1053010.0,6031680.0,1393234.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==86){if(part==0)value=vec4(291148.0,3985420.0,78166.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==87){if(part==0)value=vec4(4781331.0,9699589.0,5247808.0,515.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==88){if(part==0)value=vec4(1365121.0,4.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==89){if(part==0)value=vec4(1106002.0,847.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==90){if(part==0)value=vec4(4248515.0,1392972.0,290820.0,78157.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==91){if(part==0)value=vec4(5280279.0,2453509.0,1230.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==92){if(part==0)value=vec4(791298.0,2453515.0,1230.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==93){if(part==0)value=vec4(6034564.0,19.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==94){if(part==0)value=vec4(1401805.0,80211.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==95){if(part==0)value=vec4(1376594.0,1281.0,0.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==96){if(part==0)value=vec4(5341518.0,3412416.0,5.0,0.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==97){if(part==0)value=vec4(1364039.0,3469504.0,5264144.0,151557.0);if(part==1)value=vec4(5321042.0,2442369.0,462.0,0.0);}if(label==98){if(part==0)value=vec4(5058899.0,58313.0,345044.0,12.0);if(part==1)value=vec4(0.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==99){if(part==0)value=vec4(2413132.0,151572.0,1388882.0,5320724.0);if(part==1)value=vec4(79105.0,0.0,0.0,0.0);if(part==2)value=vec4(0.0,0.0,0.0,0.0);}if(label==101){if(part==0)value=vec4(3691535.0,29577.0,4800589.0,1545.0);}if(label==102){if(part==0)value=vec4(5518278.0,16723.0,4723650.0,4.0);}if(label==103){if(part==0)value=vec4(5320780.0,5002368.0,82709.0,0.0);}if(label==105){if(part==0)value=vec4(49921.0,4723650.0,1220.0,0.0);}if(label==106){if(part==0)value=vec4(3728722.0,29577.0,0.0,0.0);}if(label==107){if(part==0)value=vec4(807427.0,1227.0,0.0,0.0);}if(label==108){if(part==0)value=vec4(4793667.0,82821.0,1348368.0,19.0);}if(label==109){if(part==0)value=vec4(2437458.0,786778.0,353153.0,19.0);}if(label==110){if(part==0)value=vec4(5574994.0,1070217.0,6329344.0,78597.0);}if(label==111){if(part==0)value=vec4(2364801.0,3153996.0,2424837.0,5030232.0);}if(label==112){if(part==0)value=vec4(5280279.0,4255749.0,3707781.0,7.0);}if(label==113){if(part==0)value=vec4(791298.0,1384459.0,103184.0,0.0);}if(label==115){if(part==0)value=vec4(270802.0,3148096.0,7341519.0,2367515.0);if(part==1)value=vec4(1236.0,0.0,0.0,0.0);}return value;}float atlasLabelLength(int label){float value=0.0;if(label==1)value=13.0;if(label==2)value=13.0;if(label==3)value=14.0;if(label==4)value=14.0;if(label==5)value=10.0;if(label==6)value=10.0;if(label==7)value=4.0;if(label==8)value=9.0;if(label==9)value=9.0;if(label==10)value=13.0;if(label==11)value=19.0;if(label==12)value=12.0;if(label==13)value=12.0;if(label==14)value=8.0;if(label==15)value=4.0;if(label==16)value=10.0;if(label==17)value=12.0;if(label==18)value=6.0;if(label==19)value=5.0;if(label==20)value=4.0;if(label==21)value=6.0;if(label==22)value=6.0;if(label==23)value=4.0;if(label==24)value=2.0;if(label==25)value=9.0;if(label==26)value=41.0;if(label==27)value=37.0;if(label==28)value=16.0;if(label==29)value=17.0;if(label==30)value=11.0;if(label==31)value=12.0;if(label==32)value=20.0;if(label==33)value=26.0;if(label==34)value=39.0;if(label==35)value=45.0;if(label==36)value=41.0;if(label==37)value=22.0;if(label==38)value=41.0;if(label==39)value=28.0;if(label==40)value=12.0;if(label==41)value=19.0;if(label==42)value=13.0;if(label==43)value=9.0;if(label==44)value=20.0;if(label==45)value=18.0;if(label==46)value=9.0;if(label==47)value=6.0;if(label==48)value=5.0;if(label==49)value=9.0;if(label==50)value=4.0;if(label==51)value=3.0;if(label==52)value=4.0;if(label==53)value=6.0;if(label==54)value=2.0;if(label==55)value=8.0;if(label==56)value=5.0;if(label==57)value=5.0;if(label==58)value=5.0;if(label==59)value=4.0;if(label==60)value=15.0;if(label==61)value=24.0;if(label==62)value=12.0;if(label==63)value=7.0;if(label==64)value=6.0;if(label==65)value=2.0;if(label==66)value=2.0;if(label==67)value=2.0;if(label==68)value=2.0;if(label==69)value=6.0;if(label==70)value=2.0;if(label==71)value=6.0;if(label==72)value=13.0;if(label==73)value=6.0;if(label==74)value=13.0;if(label==75)value=15.0;if(label==76)value=1.0;if(label==77)value=1.0;if(label==78)value=1.0;if(label==79)value=1.0;if(label==80)value=16.0;if(label==81)value=4.0;if(label==82)value=13.0;if(label==83)value=13.0;if(label==84)value=17.0;if(label==85)value=12.0;if(label==86)value=11.0;if(label==87)value=14.0;if(label==88)value=5.0;if(label==89)value=6.0;if(label==90)value=15.0;if(label==91)value=10.0;if(label==92)value=10.0;if(label==93)value=5.0;if(label==94)value=7.0;if(label==95)value=6.0;if(label==96)value=9.0;if(label==97)value=26.0;if(label==98)value=13.0;if(label==99)value=19.0;if(label==101)value=14.0;if(label==102)value=13.0;if(label==103)value=11.0;if(label==105)value=10.0;if(label==106)value=7.0;if(label==107)value=6.0;if(label==108)value=13.0;if(label==109)value=13.0;if(label==110)value=15.0;if(label==111)value=16.0;if(label==112)value=13.0;if(label==113)value=11.0;if(label==115)value=18.0;return value;}const int ATLAS_GLYPH_COUNT=46;const int ATLAS_GLYPH_COLUMNS=10;const int ATLAS_GLYPH_PITCH=6;const int ATLAS_LABEL_COUNT=118;const int ATLAS_TEXT_OFFSET=2560;const int ATLAS_LENGTH_OFFSET=3976;vec2 atlasTablePixel(int index){float n=float(index);return vec2(mod(n,64.0),floor(n/64.0))+0.5;}vec4 buildTextAtlas(ivec2 pixel){if(pixel . x>=64||pixel . y>=64)return vec4(0.0);if(pixel . x==63&&pixel . y==63)return vec4(1.0,0.0,1.0,1.0);vec4 sentinel=IMG_PIXEL(textAtlas,vec2(63.5));if(sentinel . r>0.99&&sentinel . g<0.01&&sentinel . b>0.99&&sentinel . a>0.99)return IMG_PIXEL(textAtlas,vec2(float(pixel . x),float(pixel . y))+0.5);if(pixel . y<40){int column=pixel . x/ATLAS_GLYPH_PITCH,row=pixel . y/8;int glyph=column+row*ATLAS_GLYPH_COLUMNS;int x=pixel . x-column*ATLAS_GLYPH_PITCH;int y=pixel . y-row*8;if(column>=ATLAS_GLYPH_COLUMNS||glyph>=ATLAS_GLYPH_COUNT||x>=5||y>=7)return vec4(0.0);vec2 data=atlasFontBits(glyph);float word=y<4?data . x:data . y;float shift=float((y<4?y:y-4)*5+4-x);float bit=mod(floor(word/exp2(shift)),2.0);return vec4(bit);}int index=(pixel . y-40)*64+pixel . x;if(index<ATLAS_LABEL_COUNT*12){int label=index/12;int chunk=index-label*12;int part=chunk/4;int component=chunk-part*4;vec4 words=atlasLabelPack(label,part);float word=words . x;if(component==1)word=words . y;if(component==2)word=words . z;if(component==3)word=words . w;return vec4(mod(word,64.0),mod(floor(word/64.0),64.0),mod(floor(word/4096.0),64.0),mod(floor(word/262144.0),64.0))/255.0;}if(index<ATLAS_LABEL_COUNT*13)return vec4(atlasLabelLength(index-ATLAS_LABEL_COUNT*12)/255.0,0.0,0.0,1.0);return vec4(0.0);}float labelLength(int label){return floor(IMG_PIXEL(textAtlas,atlasTablePixel(ATLAS_LENGTH_OFFSET+label)). r*255.0+0.5);}float glyphCoverage(vec2 p,int glyph,float pixel){vec2 q=p/pixel;if(glyph<=0||glyph>=ATLAS_GLYPH_COUNT||q . x<-0.5||q . x>5.5||q . y<-0.5||q . y>7.5)return 0.0;int row=glyph/ATLAS_GLYPH_COLUMNS;int column=glyph-row*ATLAS_GLYPH_COLUMNS;vec2 origin=vec2(float(column*ATLAS_GLYPH_PITCH),float(row*8));vec2 samplePoint=origin+clamp(q,vec2(-0.5),vec2(5.5,7.5));samplePoint . y=min(samplePoint . y,float(row*8)+7.5);float ink=IMG_PIXEL(textAtlas,samplePoint). r;if(column==0)ink*=clamp(q . x+0.5,0.0,1.0);if(row==0)ink*=clamp(q . y+0.5,0.0,1.0);float aa=clamp(0.65/(chessSize()*pixel),0.075,0.49);return smoothstep(0.5-aa,0.5+aa,ink);}float labelCoverageCount(vec2 p,int label,float pixel,float count){if(p . x<0.0||p . x>=count*6.0*pixel||p . y<-pixel||p . y>8.0*pixel)return 0.0;int character=int(floor(p . x/(6.0*pixel)));int chunk=character/4;int component=character-chunk*4;vec4 data=floor(IMG_PIXEL(textAtlas,atlasTablePixel(ATLAS_TEXT_OFFSET+label*12+chunk))*255.0+0.5);int glyph=packedPiece(data,component);vec2 local=vec2(p . x-float(character)*6.0*pixel,p . y);return glyphCoverage(local,glyph,pixel);}float labelCoverage(vec2 p,int label,float pixel){if(p . y<-pixel||p . y>8.0*pixel)return 0.0;return labelCoverageCount(p,label,pixel,labelLength(label));}vec3 labelLeft(vec3 color,vec2 uv,vec2 anchor,int label,float pixel,vec3 ink){return mix(color,ink,labelCoverage(uv-anchor,label,pixel));}vec3 labelRight(vec3 color,vec2 uv,vec2 anchor,int label,float pixel,vec3 ink){if(uv . y<anchor . y-pixel||uv . y>anchor . y+8.0*pixel)return color;float count=labelLength(label);anchor . x-=(count*6.0-1.0)*pixel;return mix(color,ink,labelCoverageCount(uv-anchor,label,pixel,count));}vec3 labelCenter(vec3 color,vec2 uv,vec2 anchor,int label,float pixel,vec3 ink){if(uv . y<anchor . y-pixel||uv . y>anchor . y+8.0*pixel)return color;float count=labelLength(label);anchor . x-=(count*6.0-1.0)*pixel*0.5;return mix(color,ink,labelCoverageCount(uv-anchor,label,pixel,count));}float boardCoordinate(vec2 p,int glyph){float pixel=0.00215;return glyphCoverage(p+vec2(2.5,3.5)*pixel,glyph,pixel);}vec3 squareReadout(vec3 color,vec2 uv,vec2 anchor,int square,vec3 ink){float pixel=0.0035;float alpha;if(square<0||square>63){alpha=glyphCoverage(uv-anchor,38,pixel);}else{int rank=square/8;int file=square-rank*8;alpha=glyphCoverage(uv-anchor,file+1,pixel);alpha+=glyphCoverage(uv-anchor-vec2(6.0*pixel,0.0),rank+28,pixel);}return mix(color,ink,min(alpha,1.0));}vec3 dataCyan(){return vec3(0.045,1.00,0.94);}vec3 dataAmber(){return vec3(1.00,0.53,0.055);}vec3 dataDraw(){return vec3(0.84,0.43,1.00);}vec3 dataInk(){return vec3(0.78,0.90,0.94);}vec3 channelInk(int channel){if(channel==0)return vec3(1.00,0.20,0.31);if(channel==1)return vec3(0.18,1.00,0.40);if(channel==2)return vec3(0.16,0.52,1.00);return vec3(0.90,0.96,1.00);}vec3 lastResultInk(){int result=int(gLastResult . x);if(result==1||result==9)return dataCyan();if(result==2||result==10)return dataAmber();return dataDraw();}float memoryPattern(float key){float h=fract(key*0.01371);return fract(h*(h+19.19)*41.17);}vec3 memoryShards(vec3 color,vec2 q,float value,float key,float energy,float emphasis,vec3 ink,float master){if(abs(value)<0.5||q . x<0.0||q . x>1.0||q . y<0.0||q . y>1.0)return color;float power=clamp(emphasis,0.3,3.0);float hit=floor(clamp(energy,0.0,1.0)*5.0)*0.2;float lanes=5.0+master*3.0;float lane=floor(q . y*lanes);float h=memoryPattern(key+lane*23.0+value*37.0);float lengthValue=0.13+floor(h*7.0)*0.105;float shift=(floor(h*9.0)-4.0)*0.024*power*(0.45+hit);float x=q . x-fract(h*17.0)*(0.93-lengthValue)-shift;float fragments=step(0.0,x)*step(x,lengthValue)*step(0.22,fract(x*(8.0+floor(h*9.0))+h));float y=abs(fract(q . y*lanes)-0.52);float streak=1.0-smoothstep(0.055,0.20,y);float echo=step(0.0,x+0.08*power)*step(x+0.08*power,lengthValue)*(1.0-smoothstep(0.025,0.10,abs(y-0.22)));float quiet=smoothstep(0.20,0.37,max(abs(q . x-0.5),abs(q . y-0.5)));if(master>0.5)quiet=q . y>0.53?0.13:1.0;float spark=step(0.73,h)*exp(-520.0*dot(vec2(q . x-fract(h*9.7),fract(q . y*lanes)-0.78),vec2(q . x-fract(h*9.7),fract(q . y*lanes)-0.78)));color*=1.0-fragments*streak*quiet*0.20;color+=(ink*fragments*streak+mix(ink,ink . brg,0.68)*echo*0.55)*quiet*power*(0.26+hit*0.58);color+=mix(ink,vec3(1.0),0.65)*spark*quiet*power*(0.24+hit*0.70);return color;}vec4 dataPanelRect(int panel){if(chessWide()){if(panel==0)return vec4(-0.390,0.515,0.335,0.485);if(panel==1)return vec4(1.055,0.530,0.335,0.470);if(panel==2)return vec4(1.055,0.015,0.335,0.465);return vec4(-0.390,0.015,0.335,0.450);}if(panel==0)return vec4(0.015,-0.445,0.290,0.282);if(panel==1)return vec4(0.355,-0.445,0.290,0.282);return vec4(0.695,-0.445,0.290,0.282);}bool inDataRect(vec2 uv,vec4 rect){vec2 p=uv-rect . xy;return p . x>=0.0&&p . y>=0.0&&p . x<rect . z&&p . y<rect . w;}vec3 instrumentPanel(vec3 color,vec2 uv,vec4 rect,vec3 accent,float energy){float aa=0.7/chessSize();vec2 p=uv-rect . xy-rect . zw*0.5;float d=sdRoundBox(p,rect . zw*0.5,0.008);color+=accent*(0.018+energy*0.022)*exp(-max(d,0.0)*130.0);vec3 surface=vec3(0.006,0.013,0.023)+0.005*(p . y/rect . w+0.5);color=mix(color,surface,coverage(d,aa));color=mix(color,accent*(0.48+energy*0.45),coverage(abs(d)-0.0007,aa));float top=sdBox(uv-vec2(rect . x+rect . z*0.5,rect . y+rect . w-0.002),vec2(rect . z*0.34,0.0008));color+=accent*coverage(top,aa)*(0.35+0.40*energy);return color;}vec3 numberRight(vec3 color,vec2 uv,vec2 anchor,int value,int digits,float pixel,vec3 ink){if(uv . y<anchor . y-pixel||uv . y>anchor . y+8.0*pixel)return color;float offset=(anchor . x-uv . x)/pixel;int place=int(floor(max((offset+0.5)/6.0,0.0)));if(offset<-0.5||place>=digits)return color;int magnitude=value<0?-value:value;int power=1;for(int i=0;i<9;++i)if(i<place)power*=10;if(place>0&&magnitude<power)return color;int quotient=magnitude/power;int digit=quotient-(quotient/10)*10;vec2 at=anchor-vec2((float(place)*6.0+5.0)*pixel,0.0);return mix(color,ink,glyphCoverage(uv-at,digit+27,pixel));}vec3 decimalRight(vec3 color,vec2 uv,vec2 anchor,float value,int decimals,int integerDigits,float pixel,vec3 ink){if(uv . y<anchor . y-pixel||uv . y>anchor . y+8.0*pixel)return color;float offset=(anchor . x-uv . x)/pixel;int place=int(floor(max((offset+0.5)/6.0,0.0)));if(offset<-0.5||place>=integerDigits+decimals+1)return color;int glyph=39;if(place!=decimals){int digitPlace=place>decimals?place-1:place;float magnitude=floor(abs(value)*pow(10.0,float(decimals))+0.5);float power=pow(10.0,float(digitPlace));if(place>decimals+1&&magnitude<power)return color;glyph=int(mod(floor(magnitude/power),10.0))+27;}vec2 at=anchor-vec2((float(place)*6.0+5.0)*pixel,0.0);return mix(color,ink,glyphCoverage(uv-at,glyph,pixel));}vec3 bitLamp(vec3 color,vec2 uv,vec2 center,float radius,bool on,vec3 ink,float pulse){float d=length(uv-center)-radius;float aa=0.65/chessSize();color+=ink*(on?0.12+pulse*0.16:0.006)*exp(-max(d,0.0)*330.0);return mix(color,on?ink*(0.8+0.2*pulse):vec3(0.08,0.14,0.145),coverage(d,aa));}vec3 completedGameStats(vec3 color,vec2 uv,vec4 pulse){bool wide=chessWide();vec4 rect=wide?vec4(-0.390,-0.252,1.780,0.102):vec4(0.015,-0.595,0.970,0.115);color=instrumentPanel(color,uv,rect,dataCyan(),pulse . x*0.12);if(!inDataRect(uv,rect))return color;vec4 stats=uiGameStats();vec3 drawInk=dataDraw();vec3 totalInk=vec3(0.98,0.98,0.91);float columnWidth=rect . z*0.25;int column=int(floor((uv . x-rect . x)/columnWidth));vec2 origin=rect . xy+vec2(float(column)*columnWidth,0.0);vec3 ink=totalInk;float count=stats . w;if(column==1){ink=dataCyan();count=stats . x;}if(column==2){ink=dataAmber();count=stats . y;}if(column==3){ink=drawInk;count=stats . z;}float titlePixel=wide?0.0026:0.0022;color=labelLeft(color,uv,origin+vec2(0.016,rect . w-0.022),90+column,titlePixel,ink);vec2 numberAt=origin+vec2(columnWidth-0.017,wide?0.044:0.055);color=numberRight(color,uv,numberAt,int(count),7,wide?0.0038:0.0035,ink);float ratePixel=wide?0.0028:0.0026;vec2 rateAt=origin+vec2(columnWidth-0.017,wide?0.0175:0.030);if(column==0){bool full=gameData(30). w>0.5;color=labelRight(color,uv,rateAt,full?99:98,wide?0.0018:0.00165,full?dataAmber():dataInk());}else if(stats . w>0.0){float rate=count*100.0/stats . w;color=decimalRight(color,uv,rateAt-vec2(6.0*ratePixel,0.0),rate,1,3,ratePixel,ink*0.87);color=mix(color,ink*0.87,glyphCoverage(uv-rateAt+vec2(5.0*ratePixel,0.0),45,ratePixel));}else{color=mix(color,dataInk(),glyphCoverage(uv-rateAt+vec2(5.0*ratePixel,0.0),38,ratePixel));}vec4 bar=vec4(rect . xy+vec2(0.016,0.008),rect . z-0.032,0.0045);if(inDataRect(uv,bar)){float x=(uv . x-bar . x)/bar . z;vec3 barInk=vec3(0.11,0.18,0.19);if(stats . w>0.0){barInk=drawInk;if(x<(stats . x+stats . y)/stats . w)barInk=dataAmber();if(x<stats . x/stats . w)barInk=dataCyan();}color=barInk*0.85;}return color;}float numericBit(float value,float bit){return mod(floor(mod(value,256.0)/exp2(bit)),2.0);}vec3 registerBits(vec3 color,vec2 uv,vec4 rect,float energy){if(!inDataRect(uv,rect))return color;vec2 q=(uv-rect . xy)/rect . zw*vec2(32.0,9.0);int column=int(floor(q . x));int channel=column/8;int bit=7-(column-channel*8);int row=int(floor(q . y));float value=float(packedPiece(gameData(16+row),channel));float active=numericBit(value,float(bit));float d=sdBox(fract(q)-0.5,vec2(0.35,0.30));float aa=0.6/(chessSize()*min(rect . z/32.0,rect . w/9.0));vec3 ink=channelInk(channel);color=memoryShards(color,fract(q),active,gPixelSeed+float(row*32+column)+value*3.0,energy+gLastResult . y,uBoardPixels,ink,0.0);color=mix(color,ink*(0.045+active*(0.88+0.17*energy)),coverage(d,aa));return color;}vec3 pieceMemory(vec3 color,vec2 uv,vec4 rect,vec4 pulse){bool wide=chessWide();float size=wide?0.285:0.168;vec2 origin=rect . xy+(wide?vec2(0.025,0.097):vec2(0.012,0.065));if(inDataRect(uv,vec4(origin,size,size))){vec2 q=(uv-origin)*8.0/size;int square=int(floor(q . x))+int(floor(q . y))*8;int piece=uiPiece(square);int type=piece<0?-piece:piece;vec2 p=fract(q)-0.5;float aa=0.7*8.0/(chessSize()*size);vec3 ink=piece>0?dataCyan():dataAmber();float d=sdRoundBox(p,vec2(0.44),0.045);vec3 cell=vec3(0.030,0.075,0.080);if(piece!=0)cell=ink*(0.16+float(type)*0.033);color=mix(color,cell,coverage(d,aa));color=memoryShards(color,fract(q),float(piece),gPixelSeed+float(square)*13.0,pulse . x+pulse . y+gLastResult . y,uBoardPixels,ink,0.0);int component=square-(square/4)*4;float channel=coverage(sdBox(p-vec2(0.0,-0.35),vec2(0.31,0.027)),aa);color=mix(color,channelInk(component),channel*(piece==0?0.20:0.65));vec2 center=origin+(floor(q)+0.5)*size/8.0;float fontPixel=size/8.0*0.071;float glyph=glyphCoverage(uv-center+vec2(2.5,2.6)*fontPixel,type+27,fontPixel);color=mix(color,piece==0?vec3(0.10,0.21,0.22):ink,glyph);if(square==uiData(5)||square==uiData(6)){float ring=coverage(abs(d)-0.026,aa);color=mix(color,mix(dataCyan(),dataAmber(),pulse . y),ring*(0.4+0.6*pulse . x));}}float titlePixel=wide?0.0028:0.00205;color=labelLeft(color,uv,rect . xy+vec2(0.014,rect . w-0.030),40,titlePixel,dataCyan());if(wide){color=labelLeft(color,uv,rect . xy+vec2(0.025,0.411),41,0.00195,dataInk());color=labelLeft(color,uv,rect . xy+vec2(0.025,0.046),74,0.0020,dataInk());color=bitLamp(color,uv,rect . xy+vec2(0.255,0.052),0.005,true,dataCyan(),pulse . x);color=bitLamp(color,uv,rect . xy+vec2(0.282,0.052),0.005,true,dataAmber(),pulse . y);}else{vec4 rules=gameData(16),hist=gameData(19);float x=rect . x+0.198;color=labelLeft(color,uv,vec2(x,rect . y+0.216),51,0.00150,dataInk());color=numberRight(color,uv,vec2(rect . x+0.278,rect . y+0.194),uiData(11),6,0.00215,dataCyan());color=labelLeft(color,uv,vec2(x,rect . y+0.165),52,0.00150,dataInk());color=numberRight(color,uv,vec2(rect . x+0.278,rect . y+0.143),int(rules . w),3,0.00215,dataAmber());color=labelLeft(color,uv,vec2(x,rect . y+0.114),53,0.00150,dataInk());color=numberRight(color,uv,vec2(rect . x+0.278,rect . y+0.092),int(hist . z),2,0.00215,dataCyan());color=registerBits(color,uv,vec4(rect . xy+vec2(0.012,0.014),0.266,0.029),pulse . x);for(int bit=0;bit<4;++bit)color=bitLamp(color,uv,vec2(x+0.011+float(bit)*0.020,rect . y+0.062),0.0032,numericBit(rules . y,float(bit))>0.5,bit<2?dataCyan():dataAmber(),pulse . x);}return color;}vec3 legalMemory(vec3 color,vec2 uv,vec4 rect,vec4 pulse){bool wide=chessWide();float size=wide?0.283:0.220;vec2 origin=rect . xy+(wide?vec2(0.026,0.102):vec2(0.035,0.027));bool locked=uiData(4)!=0;vec3 ink=uiData(0)>0?dataCyan():dataAmber();if(inDataRect(uv,vec4(origin,size,size))){vec2 q=(uv-origin)/size*64.0;int to=int(floor(q . x)),from=int(floor(q . y));float active=storedLegal(from,to);float glow=0.0;for(int dy=-1;dy<=1;++dy){for(int dx=-1;dx<=1;++dx){float bit=storedLegal(from+dy,to+dx);vec2 delta=q-floor(q)-vec2(float(dx),float(dy))-0.5;glow+=bit*exp(-2.9*dot(delta,delta));}}color=vec3(0.025,0.073,0.085);vec2 group=abs(fract(q/8.0)-0.5);float gridLine=max(smoothstep(0.475,0.5,group . x),smoothstep(0.475,0.5,group . y));color+=vec3(0.030,0.085,0.095)*gridLine;float scan=exp(-350.0*pow(fract(q . y/64.0-pulse . w*0.25+1.0)-0.5,2.0));float d=sdBox(fract(q)-0.5,vec2(0.38));float aa=0.65*64.0/(chessSize()*size);color+=ink*glow*(0.26+pulse . x*0.45);color=memoryShards(color,fract(q),active,gPixelSeed+float(from*64+to),pulse . x+pulse . y+gLastResult . y,uBoardPixels,ink,0.0);color=mix(color,ink*(0.94+0.20*scan),active*coverage(d,aa));color+=ink*scan*0.025;if(!uAutoPlay&&uiData(1)>=0){if(from==uiData(1)||to==uiData(10))color+=dataAmber()*0.10;}if(locked)color*=0.45;}int title=locked?44:42;color=labelLeft(color,uv,rect . xy+vec2(0.014,rect . w-0.026),title,wide?0.00235:0.00195,locked?dataAmber():dataCyan());if(wide){color=labelLeft(color,uv,rect . xy+vec2(0.026,0.407),86,0.00190,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.309,0.404),int(gameData(27). z),4,0.00260,ink);vec4 histogram=vec4(rect . xy+vec2(0.026,0.043),0.283,0.038);if(inDataRect(uv,histogram)){vec2 q=(uv-histogram . xy)/histogram . zw;int from=int(floor(q . x*64.0));float count=factData(from). r;if(q . y<count/32.0)color=mix(color,ink*0.7,0.75);}color=labelLeft(color,uv,rect . xy+vec2(0.026,0.017),62,0.00165,dataInk());color=labelRight(color,uv,rect . xy+vec2(0.309,0.017),43,0.00165,dataInk());}else{color=labelLeft(color,uv,rect . xy+vec2(0.035,0.006),83,0.00155,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.255,0.006),int(gameData(27). z),4,0.00175,ink);}return color;}vec3 historyMemory(vec3 color,vec2 uv,vec4 rect,vec4 pulse){bool wide=chessWide();vec4 hist=gameData(19);vec4 area=wide?vec4(rect . xy+vec2(0.019,0.111),0.297,0.272):vec4(rect . xy+vec2(0.013,0.070),0.264,0.172);vec2 shape=wide?vec2(13.0,12.0):vec2(16.0,10.0);if(inDataRect(uv,area)){vec2 q=(uv-area . xy)/area . zw*shape;int slot=int(floor(q . x)+floor(q . y)*shape . x);vec2 p=fract(q);bool valid=slot<151&&slot<int(hist . y);color=vec3(0.029,0.066,0.074);float frame=coverage(abs(sdBox(p-0.5,vec2(0.465)))-0.014,0.55/(chessSize()*min(area . z/shape . x,area . w/shape . y)));color=mix(color,vec3(0.08,0.19,0.21),frame*0.50);if(valid&&p . x>0.09&&p . x<0.91&&p . y>0.09&&p . y<0.91){vec2 memoryUV=(p-0.09)/0.82;int square=int(floor(memoryUV . x*8.0))+int(floor(memoryUV . y*8.0))*8;int column=square/4;int group=column/2;int code=packedPiece(gameData(64+slot*9+group),square-column*4);int piece=column==group*2?code/13-6:code-(code/13)*13-6;if(piece!=0){float strength=0.35+abs(float(piece))*0.055;vec3 ink=piece>0?dataCyan():dataAmber();color=ink*strength;color=memoryShards(color,fract(memoryUV*8.0),float(piece),gPixelSeed+float(slot*64+square),pulse . x+gLastResult . y,uBoardPixels,ink,0.0);}}if(valid&&cachedHistoryMatch(slot)>0.5)color=mix(color,dataAmber(),frame*0.90);if(slot==int(hist . x))color=mix(color,dataAmber(),frame*(0.65+0.35*pulse . x));if(slot>=151)color*=0.35;}color=labelLeft(color,uv,rect . xy+vec2(0.014,rect . w-0.027),45,wide?0.00220:0.00190,dataCyan());if(wide){color=labelLeft(color,uv,rect . xy+vec2(0.019,0.406),46,0.0019,dataInk());color=labelLeft(color,uv,rect . xy+vec2(0.019,0.067),47,0.00185,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.143,0.065),int(hist . x),3,0.0026,dataAmber());color=labelLeft(color,uv,rect . xy+vec2(0.180,0.067),48,0.00185,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.315,0.065),int(hist . y),3,0.0026,dataCyan());color=labelLeft(color,uv,rect . xy+vec2(0.019,0.024),87,0.00185,dataInk());}else{color=labelLeft(color,uv,rect . xy+vec2(0.014,0.027),47,0.00165,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.135,0.025),int(hist . x),3,0.0022,dataAmber());color=labelLeft(color,uv,rect . xy+vec2(0.160,0.027),48,0.00165,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.276,0.025),int(hist . y),3,0.0022,dataCyan());}return color;}vec3 registerMemory(vec3 color,vec2 uv,vec4 rect,vec4 pulse){vec4 rules=gameData(16),hist=gameData(19);color=labelLeft(color,uv,rect . xy+vec2(0.018,0.408),49,0.0028,dataCyan());color=labelLeft(color,uv,rect . xy+vec2(0.018,0.352),81,0.0020,dataInk());color=labelRight(color,uv,rect . xy+vec2(0.313,0.350),rules . x>0.0?57:58,0.0028,rules . x>0.0?dataCyan():dataAmber());color=labelLeft(color,uv,rect . xy+vec2(0.018,0.298),51,0.0019,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.153,0.296),uiData(11),6,0.0027,dataCyan());color=labelLeft(color,uv,rect . xy+vec2(0.189,0.298),52,0.0019,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.313,0.296),int(rules . w),3,0.0027,dataAmber());color=labelLeft(color,uv,rect . xy+vec2(0.018,0.251),53,0.0018,dataInk());color=numberRight(color,uv,rect . xy+vec2(0.153,0.249),int(hist . z),2,0.0027,dataCyan());color=labelLeft(color,uv,rect . xy+vec2(0.189,0.251),54,0.0019,dataInk());color=squareReadout(color,uv,rect . xy+vec2(0.272,0.247),int(rules . z),dataAmber());color=labelLeft(color,uv,rect . xy+vec2(0.018,0.200),55,0.0017,dataInk());for(int bit=0;bit<4;++bit){float x=rect . x+0.167+float(bit)*0.043;vec3 ink=bit<2?dataCyan():dataAmber();color=bitLamp(color,uv,vec2(x,rect . y+0.209),0.0046,numericBit(rules . y,float(bit))>0.5,ink,pulse . x);color=labelCenter(color,uv,vec2(x,rect . y+0.186),65+bit,0.0013,dataInk());}color=labelLeft(color,uv,rect . xy+vec2(0.018,0.151),56,0.0018,dataInk());color=bitLamp(color,uv,rect . xy+vec2(0.184,0.159),0.0045,numericBit(hist . w,0.0)>0.5,dataAmber(),pulse . x);color=bitLamp(color,uv,rect . xy+vec2(0.242,0.159),0.0045,numericBit(hist . w,1.0)>0.5,dataAmber(),pulse . x);color=bitLamp(color,uv,rect . xy+vec2(0.300,0.159),0.0045,gameData(21). x>0.5,dataCyan(),pulse . x);color=labelCenter(color,uv,rect . xy+vec2(0.184,0.135),76,0.00125,dataInk());color=labelCenter(color,uv,rect . xy+vec2(0.242,0.135),70,0.00125,dataInk());color=labelCenter(color,uv,rect . xy+vec2(0.300,0.135),88,0.00115,dataInk());color=labelLeft(color,uv,rect . xy+vec2(0.018,0.121),84,0.0016,dataInk());color=registerBits(color,uv,vec4(rect . xy+vec2(0.019,0.020),0.297,0.087),pulse . x);return color;}vec3 boardMemoryRail(vec3 color,vec2 uv,vec4 pulse,float physicalSize){vec2 p=uv-0.5;float radius=0.518;float edge=max(abs(p . x),abs(p . y));float distanceToRail=abs(edge-radius);if(distanceToRail>0.045)return color;float path;if(abs(p . x)>abs(p . y)){path=p . x>0.0?1.0+(radius-p . y)/(2.0*radius):3.0+(p . y+radius)/(2.0*radius);}else{path=p . y>0.0?(p . x+radius)/(2.0*radius):2.0+(radius-p . x)/(2.0*radius);}int square=int(floor(path*16.0));if(square<0)square=0;if(square>63)square=63;int piece=uiPiece(square);vec3 ink=piece>0?dataCyan():dataAmber();if(piece==0)ink=vec3(0.09,0.24,0.26);float energy=piece==0?0.12:0.55+abs(float(piece))*0.055;if(square==uiData(5)||square==uiData(6))energy+=pulse . x*1.3;if(uiData(7)!=0)ink=mix(ink,vec3(1.0,0.32,0.20),0.43);ink=mix(ink,vec3(1.0,0.27,0.18),pulse . z*0.8);float scan=pow(max(0.0,cos((path-pulse . w)*1.5707963)),32.0);float segment=fract(path*16.0);float runEnd=0.70+0.27*memoryPattern(gPixelSeed+float(square)*11.0+float(piece)*73.0);float segmentMask=smoothstep(0.03,0.13,segment)*(1.0-smoothstep(runEnd-0.08,runEnd,segment));float ribbon=max(0.010+uBoardPixels*0.004,1.0/physicalSize);color=memoryShards(color,vec2(segment,0.5+(edge-radius)/(2.0*ribbon)),float(piece),gPixelSeed+float(square)*23.0,pulse . x+pulse . y+gLastResult . y+float(uiData(7)!=0)*0.3,uBoardPixels,ink,0.0);float glow=exp(-distanceToRail*170.0)*segmentMask;color+=ink*glow*(0.10+0.06*uBoardPixels+pulse . x*0.10+pulse . y*0.25)*energy;float core=coverage(distanceToRail-max(0.0015*uBoardPixels,0.48/physicalSize),0.6/physicalSize)*segmentMask;color=mix(color,ink*(energy+scan*0.30),core);float hairline=coverage(abs(edge-0.532)-0.00055,0.65/physicalSize);vec3 edgeInk=mix(mix(dataCyan(),dataAmber(),pulse . y),lastResultInk(),gLastResult . y);color+=edgeInk*hairline*(0.30+pulse . x*0.45+gLastResult . y*0.65);return color;}vec3 drawStateBorder(vec3 color,vec2 uv,vec4 pulse){color=boardMemoryRail(color,uv,pulse,chessSize());vec4 a=dataPanelRect(0),b=dataPanelRect(1),c=dataPanelRect(2);color=instrumentPanel(color,uv,a,dataCyan(),pulse . x);color=instrumentPanel(color,uv,b,dataCyan(),pulse . x);color=instrumentPanel(color,uv,c,dataAmber(),pulse . y+pulse . x*0.4);color=pieceMemory(color,uv,a,pulse);color=legalMemory(color,uv,b,pulse);color=historyMemory(color,uv,c,pulse);if(chessWide()){vec4 d=dataPanelRect(3);color=instrumentPanel(color,uv,d,dataCyan(),pulse . x);color=registerMemory(color,uv,d,pulse);}return color;}vec3 boardSurface(vec3 color,vec2 uv,float physicalSize,bool interactive,bool coordinates,vec4 pulse){float pixelAA=0.70/physicalSize;int turn=uiData(0);int selectedSquare=interactive&&!uAutoPlay?uiData(1):-1;int status=uiData(4);int flip=uiData(9);int destination=interactive&&!uAutoPlay?uiData(10):uiData(6);bool inCheck=uiData(7)!=0;vec2 boardUV=(uv-INSET)/BOARD_SIZE;vec2 grid=boardUV*8.0;bool inside=boardUV . x>=0.0&&boardUV . y>=0.0&&boardUV . x<1.0&&boardUV . y<1.0;bool frame=uv . x>=0.0&&uv . x<1.0&&uv . y>=0.0&&uv . y<1.0;if(frame){color=vec3(0.006,0.014,0.024)+0.005*(1.0-uv . y);}if(inside){int displayFile=int(floor(grid . x));int displayRank=int(floor(grid . y));int file=flip==0?displayFile:7-displayFile;int rank=flip==0?displayRank:7-displayRank;int square=file+rank*8;int piece=uiPiece(square);int type=piece<0?-piece:piece;vec2 p=fract(grid)-0.5;float aa=pixelAA*8.0/BOARD_SIZE;bool lightSquare=mod(float(file+rank),2.0)>0.5;color=lightSquare?vec3(0.855,0.879,0.809):vec3(0.025,0.105,0.133);color+=0.015*(boardUV . y-boardUV . x);if(square==uiData(5)||square==uiData(6))color=mix(color,vec3(0.17,0.95,0.73),0.31);if(square==destination&&square!=selectedSquare&&status==0&&!uAutoPlay)color=mix(color,vec3(0.96,0.96,0.88),0.13);if(square==selectedSquare&&status==0)color=mix(color,vec3(0.88,0.80,0.44),0.49);if(inCheck&&type==6&&(piece>0?1:-1)==turn){float glow=exp(-4.1*dot(p,p));color=mix(color,vec3(0.79,0.23,0.20),0.40+0.29*glow);}if(square==selectedSquare&&status==0){float border=abs(sdBox(p,vec2(0.468)))-0.009;color=mix(color,vec3(0.95,0.90,0.60),0.85*coverage(border,aa));}bool legal=false;if(selectedSquare>=0&&selectedSquare<64&&status==0)legal=uiLegal(selectedSquare,square)>0.5;if(legal){float marker;if(piece==0)marker=coverage(sdCircle(p,0.069),aa);else{float ring=abs(length(p)-0.442)-0.027;marker=coverage(ring,aa)*smoothstep(0.230,0.260,min(abs(p . x),abs(p . y)));}color=mix(color,vec3(0.10,0.25,0.18),marker*0.49);}if(physicalSize>=92.0&&uiData(5)>=0&&uiData(6)>=0&&pulse . x>0.005){int fromRank=uiData(5)/8,toRank=uiData(6)/8;vec2 from=vec2(float(uiData(5)-fromRank*8),float(fromRank));vec2 to=vec2(float(uiData(6)-toRank*8),float(toRank));if(flip!=0){from=7.0-from;to=7.0-to;}from=INSET+(from+0.5)*BOARD_SIZE/8.0;to=INSET+(to+0.5)*BOARD_SIZE/8.0;float trace=sdCapsule(uv,from,to,0.0015);float glow=exp(-max(trace,0.0)*330.0);color=mix(color,mix(dataCyan(),dataAmber(),pulse . y),glow*pulse . x*(0.18+0.20*pulse . y));if(square==uiData(6)&&pulse . y>0.005){float radius=0.10+(1.0-pulse . y)*0.45;float ring=abs(length(p)-radius)-0.020;color=mix(color,dataAmber(),coverage(ring,aa)*pulse . y*0.65);}}if(piece!=0){if(physicalSize>=92.0)color=drawPiece(color,p,piece,aa);else{float mark=sdBox(p,vec2(0.19+float(type)*0.014,0.28));vec3 edgeInk=piece>0?vec3(0.008,0.020,0.028):dataAmber();color=mix(color,edgeInk,coverage(mark-0.05,aa*0.65));color=mix(color,piece>0?vec3(1.00,0.99,0.91):vec3(0.012,0.031,0.043),coverage(mark+0.065,aa*0.65));}}float edge=min(min(boardUV . x,boardUV . y),min(1.0-boardUV . x,1.0-boardUV . y));color*=1.0-0.12*(1.0-smoothstep(0.0,0.006,edge));}else if(frame&&coordinates){float rim=abs(sdBox(uv-0.5,vec2(BOARD_SIZE*0.5+0.003)))-0.0006;color=mix(color,vec3(0.23,0.90,0.92),0.28*coverage(rim,pixelAA));if(uv . x>=INSET&&uv . x<1.0-INSET){int file=int(floor(grid . x));int actual=flip==0?file:7-file;float x=INSET+(float(file)+0.5)*BOARD_SIZE/8.0;float lower=boardCoordinate(uv-vec2(x,0.0275),actual+1);float upper=boardCoordinate(uv-vec2(x,0.9725),actual+1);color=mix(color,vec3(0.82,0.92,0.95),lower*0.85+upper*0.53);}if(uv . y>=INSET&&uv . y<1.0-INSET){int rank=int(floor(grid . y));int actual=flip==0?rank:7-rank;float y=INSET+(float(rank)+0.5)*BOARD_SIZE/8.0;float left=boardCoordinate(uv-vec2(0.0275,y),actual+28);float right=boardCoordinate(uv-vec2(0.9725,y),actual+28);color=mix(color,vec3(0.82,0.92,0.95),left*0.85+right*0.53);}}return color;}vec4 drawLegacyChess(vec3 color,vec2 fragCoord){vec2 uv=chessPoint(fragCoord);float pixelAA=0.70/chessSize();vec4 pulse=gameData(25);vec3 cream=vec3(0.98,0.98,0.91);vec3 muted=vec3(0.72,0.84,0.87);vec3 gold=vec3(1.00,0.64,0.16);vec3 red=vec3(1.00,0.24,0.33);int turn=uiData(0);int selectedSquare=uAutoPlay?-1:uiData(1);int status=uiData(4);int flip=uiData(9);int destination=uAutoPlay?uiData(6):uiData(10);bool inCheck=uiData(7)!=0;color=drawStateBorder(color,uv,pulse);color=completedGameStats(color,uv,pulse);color=labelLeft(color,uv,vec2(0.055,1.044),80,0.00215,muted);int statusLabel=turn>0?1:2;int reason=-1;vec3 statusInk=cream;if(inCheck){statusLabel=turn>0?3:4;statusInk=red;}if(status==1||status==9)statusLabel=5;else if(status==2||status==10)statusLabel=6;else if(status!=0)statusLabel=7;if(status!=0)statusInk=statusLabel==5?dataCyan():(statusLabel==6?dataAmber():dataDraw());if(status==1||status==2)reason=8;else if(status==3)reason=9;else if(status==4)reason=10;else if(status==5)reason=11;else if(status==6)reason=12;else if(status==7)reason=32;else if(status==8)reason=31;else if(status==9||status==10)reason=30;else if(status==11)reason=29;color=labelRight(color,uv,vec2(0.945,1.070),statusLabel,0.0035,statusInk);if(reason>=0)color=labelRight(color,uv,vec2(0.945,1.044),reason,0.00215,muted);if(uAutoPlay){bool repeating=status!=0&&uAutoRepeat;float progress=status==0&&!uAutoFast?clamp(uiAutoElapsed(autoTimestamp())/autoMoveInterval(),0.0,1.0):1.0;if(status!=0&&!repeating)progress=0.0;vec3 autoInk=status==0?dataCyan():dataAmber();color=bitLamp(color,uv,vec2(0.351,1.081),0.0040,true,autoInk,status==0||repeating?1.0-progress:0.0);float smallPixel=max(0.00185,1.0/chessSize());if(status==0||repeating){if(!uAutoFast){color=labelLeft(color,uv,vec2(0.366,1.075),59,smallPixel,autoInk);color=decimalRight(color,uv,vec2(0.515,1.075),autoSpeedValue(),2,2,max(0.00235,1.1/chessSize()),autoInk);color=labelLeft(color,uv,vec2(0.530,1.075),94,max(0.0017,1.0/chessSize()),autoInk*0.83);}if(uAutoRepeat)color=labelLeft(color,uv,vec2(0.366,1.044),repeating?96:95,max(0.0016,1.0/chessSize()),autoInk*0.77);float trackLeft=uAutoRepeat?0.525:0.366;float trackHalf=(0.630-trackLeft)*0.5;float track=coverage(sdBox(uv-vec2(trackLeft+trackHalf,1.052),vec2(trackHalf,0.0010)),pixelAA);color=mix(color,autoInk*0.2,track);float fill=coverage(sdBox(uv-vec2(trackLeft+progress*trackHalf,1.052),vec2(max(0.00001,progress*trackHalf),0.0010)),pixelAA);color=mix(color,autoInk,fill);}else color=labelLeft(color,uv,vec2(0.366,1.075),60,smallPixel,autoInk);}float ruleLine=coverage(sdBox(uv-vec2(0.5,-0.020),vec2(0.445,0.00055)),pixelAA);color=mix(color,muted,ruleLine*0.25);color=labelLeft(color,uv,vec2(0.055,-0.064),23,0.0026,muted);color=squareReadout(color,uv,vec2(0.149,-0.066),uAutoPlay?uiData(5):selectedSquare,cream);color=labelLeft(color,uv,vec2(0.266,-0.064),24,0.0026,muted);color=squareReadout(color,uv,vec2(0.320,-0.066),destination,cream);color=labelLeft(color,uv,vec2(0.582,-0.064),25,0.0023,muted);int promotion=uiData(12);int promotionLabel=19;if(promotion==4)promotionLabel=20;else if(promotion==3)promotionLabel=21;else if(promotion==2)promotionLabel=22;if(uAutoPlay)color=labelRight(color,uv,vec2(0.945,-0.066),89,0.0031,cream);else color=labelRight(color,uv,vec2(0.945,-0.066),promotionLabel,0.0031,cream);int footer=26;vec3 footerInk=muted;if(uAutoPlay){footer=61;footerInk=dataCyan()*0.80;}if(uiData(8)!=0){footer=33;footerInk=gold;}if(uiData(14)==2){footer=34;footerInk=red;}if(uiData(14)==6){footer=36;footerInk=red;}if(uiData(15)!=0){footer=35;footerInk=gold;}if(status!=0){footer=uAutoPlay&&uAutoRepeat?97:27;footerInk=uAutoPlay&&uAutoRepeat?dataAmber()*0.85:muted;}color=labelCenter(color,uv,vec2(0.5,-0.117),footer,0.00255,footerInk);if(uiData(13)==0){color*=0.20;float panel=coverage(sdRoundBox(uv-vec2(0.5,0.5),vec2(0.46,0.115),0.012),pixelAA);color=mix(color,vec3(0.10,0.14,0.115),panel);color=labelCenter(color,uv,vec2(0.5,0.545),37,0.0040,red);color=labelCenter(color,uv,vec2(0.5,0.477),38,0.0027,cream);color=labelCenter(color,uv,vec2(0.5,0.426),39,0.00265,muted);}return vec4(color,1.0);}vec3 screenText(vec3 color,vec2 p,vec2 at,int label,float size,vec3 ink){float scale=chessSize();return labelLeft(color,p/scale,at/scale,label,size/scale,ink);}vec3 screenRight(vec3 color,vec2 p,vec2 at,int label,float size,vec3 ink){float scale=chessSize();return labelRight(color,p/scale,at/scale,label,size/scale,ink);}vec3 screenNumber(vec3 color,vec2 p,vec2 at,int value,int digits,float size,vec3 ink){float scale=chessSize();return numberRight(color,p/scale,at/scale,value,digits,size/scale,ink);}float screenGlyph(vec2 p,vec2 at,int glyph,float size){return glyphCoverage((p-at)/chessSize(),glyph,size/chessSize());}vec3 screenPanel(vec3 color,vec2 p,vec4 rect,vec3 ink,float energy){float d=sdRoundBox(p-rect . xy-rect . zw*0.5,rect . zw*0.5,5.0);color+=ink*(0.025+energy*0.04)*exp(-max(d,0.0)*0.16);color=mix(color,vec3(0.004,0.010,0.020),coverage(d,0.7));color=mix(color,ink*(0.45+energy*0.48),coverage(abs(d)-0.55,0.7));return color;}vec3 resultInk(int result){if(result==1||result==9)return dataCyan();if(result==2||result==10)return dataAmber();return dataDraw();}int boardStatusLabel(){int result=uiData(4);if(result==1||result==9)return 5;if(result==2||result==10)return 6;if(result!=0)return 7;if(uiData(7)!=0)return uiData(0)>0?3:4;return uiData(0)>0?1:2;}vec3 openingLabel(vec3 color,vec2 p,vec2 center,int opening,bool white,float size,vec3 ink){bool knight=opening>=16;int file=opening<8?opening:opening-8;if(knight){file=0;if(opening==17)file=2;if(opening==18)file=5;if(opening==19)file=7;}int rank=white?3:6;if(opening>=8&&opening<16)rank=white?4:5;float count=knight?3.0:2.0;vec2 at=center-vec2((count*6.0-1.0)*size*0.5,0.0);float x=(p . x-at . x)/(6.0*size);if(x<0.0||x>=count)return color;int character=int(floor(x));int glyph=rank+27;if(character==0)glyph=knight?14:file+1;if(knight&&character==1)glyph=file+1;return mix(color,ink,screenGlyph(p,at+vec2(float(character)*6.0*size,0.0),glyph,size));}vec3 gridResults(vec3 color,vec2 p,vec4 rect,bool global){if(!inDataRect(p,rect))return color;ivec4 totals=ivec4(uiGameStats());if(global)totals=masterExactCounts();float width=rect . z*0.25;int column=int(floor((p . x-rect . x)/width));vec2 origin=rect . xy+vec2(float(column)*width,0.0);int count=totals . w;vec3 ink=vec3(0.87,0.89,0.80);if(column==1){count=totals . x;ink=dataCyan();}if(column==2){count=totals . y;ink=dataAmber();}if(column==3){count=totals . z;ink=resultInk(3);}float font=global?1.0:0.86;float captionY=rect . w-(global?10.0:9.0);if(column==0)color=screenText(color,p,origin+vec2(4.0-60.0*font,captionY),90,font,ink*0.83);else{float captionSize=global?1.00:0.86;int glyph=column==1?23:(column==2?2:4);color=mix(color,ink,screenGlyph(p,origin+vec2(width*0.5-2.5*captionSize,captionY),glyph,captionSize));}float numberSize=min(global?1.30:1.10,(width-9.0)/(global?53.0:41.0));float numberY=global?min(20.0,rect . w-25.0):min(14.0,rect . w-18.0);color=screenNumber(color,p,origin+vec2(width-5.0,numberY),count,global?9:7,numberSize,ink);vec2 rateAt=origin+vec2(width-5.0,global?5.0:(rect . w<30.0?1.0:3.0));float rateSize=global?0.90:0.83;if(column==0){if(global)color=screenRight(color,p,rateAt,105,min(0.80,(width-8.0)/59.0),dataInk());}else if(totals . w>0){color=decimalRight(color,p/chessSize(),(rateAt-vec2(6.0*rateSize,0.0))/chessSize(),float(count)*100.0/float(totals . w),1,3,rateSize/chessSize(),ink*0.82);color=mix(color,ink*0.82,screenGlyph(p,rateAt-vec2(5.0*rateSize,0.0),45,rateSize));}else color=mix(color,dataInk(),screenGlyph(p,rateAt-vec2(5.0*rateSize,0.0),38,rateSize));if(global&&p . y<rect . y+3.0){float x=(p . x-rect . x)/rect . z;color=vec3(0.08,0.16,0.18);if(totals . w>0){color=resultInk(3);if(x<float(totals . x+totals . y)/float(totals . w))color=dataAmber();if(x<float(totals . x)/float(totals . w))color=dataCyan();}}return color;}vec3 gridLocalPixels(vec3 color,vec2 p,vec4 rect,vec4 pulse){if(!inDataRect(p,rect))return color;float width=rect . z/3.0;int section=int(floor((p . x-rect . x)/width));vec2 origin=rect . xy+vec2(float(section)*width,0.0);int title=section==0?40:(section==1?42:49);if(section==1&&uiData(4)!=0)title=44;float titleSize=min(0.88,(width-7.0)/(section==1&&uiData(4)!=0?119.0:77.0));color=screenText(color,p,origin+vec2(4.0,rect . w-10.0),title,titleSize,section==1&&uiData(4)!=0?dataAmber():dataCyan());vec4 bank=vec4(origin+vec2(4.0,2.0),width-8.0,rect . w-18.0);if(!inDataRect(p,bank))return color;vec2 unit=(p-bank . xy)/bank . zw;float emphasis=clamp(uBoardPixels,0.3,3.0);if(section==0){vec2 q=unit*8.0;int square=int(floor(q . x))+int(floor(q . y))*8;int piece=uiPiece(square);int type=piece<0?-piece:piece;vec3 ink=piece>0?dataCyan():dataAmber();if(piece==0)ink=vec3(0.10,0.24,0.26);vec2 local=fract(q)-0.5;float d=sdBox(local,vec2(clamp(0.31+0.038*emphasis,0.33,0.46)));float aa=0.5*8.0/min(bank . z,bank . w);color=mix(color,ink*(piece==0?0.12:0.38+float(type)*0.085),coverage(d,aa));color=memoryShards(color,fract(q),float(piece),gPixelSeed+float(square)*13.0,pulse . x+pulse . y+gLastResult . y,emphasis,ink,0.0);if(square==uiData(5)||square==uiData(6))color+=ink*pulse . x*0.22;float font=min(bank . z,bank . w)/8.0*0.074;vec2 center=bank . xy+(floor(q)+0.5)*bank . zw/8.0;color=mix(color,ink,screenGlyph(p,center-vec2(2.5,3.5)*font,27+type,font));}else if(section==1){vec2 q=unit*64.0;int to=int(floor(q . x)),from=int(floor(q . y));float light=0.0;for(int y=-1;y<=1;++y){for(int x=-1;x<=1;++x){vec2 offset=fract(q)-0.5-vec2(float(x),float(y));light+=storedLegal(from+y,to+x)*exp(-dot(offset,offset)*(3.4-emphasis*0.35));}}color=vec3(0.020,0.060,0.071);vec2 line=abs(fract(q/8.0)-0.5);color+=dataCyan()*0.05*max(step(0.46,line . x),step(0.46,line . y));vec3 ink=uiData(0)>0?dataCyan():dataAmber();color=memoryShards(color,fract(q),storedLegal(from,to),gPixelSeed+float(from*64+to),pulse . x+pulse . y+gLastResult . y,emphasis,ink,0.0);color+=ink*light*(0.92+pulse . x*0.35);if(uiData(4)!=0)color*=0.40;}else{vec2 q=unit*vec2(4.0,9.0);int channel=int(floor(q . x)),row=8-int(floor(q . y));float value=float(packedPiece(gameData(16+row),channel));vec2 local=fract(q);int bit=int(floor(local . x*4.0))+int(floor(local . y*2.0))*4;float active=numericBit(value,float(bit));vec2 bitLocal=fract(local*vec2(4.0,2.0))-0.5;float d=sdBox(bitLocal,vec2(0.27+emphasis*0.055));float aa=0.45/min(bank . z/16.0,bank . w/18.0);color=memoryShards(color,local,value,gPixelSeed+float(row*4+channel),pulse . x+pulse . y+gLastResult . y,emphasis,channelInk(channel),0.0);color=mix(color,channelInk(channel)*(0.04+active*0.95),coverage(d,aa));}return color;}vec3 gridMasterPixels(vec3 color,vec2 p,vec4 rect){if(!inDataRect(p,rect))return color;vec2 q=(p-rect . xy)/rect . zw*vec2(4.0,8.0);int channel=int(floor(q . x)),row=7-int(floor(q . y));int value=packedPiece(masterData(row),channel);vec2 local=fract(q);float emphasis=clamp(uMasterPixels,0.3,3.0);vec3 ink=channelInk(channel);float edge=coverage(sdBox(local-0.5,vec2(0.46)),0.6/min(rect . z/4.0,rect . w/8.0));color=mix(color,ink*(0.030+min(float(value)/1023.0,1.0)*0.21),edge);vec4 pulse=masterData(8);float burst=pulse . x+pulse . y+step(0.5,masterData(9). x);color=memoryShards(color,local,float(value),float(row*31+channel*7)+float(value)*0.5,burst,emphasis,ink,1.0);float cellHeight=rect . w/8.0;vec2 bitUV=vec2(local . x,local . y/(cellHeight>=18.0?0.42:1.0));if(bitUV . y<1.0){int bit=int(floor(bitUV . x*5.0))+int(floor(bitUV . y*2.0))*5;float active=mod(floor(float(value)/exp2(float(bit))),2.0);vec2 bitLocal=fract(bitUV*vec2(5.0,2.0))-0.5;float d=sdBox(bitLocal,vec2(0.22+emphasis*0.065));float aa=0.50/min(rect . z/20.0,cellHeight/3.5);color=mix(color,ink*(0.028+active*(0.90+0.07*emphasis)),coverage(d,aa));color+=ink*active*exp(-dot(bitLocal,bitLocal)*7.0)*emphasis*0.045;}if(cellHeight>=18.0){vec2 cell=rect . xy+floor(q)*rect . zw/vec2(4.0,8.0);color=screenNumber(color,p,cell+vec2(rect . z/4.0-7.0,cellHeight*0.56),value,4,min(1.15,cellHeight*0.049),ink*0.84);}return color;}vec3 gridMasterPanel(vec3 color,vec2 p){vec4 rect=gridMasterRect();if(!inDataRect(p,rect))return color;vec4 pulse=masterData(8),state=masterData(3);float statsHeight=38.0;color=gridResults(color,p,vec4(rect . xy+vec2(0.0,rect . w-statsHeight),rect . z,statsHeight),true);float x=rect . x;float y=rect . y+rect . w-49.0;color=screenText(color,p,vec2(x,y),106,0.72,dataInk());color=screenNumber(color,p,vec2(rect . x+rect . z*0.33,y),int(state . x),3,0.90,dataCyan());color=screenText(color,p,vec2(rect . x+rect . z*0.43,y),107,0.72,dataInk());color=screenNumber(color,p,vec2(rect . x+rect . z*0.78,y),int(state . z),3,0.90,dataAmber());color=screenNumber(color,p,vec2(rect . x+rect . z-2.0,y),requestedBoardCount(),3,0.90,dataInk());float pliesY=y-11.0;color=screenText(color,p,vec2(x,pliesY),108,0.68,dataInk());color=screenNumber(color,p,vec2(rect . x+rect . z-2.0,pliesY),masterPly(),9,0.92,dataCyan());color=screenText(color,p,vec2(x+rect . z*0.36,pliesY),115,0.65,dataAmber()*0.80);vec2 lamp=vec2(x+rect . z*0.70,pliesY+3.0);int channel=int(floor((p . x-lamp . x+5.0)/12.0));if(channel>=0&&channel<3&&abs(p . y-lamp . y)<8.0){float value=channel==0?pulse . x:(channel==1?pulse . y:pulse . z);vec3 ink=channel==0?dataCyan():(channel==1?dataAmber():vec3(1.0,0.25,0.13));float d=length(p-lamp-vec2(float(channel)*12.0,0.0));color+=ink*value*exp(-d*0.25)*0.45;color=mix(color,ink*(0.12+value*0.88),coverage(d-1.6,0.5));}vec4 bank=vec4(rect . xy+vec2(14.0,1.0),rect . z-16.0,rect . w-65.0);color=gridMasterPixels(color,p,bank);return color;}vec3 gridTileOverlay(vec3 color,vec2 p,vec2 uv,float size,vec4 tile,vec4 pulse){color=boardMemoryRail(color,uv,pulse,size);int result=uiData(4);bool selected=gBoard==focusBoard();vec3 ink=result==0?dataCyan():resultInk(result);if(uiData(7)!=0)ink=vec3(1.0,0.30,0.20);float d=abs(sdBox(p-tile . xy-tile . zw*0.5,tile . zw*0.5-1.4))-0.30;float strength=result!=0?0.75:0.11+pulse . x*0.38;color=mix(color,ink,coverage(d,0.6)*strength);color+=lastResultInk()*exp(-abs(d)*0.8)*gLastResult . y*0.55;vec4 stats=uiGameStats();vec4 bar=vec4(tile . xy+vec2(tile . z*0.075,max(1.5,tile . w*0.022)),tile . z*0.85,max(1.0,tile . w*0.016));if(inDataRect(p,bar)){float x=(p . x-bar . x)/bar . z;color=vec3(0.09,0.17,0.19);if(stats . w>0.0){color=resultInk(3);if(x<(stats . x+stats . y)/stats . w)color=dataAmber();if(x<stats . x/stats . w)color=dataCyan();}}if(tile . z>=95.0){float width=tile . z*0.283;int part=int(floor((p . x-tile . x-tile . z*0.075)/width));if(part>=0&&part<3){float value=part==0?stats . x:(part==1?stats . y:stats . z);vec3 statInk=part==0?dataCyan():(part==1?dataAmber():resultInk(3));vec2 at=tile . xy+vec2(tile . z*0.075+float(part)*width,tile . w*0.068);int glyph=part==0?23:(part==1?2:4);color=mix(color,statInk,screenGlyph(p,at,glyph,0.82));color=screenNumber(color,p,at+vec2(width-4.0,0.0),int(value),7,min(0.90,(width-14.0)/41.0),statInk);}}if(selected){vec2 center=tile . xy+tile . zw*0.5;vec2 halfSize=tile . zw*0.5-2.0;float edge=abs(sdBox(p-center,halfSize));color=mix(color,vec3(0.003,0.008,0.012),coverage(edge-1.5,0.35));color=mix(color,vec3(0.72,1.0,0.06),coverage(edge-0.75,0.35));vec2 corner=halfSize-abs(p-center);float arm=clamp(tile . z*0.20,4.0,10.0);float brackets=1.0-smoothstep(arm-1.0,arm,max(corner . x,corner . y));color=mix(color,vec3(1.0,1.0,0.93),brackets*coverage(edge-1.10,0.35));}return color;}vec3 gridAxes(vec3 color,vec2 p,vec4 matrix){float side=float(gridSide()),cell=matrix . z/side;int focus=focusBoard(),focusRow=focus/gridSide(),focusColumn=focus-focusRow*gridSide();float font=min(1.15,cell/22.0);bool top=p . x>=matrix . x&&p . x<matrix . x+matrix . z&&p . y>=matrix . y+matrix . w&&p . y<matrix . y+matrix . w+17.0;bool left=p . x>=matrix . x-27.0&&p . x<matrix . x&&p . y>=matrix . y&&p . y<matrix . y+matrix . w;if(top||left){int index=top?int(floor((p . x-matrix . x)/cell)):gridSide()-1-int(floor((p . y-matrix . y)/cell));vec2 center=top?vec2(matrix . x+(float(index)+0.5)*cell,matrix . y+matrix . w+5.0):vec2(matrix . x-15.0,matrix . y+matrix . w-(float(index)+0.5)*cell-3.5*font);bool selected=top?index==focusColumn:index==focusRow;vec3 ink=top?dataCyan():dataAmber();if(!selected)ink*=0.67;if(uOpeningMatrix)color=openingLabel(color,p,center,index,top,font,ink);else color=screenNumber(color,p,center+vec2((index<9?2.5:5.5)*font,0.0),index+1,2,font,ink);}if(uOpeningMatrix)color=screenText(color,p,vec2(matrix . x-24.0,matrix . y+matrix . w+21.0),113,0.85,dataAmber()*0.85);color=screenText(color,p,vec2(matrix . x+matrix . z*0.45,matrix . y+matrix . w+21.0),uOpeningMatrix?112:105,0.85,dataCyan()*0.85);return color;}vec3 gridAutoReadout(vec3 color,vec2 p,vec2 at,float width){if(!uAutoPlay||uAutoFast)return color;vec3 ink=dataCyan();float size=min(1.1,width/250.0);color=screenText(color,p,at,59,size,ink);color=decimalRight(color,p/chessSize(),(at+vec2(71.0*size,0.0))/chessSize(),autoSpeedValue(),2,2,size/chessSize(),ink);color=screenText(color,p,at+vec2(79.0*size,0.0),94,size,ink*0.80);return color;}vec3 gridFocusPanel(vec3 color,vec2 p,vec4 pulse){vec4 rect=gridFocusRect();if(!inDataRect(p,rect))return color;float headerY=rect . w-10.0;float statusY=rect . w-22.0;color=screenText(color,p,rect . xy+vec2(0.0,headerY),102,1.00,dataCyan());int index=focusBoard(),row=index/gridSide(),column=index-row*gridSide();vec2 numberAt=rect . xy+vec2(rect . z-31.0,headerY);color=screenNumber(color,p,numberAt,row+1,2,1.00,dataAmber());color=mix(color,dataInk(),screenGlyph(p,numberAt+vec2(5.0,0.0),37,1.00));color=screenNumber(color,p,numberAt+vec2(25.0,0.0),column+1,2,1.00,dataCyan());int status=boardStatusLabel();vec3 ink=uiData(4)==0?dataInk():resultInk(uiData(4));if(uiData(7)!=0)ink=vec3(1.0,0.35,0.23);if(uiData(14)==2){status=34;ink=vec3(1.0,0.35,0.23);}color=screenText(color,p,rect . xy+vec2(0.0,statusY),status,min(0.90,rect . z/(uiData(14)==2?233.0:83.0)),ink);if(gLastResult . y>0.025&&uiData(14)!=2){vec2 at=rect . xy+vec2(rect . z*0.43,headerY);vec3 lastInk=lastResultInk()*(0.55+gLastResult . y*0.45);color=screenText(color,p,at,103,0.65,lastInk);int last=int(gLastResult . x);int glyph=last==1||last==9?23:(last==2||last==10?2:4);color=mix(color,lastInk,screenGlyph(p,at+vec2(61.0,0.0),glyph,0.90));}if(uiData(14)!=2)color=gridAutoReadout(color,p,rect . xy+vec2(rect . z*0.51,statusY),rect . z*0.49);vec4 stats=vec4(rect . xy+vec2(0.0,rect . w-52.0),rect . z,27.0);color=gridResults(color,p,stats,false);vec4 local=vec4(rect . xy+vec2(0.0,1.0),rect . z,rect . w-55.0);color=gridLocalPixels(color,p,local,pulse);return color;}vec3 gridInfoPanel(vec3 color,vec2 p,vec4 pulse){vec4 info=gridInfoRect();vec4 globalPulse=masterData(8);color=screenPanel(color,p,info,vec3(0.36,0.62,0.70),globalPulse . x*0.28+globalPulse . y*0.35+step(0.5,masterData(9). x)*0.40);if(!inDataRect(p,info))return color;vec4 local=gridFocusRect();float separator=abs(p . x-local . x-local . z-6.0);color=mix(color,dataInk()*0.22,coverage(separator-0.35,0.55));color=gridFocusPanel(color,p,pulse);color=gridMasterPanel(color,p);return color;}vec4 gridCapacityWarning(vec3 color,vec2 p){float scale=min(RENDERSIZE . x,RENDERSIZE . y);vec4 rect=vec4(RENDERSIZE*0.5-vec2(min(260.0,RENDERSIZE . x*0.46),120.0),min(520.0,RENDERSIZE . x*0.92),240.0);color=screenPanel(color,p,rect,dataAmber(),0.8);float font=clamp(scale/650.0,0.6,1.3);vec2 at=rect . xy+vec2(18.0,204.0);color=screenText(color,p,at,109,font*2.0,dataAmber());color=screenText(color,p,at-vec2(0.0,44.0),105,font,dataInk());color=screenNumber(color,p,vec2(rect . x+rect . z-18.0,at . y-44.0),requestedBoardCount(),3,font*1.4,dataCyan());color=screenText(color,p,at-vec2(0.0,82.0),110,font,dataInk());color=screenNumber(color,p,vec2(rect . x+rect . z-18.0,at . y-82.0),STATE_TEXELS*requestedBoardCount(),7,font*1.4,dataAmber());color=screenText(color,p,at-vec2(0.0,120.0),111,font,dataInk());color=screenNumber(color,p,vec2(rect . x+rect . z-18.0,at . y-120.0),int(RENDERSIZE . x*RENDERSIZE . y),9,font*1.4,dataCyan());color=screenText(color,p,at-vec2(0.0,164.0),101,font,dataInk()*0.8);return vec4(color,1.0);}vec4 drawChess(vec2 fragCoord){gRenderSize=chessLayoutSize();gBoard=focusBoard();vec2 screenUV=fragCoord/RENDERSIZE;vec3 color=(vec3(0.002,0.005,0.011)+0.004*(1.0-screenUV . y))*(1.0-0.08*length(screenUV-0.5));if(!gridStorageReady())return gridCapacityWarning(color,fragCoord);bool dashboard=gridDashboard();vec4 matrix=gridMatrixRect();bool tilePixel=dashboard&&inDataRect(fragCoord,matrix);vec2 uv=dashboard?vec2(0.0):chessPoint(fragCoord);float physicalSize=chessSize();vec4 tile=vec4(0.0);if(tilePixel){float cell=matrix . z/float(gridSide());vec2 coordinate=floor((fragCoord-matrix . xy)/cell);int column=int(coordinate . x),row=gridSide()-1-int(coordinate . y);gBoard=row*gridSide()+column;tile=vec4(matrix . xy+coordinate*cell,cell,cell);physicalSize=cell*0.85;uv=(fragCoord-tile . xy-vec2(cell*0.075,cell*0.115))/physicalSize;}vec4 pulse=gameData(25);vec4 seedWords=gameData(27);gPixelSeed=seedWords . x+256.0*seedWords . y+float(gBoard)*19.0;gLastResult=gameData(36);if(!dashboard||tilePixel)color=boardSurface(color,uv,physicalSize,!dashboard||gBoard==focusBoard(),!dashboard,pulse);if(!dashboard)return drawLegacyChess(color,fragCoord);if(tilePixel)return vec4(gridTileOverlay(color,fragCoord,uv,physicalSize,tile,pulse),1.0);color=gridAxes(color,fragCoord,matrix);color=gridInfoPanel(color,fragCoord,pulse);return vec4(color,1.0);}void main(){highp vec2 fragPosition=gl_FragCoord . xy;ivec2 pixel=ivec2(floor(fragPosition));int linear=pixel . y*int(RENDERSIZE . x)+pixel . x;if(PASSINDEX<32){int stage=PASSINDEX-(PASSINDEX/4)*4;int stride=stage==0?91:(stage==1?LEGAL_TEXELS:(stage==2?FACT_TEXELS:STATE_TEXELS));gBoard=linear/stride;if(gBoard>=activeBoardCount())discard;int index=linear-gBoard*stride;if(stage==0){gl_FragColor=advanceGame(index);}else if(stage==1){int from=index/16;gl_FragColor=calculateLegal(ivec2(index-from*16,from));}else if(stage==2)gl_FragColor=calculateFacts(index);else gl_FragColor=finishGame(index);}else if(PASSINDEX<34){if(linear>=656)discard;gl_FragColor=PASSINDEX==32?masterRows(linear):masterFinish(linear);}else if(PASSINDEX==34){if(pixel . x>=64||pixel . y>=64)discard;gl_FragColor=buildTextAtlas(pixel);}else{gBoard=focusBoard();gl_FragColor=drawChess(fragPosition);}}
122.2 / 128 KiB
Concurrent chess entirely in GLSL, with high-contrast boards and state-driven glitch memory art. Grid side selects 1x1 to 20x20. Opening matrix forces 400 boards: White opening across columns, Black reply down rows, then random legal play. Focus row/column selects manual controls and inspection. Each board retains its own history, random stream and W/B/D counts; master pixels aggregate the grid. Auto-play starts enabled in Fastest mode at 8 moves per board per frame; timed speed defaults to 60 moves/second. Auto-repeat immediately starts the next game from the assigned opening and preserves counts. Restart all preserves counts; Reset statistics clears them. Changing grid or opening mode resets the cohort. Resize/recompile/seek clears buffers. 400 boards need 569200 pixels and 64x64 minimum dimensions; use 960x640 or larger.
export clip · render a video in your browser
Renders to video in your browser (no upload), stepping the real renderer frame by frame so multipass + feedback come out right. motion auto-animates the shader's own knobs — each export rolls a fresh take (🎲 re-roll, 🔒 to pin one you like). GIF is slower with a tighter length cap; MP4/WebM are faster. Some devices record in real time (noted below if so) — keep the tab visible.
embed · drop this shader into any page
Renders client-side in the reader's browser (CC0 — no attribution required, but the backlink is appreciated).