$mode,'preferred_color'=>$preferred,'alternative_color'=>$alternative]; } // No conflict: both default on opposite rules sides. $r=resolvePieceSkins(prefs('default','White','Black'),prefs('default','White','Black')); check($r===['white'=>'White','black'=>'Black'],'Both default keep rules colours'); // No conflict: custom preferreds differ. $r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Green','Yellow')); check($r===['white'=>'Red','black'=>'Green'],'Different custom preferreds'); // Default vs custom conflict: default keeps rules colour; custom uses alternative. $r=resolvePieceSkins(prefs('default','White','Black'),prefs('custom','White','Red')); check($r===['white'=>'White','black'=>'Red'],'Black custom yields to alternative when conflicting with default White'); $r=resolvePieceSkins(prefs('custom','Black','Blue'),prefs('default','White','Black')); check($r===['white'=>'Blue','black'=>'Black'],'White custom yields to alternative when conflicting with default Black'); // Default vs custom with broken alternative equal to default colour: cycle further. $r=resolvePieceSkins(prefs('default','White','Black'),prefs('custom','White','White')); // validatePieceColors would reject equal prefs; resolution still cycles if alternative equals. // Here alternative equals preferred (invalid), but also equals whiteWant; nextDistinct from White skip White -> Black check($r['white']==='White' && $r['black']!=='White','Cycled alternative when equal to default colour'); // Both custom same preferred: coin flip 1 => white keeps, black takes alternative $r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Red','Green'),fn()=>1); check($r===['white'=>'Red','black'=>'Green'],'Both custom conflict: white keeps when coin=1'); $r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Red','Green'),fn()=>0); check($r===['white'=>'Blue','black'=>'Red'],'Both custom conflict: black keeps when coin=0'); // Custom preferred matches other side's rules/default without being same mode conflict path already covered. $r=resolvePieceSkins(prefs('custom','Black','Red'),prefs('custom','White','Blue')); check($r===['white'=>'Black','black'=>'White'],'Cross-coloured customs with no clash'); // effectivePreferred check(effectivePreferredColor(prefs('default','Red','Blue'),'White')==='White','Default mode uses rules colour'); check(effectivePreferredColor(prefs('custom','Red','Blue'),'White')==='Red','Custom mode uses preferred'); // nextDistinct check(nextDistinctPieceColor('White','Black')==='Red','Cycle White skip Black -> Red'); check(nextDistinctPieceColor('Yellow','White')==='Black','Cycle Yellow wrap skip White -> Black'); check(nextDistinctPieceColor('Red','Blue')==='Green','Cycle Red skip Blue -> Green'); // Validation try {validatePieceColors('nope','White','Black');check(false,'bad mode');} catch(DomainException){check(true,'bad mode rejected');} try {validatePieceColors('custom','Purple','Black');check(false,'bad colour');} catch(DomainException){check(true,'bad colour rejected');} try {validatePieceColors('custom','Red','Red');check(false,'same colours');} catch(DomainException){check(true,'same colours rejected');} validatePieceColors('custom','Red','Blue'); check(true,'valid custom accepted'); echo "Colors: $checks assertions passed.\n";