File size: 4,174 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
let enhancedFailed=0;
const fs=require('fs');const path=require('path');const{pathToFileURL}=require('url');const{chromium}=require('playwright');
function a(x,m){if(!x)throw new Error(m)}function eq(x,y,m){a(require("node:util").isDeepStrictEqual(x,y),`${m}: got ${JSON.stringify(x)} want ${JSON.stringify(y)}`)}async function tc(id,f){try{await f();console.log(id+' PASS')}catch(e){console.error(id+' FAIL: '+e.message);enhancedFailed++}}
(async()=>{const b=await chromium.launch({headless:true,args:['--no-sandbox','--disable-dev-shm-usage']});const p=await b.newPage();await p.goto(pathToFileURL(path.join(process.cwd(),'index.html')).href);
// ENHANCED_CASE_1: standard opening has the exact four pieces, black turn, counts and legal move set.
await tc('ENHANCED_CASE_1',async()=>{const s=await p.evaluate(()=>{__game.init();return{state:__game.getState(),moves:__game.legalMoves()}});eq([s.state.board[3][3],s.state.board[3][4],s.state.board[4][3],s.state.board[4][4]],['W','B','B','W'],'opening center');eq([s.state.turn,s.state.counts.B,s.state.counts.W],['B',2,2],'opening state');eq(s.moves.sort(),[[2,3],[3,2],[4,5],[5,4]].sort(),'opening legal moves')});
// ENHANCED_CASE_2: one legal play flips enclosed opponent pieces in all eight directions.
await tc('ENHANCED_CASE_2',async()=>{const s=await p.evaluate(()=>{const z=Array.from({length:8},()=>Array(8).fill(null));for(const[dr,dc]of[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]){z[3+dr][3+dc]='W';z[3+2*dr][3+2*dc]='B'}__game.setState(z,'B');return __game.play(3,3)});a(s.board.flat().filter(x=>x==='B').length===17,'not all eight directions flipped');a(s.board.flat().filter(x=>x==='W').length===0,'opponent pieces remained')});
// ENHANCED_CASE_3: no-move opponent is automatically passed, then the final move ends the game with the counted winner.
await tc('ENHANCED_CASE_3',async()=>{const r=await p.evaluate(()=>{const z=Array.from({length:8},()=>Array(8).fill('B'));z[0]=['B','W',null,'B','W',null,'B','B'];__game.setState(z,'B');const passed=__game.play(0,2);const over=__game.play(0,5);return{passed,over}});eq([r.passed.status,r.passed.turn],['playing','B'],'automatic pass');eq(r.over.status,'over','terminal status');eq(r.over.winner,'B','winner');eq(r.over.counts,{B:64,W:0},'terminal counts')});

await tc('COPY_AND_REAL_PLAY',async()=>{
 await p.evaluate(()=>__game.init());
 const board=p.locator('[data-testid=board]'), before=await board.screenshot(),bounds=await board.boundingBox();
 await p.mouse.click(bounds.x+bounds.width*3.5/8,bounds.y+bounds.height*2.5/8);
 const current=await p.evaluate(()=>__game.getState());
 eq(current.board[2][3],'B','real mouse move');eq(current.counts,{B:4,W:1},'real flip counts');eq(current.turn,'W','real turn');
 a(!before.equals(await board.screenshot()),'real move must visibly change discs');
 for(const [id,value]of [['count-b','4'],['count-w','1'],['turn','W']])eq((await p.locator('[data-testid='+id+']').innerText()).trim(),value,'visible HUD '+id);
 const copy=await p.evaluate(()=>{const input=__game.getState().board;const state=__game.setState(input,'W');input[2][3]='W';state.board[2][3]=null;return __game.getState()});
 eq(copy.board,current.board,'input and output arrays may not alias engine');
 fs.mkdirSync('/logs/verifier/visual-audit',{recursive:true});await p.screenshot({path:'/logs/verifier/visual-audit/played-and-flipped.png'});
 const terminal=await p.evaluate(()=>{const board=Array.from({length:8},()=>Array(8).fill('W'));board[0][0]=null;return __game.setState(board,'B')});
 eq(terminal.status,'over','non-full terminal');eq(terminal.winner,'W','white terminal victory');
 eq((await p.locator('[data-testid=status]').innerText()).trim(),'over','visible terminal status');
 a((await p.locator('[data-testid=winner]').innerText()).includes('W'),'visible winner');
 await p.screenshot({path:'/logs/verifier/visual-audit/white-victory.png'});
 await p.locator('[data-testid=new-game]').click();eq((await p.evaluate(()=>__game.getState())).counts,{B:2,W:2},'new game resets counts');
});
await b.close();console.log('ENHANCED_SCORE='+((4-enhancedFailed)/4));})().catch(e=>{console.error(e.stack||e);process.exit(1)});