Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Repository Guidelines

## Project Structure & Module Organization
`index.html` is the single-page shell; it links the modern styling in `battleship.css` and boots `battleship.js` as an ES module. Gameplay logic lives under `src/`: `game.js` orchestrates turns and win states, `board.js` tracks ship placement and attacks, `ship.js` models individual vessels, `ai-controller.js` handles smart CPU targeting, and `ui-controller.js` updates the DOM. Shared constants (ship specs, orientations, board size) are defined in `src/constants.js` so both players stay in sync. `battleship.js` wires the controllers together, exposes the global bridge required by the existing `onclick` handlers, and inserts the current year into the footer. Static assets (splash/explosion SVGs, icons, screenshots) live in `images/`; prefer `.webp` for screenshots and keep SVGs optimized (`svgo` or similar) when adding new art.

Comment on lines +3 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Docs out of sync with code (bridge is disabled).

AGENTS.md says battleship.js wires controllers and exposes a global bridge, but the file has all wiring commented out in this PR. Either re-enable the bridge (preferred) or update this section to reflect current state.


I'll verify the review comment by checking both AGENTS.md and battleship.js to confirm whether there's a documentation-code mismatch.


🏁 Script executed:

#!/bin/bash
# Check AGENTS.md content, especially around the mentioned section
cat AGENTS.md 2>/dev/null || echo "AGENTS.md not found"

Length of output: 3383


🏁 Script executed:

#!/bin/bash
# Check battleship.js for bridge wiring and commented code
if [ -f "battleship.js" ]; then
  echo "=== Full battleship.js ===" 
  cat battleship.js
elif [ -f "src/battleship.js" ]; then
  echo "=== Full src/battleship.js ==="
  cat src/battleship.js
else
  echo "Searching for battleship.js..."
  find . -name "battleship.js" -type f 2>/dev/null | head -5
fi

Length of output: 1638


🏁 Script executed:

#!/bin/bash
# Also search for any commented wiring or bridge references
echo "=== Searching for bridge/wiring references and commented code ==="
rg -n "bridge|wiring|onclick|global" -i --type=js 2>/dev/null | head -30

Length of output: 462


🏁 Script executed:

#!/bin/bash
# Check if there's an index.html to understand the structure
if [ -f "index.html" ]; then
  echo "=== index.html ===" 
  cat index.html
fi

Length of output: 20632


🏁 Script executed:

#!/bin/bash
# List directory structure to understand layout
echo "=== Repository structure ===" 
ls -la
echo ""
echo "=== src/ directory ===" 
ls -la src/ 2>/dev/null || echo "src/ not found"

Length of output: 1408


🏁 Script executed:

#!/bin/bash
# Check git status or diff to see what's commented in this PR
echo "=== Recent git changes involving battleship or bridge ===" 
git diff HEAD~1 --no-ext-diff 2>/dev/null | grep -A5 -B5 -i "bridge\|wiring\|battleship" | head -50 || echo "Git diff not available"

Length of output: 401


🏁 Script executed:

#!/bin/bash
# More targeted search for battleship.js location and commented sections
echo "=== Looking for commented code patterns in JS files ===" 
rg -n "\/\/" --type=js -A2 -B2 "controllers|bridge|wiring" 2>/dev/null | head -40

Length of output: 55


🏁 Script executed:

#!/bin/bash
# Final check: Find and display the actual battleship.js file
echo "=== Finding battleship.js ===" 
fd -t f "battleship.js" -x cat {} \; 2>/dev/null

Length of output: 1641


🏁 Script executed:

#!/bin/bash
# Check AGENTS.md for the exact claim about the bridge
echo "=== AGENTS.md content ===" 
if [ -f "AGENTS.md" ]; then
  cat AGENTS.md
else
  echo "AGENTS.md not found; checking for similar files..."
  find . -name "*AGENT*" -o -name "*agent*" 2>/dev/null | head -10
fi

Length of output: 3409


🏁 Script executed:

#!/bin/bash
# List all markdown files in root
echo "=== Root-level markdown files ===" 
ls -1 *.md 2>/dev/null

Length of output: 53


🏁 Script executed:

#!/bin/bash
# Check all JS files in root and src
echo "=== JS files in repository ===" 
fd -t f "\.js$" 2>/dev/null | head -20

Length of output: 140


🏁 Script executed:

#!/bin/bash
# Comprehensive check: show directory tree
echo "=== Directory tree ===" 
find . -type f \( -name "*.js" -o -name "*.md" -o -name "*.html" \) | sort | head -30

Length of output: 183


🏁 Script executed:

#!/bin/bash
# Direct approach: cat all candidate files
echo "=== Attempting to read AGENTS.md ===" 
cat AGENTS.md 2>&1
echo ""
echo "=== Attempting to read battleship.js ===" 
cat battleship.js 2>&1

Length of output: 5074


🏁 Script executed:

#!/bin/bash
# Check if files exist and show what we have
for f in AGENTS.md battleship.js src/battleship.js index.html; do
  echo "Checking $f..."
  [ -f "$f" ] && echo "EXISTS" || echo "NOT FOUND"
done

Length of output: 131


Re-enable the global bridge in battleship.js; it is actively required by index.html's onclick handlers.

AGENTS.md correctly documents that battleship.js exposes a global bridge for onclick handlers. index.html relies on this—it calls turnVertical(), turnHorizontal(), selectShip(), clickStartGame(), clickTarget(), and clickCpuBoard() from inline event attributes. All that wiring is currently commented out in battleship.js, so these functions are undefined at runtime and the game will not work. The PR comment itself ("does this need to commented back in to work?") signals uncertainty. Either uncomment the bridge code (preferred) or refactor index.html to remove inline onclick handlers and use event listeners instead.

🤖 Prompt for AI Agents
In AGENTS.md around lines 3 to 5: the documentation notes that battleship.js
exposes a global bridge required by index.html's inline onclick handlers, but
the actual bridge in battleship.js has been commented out so functions like
turnVertical, turnHorizontal, selectShip, clickStartGame, clickTarget, and
clickCpuBoard are undefined at runtime; re-enable the global bridge by restoring
(uncommenting) the code that assigns these functions to window (or otherwise
attaches them to the global object) so index.html's inline handlers work, or
alternatively remove all inline onclick attributes from index.html and replace
them with proper addEventListener wiring—prefer restoring the bridge for minimal
change.

## Build, Test, and Development Commands
- `npx http-server . --port 3000` serves the project with correct relative paths and caching headers; use it during active development.
- `python3 -m http.server 3000` provides a zero-dependency fallback if Node.js is unavailable.
- `open index.html` (or your OS equivalent) is fine for quick visual checks, but an HTTP server avoids asset/CORS issues and mirrors production loading better.

## Coding Style & Naming Conventions
Follow the ES module pattern already in place: default to `const`/`let`, keep classes in their own files, and export the minimal surface each module needs. JavaScript uses two-space indentation and descriptive method names (`placePlayerShip`, `handleAttackResult`). CSS also uses two spaces and kebab-case selectors; leverage the variables at the top of `battleship.css`—especially `--cell-size` for board square sizing—rather than hard-coding pixels. DOM IDs remain camelCase (`remove-on-start` is the lone kebab-case ID for legacy reasons); keep new classes prefixed with the component they style (`.player-board`, `.ship-select`) to make overrides predictable.

## Testing Guidelines
There is no automated suite yet, so rely on manual QA. Serve the site, then walk through ship placement, game start, repeated attack loops, and both win and loss flows. Confirm the hover preview outlines the full ship footprint (blue when valid, red when out of bounds or overlapping) before you click, the CPU AI switches from random attacks to focused hunts after a hit, and the retry button reloads cleanly. Validate responsive breakpoints at 1280px, 1024px, 768px, and 375px widths—the UI should keep both boards visible side by side on desktop and wrap sensibly on smaller screens. Capture GIFs or annotated screenshots for regressions and attach them to your PR.

## Commit & Pull Request Guidelines
History favors concise, lower-case subjects (`add retry button logic`). Keep messages imperative, under ~72 characters, and group related CSS/JS changes in a single commit where practical. PRs should include: (1) a short summary, (2) manual test notes listing the commands above, (3) before/after visuals for UI tweaks, and (4) linked issues or TODO references. Request reviewers aligned with the change (UI polish, gameplay logic, asset updates) to speed feedback. For larger refactors, note any follow-up tasks (e.g., migrating from inline `onclick` attributes) so the next contributor can pick them up easily.
Loading