UXInteract / task_050 /instruction.md
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
|
Raw History Blame Contribute Delete
2.24 kB

Build a playable Reversi board

Create a single offline index.html for Reversi (Othello). Render a uniform 8×8 board with clickable cells and a display of the turn, piece counts and outcome. DOM, canvas or SVG rendering is fine.

Interface

Expose window.__game with init(), setState(board, turn), getState(), legalMoves() and play(r,c). Use zero-based coordinates.

  • A board is an 8×8 array of 'B', 'W' and null. Start with white at [3,3] and [4,4], black at [3,4] and [4,3]; Black moves first.
  • init, setState and play return the resulting state. getState() returns {board,turn,status,counts:{B,W},winner}, with status playing or over, and winner null while playing or B, W or draw when over.
  • legalMoves() returns all legal positions for the current turn as [r,c] pairs, in any order, or an empty list when the game is over.
  • Use data-testid values board, count-b, count-w, turn, status, winner and new-game for the corresponding elements. Put the decimal count, turn symbol, and status value alone in their respective elements; explanatory labels can sit outside them. The New Game button resets the opening.

Acceptance Checklist

  • A move into an empty cell is legal only if it brackets one or more consecutive opponent pieces with a friendly piece along at least one of eight directions. Place the piece and flip every bracketed piece along all such directions. An occupied or non-flipping move leaves the board and turn unchanged.
  • After a valid move, switch turns, passing back automatically if the opponent cannot move. If neither can move, end the game even on a non-full board. The higher piece count wins; equal counts draw.
  • setState immediately recognizes a position with no moves for either side as terminal. If only the specified side has no moves, retain that turn for inspection with an empty move list; automatic passing is part of play, not single-sided state injection.
  • Neither the supplied board nor a returned state shares mutable arrays with the engine. Real clicks and API calls update the same visible discs, turn and counts; status and winner reflect terminal positions. The offline page runs without browser errors.