Skip to content

Commit b782c50

Browse files
Merge pull request #46 from chrisreddington/3d-mode
Add 3D Tic-Tac-Toe and enhance game functionality
2 parents 25319cd + e1a1e44 commit b782c50

21 files changed

+2413
-777
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: Game Player
3+
description: Play turn-based games like Tic-Tac-Toe and Rock Paper Scissors
4+
tools: ['turn-based-games/*']
5+
---
6+
7+
You are a GAME PLAYING agent for turn-based games. Your responsibility is to manage the game flow, make AI moves, and wait for human responses.
8+
9+
## Available Games
10+
11+
| Game | Type Key | Description |
12+
|------|----------|-------------|
13+
| Tic-Tac-Toe | `tic-tac-toe` | Classic 3x3 grid, get three in a row |
14+
| Rock Paper Scissors | `rock-paper-scissors` | Best of N rounds |
15+
16+
## Difficulty Levels
17+
18+
- `easy` - Random/beginner-friendly AI
19+
- `medium` - Strategic play (default)
20+
- `hard` - Optimal/advanced AI
21+
22+
## Workflow
23+
24+
<workflow>
25+
1. GAME SETUP
26+
- Use create_game with user's preferences (game type, difficulty, etc.)
27+
- Provide clickable deep link: http://localhost:3000/games/{gameType}/{gameId}
28+
- Tell user to open the link to make their moves
29+
30+
2. GAME LOOP (repeat until game ends)
31+
- If it's AI's turn: call play_game
32+
- IMMEDIATELY report the updated game state to user
33+
- If game status is 'playing' and it's player's turn: call wait_for_player_move
34+
- Continue based on the result
35+
36+
3. PLAYER MOVE HANDLING
37+
- If wait_for_player_move returns status 'move_detected': continue with AI's turn
38+
- If wait_for_player_move returns status 'timeout':
39+
- Call wait_for_player_move a maximum of 2 times again to continue polling
40+
- Ask the user to make their move via the game link or in chat.
41+
- If player tells you their move in chat: use make_player_move tool
42+
43+
4. CHAT-BASED MOVES
44+
- Player can say things like "I'll play top left" or "row 1, column 2" or "rock"
45+
- Use make_player_move to submit their move
46+
- For tic-tac-toe: convert to 0-indexed {row, col} (e.g., "top left" = {row: 0, col: 0})
47+
- For rock-paper-scissors: extract the choice ("rock", "paper", or "scissors")
48+
49+
5. GAME END
50+
- When game status is 'finished': announce the winner/result
51+
- Offer to analyze the game or start a new one
52+
</workflow>
53+
54+
## Critical Rules
55+
56+
<critical_rules>
57+
1. CONTINUOUS POLLING: When wait_for_player_move times out, IMMEDIATELY call it again up to a maximum of 3 times in total.
58+
- Do NOT ask the user if they want to continue waiting
59+
60+
2. AI MOVE INDEPENDENCE: When calling play_game for the AI move, the AI calculates its own optimal move
61+
- Do NOT try to influence the AI's move based on the player's move
62+
- The AI uses its own strategy based on game state
63+
64+
3. ALWAYS provide the deep link URL after creating a game
65+
- Format: http://localhost:3000/games/{gameType}/{gameId}
66+
- Example: http://localhost:3000/games/tic-tac-toe/abc123-def456
67+
68+
4. MOVE FORMAT for make_player_move:
69+
- Tic-tac-toe: { row: 0-2, col: 0-2 } (0-indexed)
70+
- Rock-paper-scissors: { choice: "rock" | "paper" | "scissors" }
71+
</critical_rules>
72+
73+
## Move Translation Guide (Tic-Tac-Toe)
74+
75+
| User says | Translates to |
76+
|-----------|---------------|
77+
| "top left", "1,1" | {row: 0, col: 0} |
78+
| "top center/middle" | {row: 0, col: 1} |
79+
| "top right" | {row: 0, col: 2} |
80+
| "middle left" | {row: 1, col: 0} |
81+
| "center", "middle" | {row: 1, col: 1} |
82+
| "middle right" | {row: 1, col: 2} |
83+
| "bottom left" | {row: 2, col: 0} |
84+
| "bottom center/middle" | {row: 2, col: 1} |
85+
| "bottom right" | {row: 2, col: 2} |
86+
87+
## Stopping Rules
88+
89+
<stopping_rules>
90+
STOP the game loop if:
91+
- Game status is 'finished'
92+
- User explicitly asks to stop/quit
93+
- An error occurs that cannot be recovered
94+
</stopping_rules>

.github/copilot-instructions.md

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,78 @@
1-
# Turn-Based Games Platform - AI Developer Guide
1+
# Turn-Based Games Platform
22

3-
## Architecture Overview
3+
## Purpose
44

5-
This is a **monorepo workspace** with three packages that work together to create a turn-based games platform:
5+
These instructions guide Copilot across all files in this monorepo. Language-specific and framework-specific rules are in separate instruction files under `.github/instructions/`.
66

7-
- **`shared/`** - Core game logic, types, and SQLite storage (TypeScript library)
8-
- **`web/`** - Next.js 15 frontend with API routes (React + TailwindCSS)
9-
- **`mcp-server/`** - Model Context Protocol server providing AI opponents (Node.js service)
7+
## Repository Structure
108

11-
**Key Integration Pattern**: The MCP server communicates with the web app via HTTP calls to `/api/games/*` endpoints, not direct database access. This maintains clear service boundaries.
9+
- `shared/` - Core game logic, types, and SQLite storage (TypeScript library)
10+
- `web/` - Next.js 15 frontend with API routes (React + TailwindCSS)
11+
- `mcp-server/` - Model Context Protocol server providing AI opponents (Node.js service)
1212

13-
## Development Workflow
13+
## Code Standards
1414

15-
**Essential build order** (shared must be built first):
16-
```bash
17-
npm run build --workspace=shared # Always run first
18-
npm run dev --workspace=web # Starts Next.js dev server (port 3000)
19-
npm run dev --workspace=mcp-server # Starts MCP server (stdio)
20-
```
15+
### Required Before Each Commit
16+
17+
- Run `npm run lint` to check for linting issues
18+
- Run `npm run test` to ensure all tests pass
19+
- Build shared package first when making cross-package changes
20+
21+
### Development Flow
22+
23+
- Build shared: `npm run build --workspace=shared` (always run first)
24+
- Dev web: `npm run dev --workspace=web` (starts Next.js on port 3000)
25+
- Dev MCP: `npm run dev --workspace=mcp-server` (starts MCP server via stdio)
26+
- Full test: `npm run test` (runs all workspace tests)
27+
- Full lint: `npm run lint` (runs all workspace linting)
2128

22-
**Database location**: SQLite file is at `web/games.db` by default, controlled by `GAMES_DB_PATH` env var.
29+
### Database
2330

24-
## Core Architecture Patterns
31+
- SQLite file location: `web/games.db` (default)
32+
- Controlled by `GAMES_DB_PATH` environment variable
2533

26-
### Game Implementation Pattern
27-
All games follow the `Game<TGameState, TMove>` interface in `shared/src/types/game.ts`:
28-
- `validateMove()` - Check if move is legal
29-
- `applyMove()` - Apply move and return new state
30-
- `checkGameEnd()` - Determine win/draw/continue
31-
- `getValidMoves()` - Get available moves
32-
- `getInitialState()` - Create starting game state
34+
## Architecture Guidelines
3335

34-
### Storage Pattern
35-
Games use a dual-storage approach:
36-
- **Web app**: Direct SQLite access via `shared/src/storage/sqlite-storage.ts`
37-
- **MCP server**: HTTP calls to web API endpoints (no direct DB access)
36+
### Service Boundaries
3837

39-
### AI Integration Pattern
40-
The MCP server exposes tools like `play_tic_tac_toe` and `create_tic_tac_toe_game`. It calls the web API to:
41-
1. Fetch current game state
42-
2. Calculate AI move using algorithms in `mcp-server/src/ai/`
43-
3. Submit move back via API POST
38+
- MCP server communicates with web app via HTTP calls to `/api/games/*` endpoints
39+
- MCP server never accesses the database directly
40+
- Web app uses direct SQLite access via `shared/src/storage/sqlite-storage.ts`
4441

45-
## File Organization Conventions
42+
### Game Interface
4643

47-
### API Routes Structure
48-
- `web/src/app/api/games/[game-type]/route.ts` - Create/list games
49-
- `web/src/app/api/games/[game-type]/[id]/move/route.ts` - Make moves
44+
All games implement `Game<TGameState, TMove>` interface in `shared/src/types/game.ts`:
5045

51-
### Game-Specific Types
52-
Game states extend `BaseGameState` and are defined in `shared/src/types/games.ts`:
53-
- `TicTacToeGameState` includes `board: Board` and `playerSymbols`
54-
- `RPSGameState` includes `rounds` and `scores`
46+
```typescript
47+
// Required methods for all game implementations
48+
validateMove(state, move) // Check if move is legal
49+
applyMove(state, move) // Apply move and return new state
50+
checkGameEnd(state) // Determine win/draw/continue
51+
getValidMoves(state) // Get available moves
52+
getInitialState(config) // Create starting game state
53+
```
54+
55+
### API Routes Pattern
5556

56-
### Component Organization
57-
- `web/src/components/games/` - Game-specific UI components
58-
- `web/src/app/games/[game-type]/` - Game-specific pages
57+
- Create/list games: `web/src/app/api/games/[game-type]/route.ts`
58+
- Make moves: `web/src/app/api/games/[game-type]/[id]/move/route.ts`
5959

60-
## Development Guidelines
60+
## Adding New Games
6161

62-
### Adding New Games
6362
1. Define types in `shared/src/types/games.ts`
6463
2. Implement game class in `shared/src/games/`
6564
3. Add API routes in `web/src/app/api/games/[new-game]/`
6665
4. Create AI implementation in `mcp-server/src/ai/`
6766
5. Add MCP tools in `mcp-server/src/server.ts`
6867
6. Build UI components in `web/src/components/games/`
6968

70-
### Environment Variables
69+
## Environment Variables
70+
7171
- `WEB_API_BASE` - MCP server's web app URL (default: `http://localhost:3000`)
7272
- `GAMES_DB_PATH` - SQLite database location (default: `./games.db`)
7373

74-
### Key Dependencies
75-
- `@modelcontextprotocol/sdk` - MCP server framework
76-
- `sqlite3` - Database (shared between web/mcp-server)
77-
- `@turn-based-mcp/shared` - Internal workspace dependency
74+
## Security Considerations
75+
76+
- Never hardcode credentials or API keys
77+
- Validate all user inputs in API routes
78+
- Sanitize game IDs and player names before database operations

.github/instructions/api-routes.instructions.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ applyTo: "web/src/app/api/**/*.{ts,js}"
33
description: Next.js API route development patterns for the turn-based games platform
44
---
55

6-
# API Route Instructions
6+
# Next.js API Routes
7+
8+
## Purpose
9+
10+
Patterns for creating API routes in the web package. Covers request handling, game integration, error handling, and security.
711

8-
Follow these patterns when creating Next.js API routes:
912

1013
## File Structure and Naming
1114

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
applyTo: "**/{copilot-instructions.md,*.instructions.md,AGENTS.md,CLAUDE.md,GEMINI.md}"
3+
description: Guidelines for writing GitHub Copilot custom instruction files
4+
---
5+
6+
# Writing GitHub Copilot Custom Instructions
7+
8+
Follow these guidelines when creating or modifying Copilot instruction files.
9+
10+
## File Types and Their Purpose
11+
12+
### Repository-Wide Instructions (`copilot-instructions.md`)
13+
14+
Use for:
15+
- General project standards that apply to all files
16+
- Cross-cutting concerns (error handling philosophy, architecture patterns)
17+
- Build, test, and lint commands
18+
- Security requirements
19+
- Environment variable documentation
20+
21+
Do NOT include:
22+
- Language-specific coding standards
23+
- Framework-specific patterns
24+
- Rules that only apply to certain file types
25+
26+
### Path-Specific Instructions (`*.instructions.md`)
27+
28+
Use for:
29+
- Language-specific coding standards (TypeScript, Python, etc.)
30+
- Framework-specific patterns (React, Next.js, etc.)
31+
- Technology-specific concerns (testing, API routes, etc.)
32+
- Different rules for different parts of the codebase
33+
34+
Always include frontmatter:
35+
```yaml
36+
---
37+
applyTo: "glob/pattern/**/*.{ts,tsx}"
38+
description: Brief description of what these instructions cover
39+
---
40+
```
41+
42+
## Writing Effective Instructions
43+
44+
### Structure and Formatting
45+
46+
- Use distinct headings to separate topics
47+
- Use bullet points for easy scanning
48+
- Write short, imperative directives (not narrative paragraphs)
49+
- Keep any single file under 1,000 lines
50+
51+
```markdown
52+
<!-- ❌ Avoid: Narrative style -->
53+
When you're reviewing code, it would be good if you could try to look
54+
for situations where developers might have accidentally left in
55+
sensitive information like passwords or API keys.
56+
57+
<!-- ✅ Prefer: Imperative bullet points -->
58+
## Security
59+
- Check for hardcoded secrets, API keys, or credentials
60+
- Validate all user inputs
61+
- Use parameterized queries to prevent SQL injection
62+
```
63+
64+
### Provide Concrete Examples
65+
66+
Include code snippets showing correct and incorrect patterns:
67+
68+
```markdown
69+
## Naming Conventions
70+
71+
```typescript
72+
// ❌ Avoid
73+
const d = new Date();
74+
const x = users.filter(u => u.active);
75+
76+
// ✅ Prefer
77+
const currentDate = new Date();
78+
const activeUsers = users.filter(user => user.isActive);
79+
```
80+
```
81+
82+
### Be Specific and Actionable
83+
84+
```markdown
85+
<!-- ❌ Vague -->
86+
- Write good tests
87+
- Use proper error handling
88+
89+
<!-- ✅ Specific -->
90+
- Test names should follow: "should [expected behavior] when [condition]"
91+
- Wrap async operations in try/catch and return appropriate error responses
92+
```
93+
94+
## What NOT to Include
95+
96+
Instructions that Copilot cannot follow:
97+
98+
- Formatting changes: "Use bold text for critical issues"
99+
- External links: "Follow standards at https://example.com" (copy content instead)
100+
- Vague quality requests: "Be more accurate", "Don't miss any issues"
101+
- UI modifications: "Add emoji to comments"
102+
103+
## Glob Pattern Examples
104+
105+
```yaml
106+
# All TypeScript files
107+
applyTo: "**/*.{ts,tsx}"
108+
109+
# Test files (both patterns)
110+
applyTo: "**/{*.test.{ts,tsx,js,jsx},__tests__/**/*.{ts,tsx,js,jsx}}"
111+
112+
# Specific directory
113+
applyTo: "web/src/components/**/*.{tsx,ts}"
114+
115+
# API routes
116+
applyTo: "web/src/app/api/**/*.{ts,js}"
117+
118+
# Multiple specific paths
119+
applyTo: "{shared,mcp-server}/src/**/*.ts"
120+
```
121+
122+
## Recommended Section Order
123+
124+
1. **Purpose** - Brief statement of what the file covers
125+
2. **Naming Conventions** - How to name things
126+
3. **Code Style** - Formatting and structure rules
127+
4. **Patterns** - Common patterns to follow (with examples)
128+
5. **Error Handling** - How to handle errors
129+
6. **Security** - Security considerations
130+
7. **Testing** - Testing expectations
131+
8. **Performance** - Performance considerations
132+
133+
## Iteration Process
134+
135+
1. Start with 10-20 specific instructions
136+
2. Note which instructions are followed or missed
137+
3. Refine wording for missed instructions
138+
4. Add new instructions incrementally based on needs

0 commit comments

Comments
 (0)