Skip to content

Commit be70dc8

Browse files
Fix linting errors for MCP workspace
1 parent 6b84604 commit be70dc8

14 files changed

+179
-161
lines changed

mcp-server/src/ai/rock-paper-scissors-ai.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RockPaperScissorsAI, type Strategy, type Difficulty } from './rock-paper-scissors-ai.js';
1+
import { RockPaperScissorsAI } from './rock-paper-scissors-ai.js';
22
import type { RPSGameState, RPSChoice, Player } from '@turn-based-mcp/shared';
33
import { RockPaperScissorsGame } from '@turn-based-mcp/shared';
44

@@ -59,8 +59,8 @@ describe('RockPaperScissorsAI', () => {
5959
});
6060

6161
it('should counter the most frequent opponent choice', async () => {
62-
// Create a state where opponent played rock 2 times, paper 1 time
63-
let state = initialState;
62+
// Create a state where opponent played rock 2 times, paper 1 time
63+
let state = initialState;
6464
state = game.applyMove(state, { choice: 'rock' }, 'player1');
6565
state = game.applyMove(state, { choice: 'paper' }, 'ai');
6666
state = game.applyMove(state, { choice: 'rock' }, 'player1');
@@ -74,8 +74,8 @@ describe('RockPaperScissorsAI', () => {
7474
});
7575

7676
it('should handle tied frequencies', async () => {
77-
// Create equal frequency scenario
78-
let state = initialState;
77+
// Create equal frequency scenario
78+
let state = initialState;
7979
state = game.applyMove(state, { choice: 'rock' }, 'player1');
8080
state = game.applyMove(state, { choice: 'paper' }, 'ai');
8181
state = game.applyMove(state, { choice: 'paper' }, 'player1');
@@ -126,7 +126,7 @@ describe('RockPaperScissorsAI', () => {
126126
});
127127

128128
it('should default to random for invalid difficulty', async () => {
129-
const choice = await ai.makeChoice(initialState, 'invalid' as Difficulty);
129+
const choice = await ai.makeChoice(initialState, 'invalid' as any);
130130
expect(['rock', 'paper', 'scissors']).toContain(choice);
131131
});
132132
});
@@ -156,7 +156,7 @@ describe('RockPaperScissorsAI', () => {
156156
});
157157

158158
describe('analyzeGameState', () => {
159-
it('should provide basic game analysis for initial state', () => {
159+
it('should provide basic game analysis for initial state', () => {
160160
const analysis = ai.analyzeGameState(initialState);
161161

162162
expect(analysis).toContain('Game Status: playing');
@@ -165,7 +165,7 @@ describe('RockPaperScissorsAI', () => {
165165
});
166166

167167
it('should show round history after moves', async () => {
168-
let state = initialState;
168+
let state = initialState;
169169
state = game.applyMove(state, { choice: 'rock' }, 'player1');
170170
state = game.applyMove(state, { choice: 'paper' }, 'ai');
171171

@@ -175,7 +175,7 @@ describe('RockPaperScissorsAI', () => {
175175
});
176176

177177
it('should analyze opponent patterns', async () => {
178-
let state = initialState;
178+
let state = initialState;
179179
// Create pattern: rock, paper, rock
180180
state = game.applyMove(state, { choice: 'rock' }, 'player1');
181181
state = game.applyMove(state, { choice: 'scissors' }, 'ai');
@@ -196,7 +196,7 @@ describe('RockPaperScissorsAI', () => {
196196
});
197197

198198
it('should show current score correctly', async () => {
199-
let state = initialState;
199+
let state = initialState; // reassigned in subsequent applyMove calls
200200
// Player 1 wins first round
201201
state = game.applyMove(state, { choice: 'rock' }, 'player1');
202202
state = game.applyMove(state, { choice: 'scissors' }, 'ai');
@@ -208,7 +208,7 @@ describe('RockPaperScissorsAI', () => {
208208
});
209209

210210
it('should handle finished games', () => {
211-
let state = initialState;
211+
const state = { ...initialState }; // mutate copy, no reassignment afterward
212212
state.status = 'finished';
213213
state.winner = 'player1';
214214
state.currentRound = 3;
@@ -218,7 +218,7 @@ describe('RockPaperScissorsAI', () => {
218218
});
219219

220220
it('should handle draw rounds', async () => {
221-
let state = initialState;
221+
let state = initialState; // reassigned in applyMove calls
222222
state = game.applyMove(state, { choice: 'rock' }, 'player1');
223223
state = game.applyMove(state, { choice: 'rock' }, 'player2');
224224

@@ -278,7 +278,7 @@ describe('RockPaperScissorsAI', () => {
278278
});
279279

280280
it('should maintain consistent difficulty behavior', async () => {
281-
const difficulties: Difficulty[] = ['easy', 'medium', 'hard'];
281+
const difficulties: any[] = ['easy', 'medium', 'hard'];
282282

283283
for (const difficulty of difficulties) {
284284
const choice = await ai.makeChoice(initialState, difficulty);
@@ -287,7 +287,7 @@ describe('RockPaperScissorsAI', () => {
287287
});
288288

289289
it('should handle incomplete rounds', () => {
290-
let state = initialState;
290+
const state = initialState;
291291
// Only player1 has made a choice in current round
292292
state.rounds[0] = { player1Choice: 'rock' };
293293

@@ -307,7 +307,7 @@ describe('RockPaperScissorsAI', () => {
307307

308308
it('should be consistent with same game state', async () => {
309309
// Create a deterministic scenario
310-
let state = initialState;
310+
let state = initialState;
311311
state = game.applyMove(state, { choice: 'rock' }, 'player1');
312312
state = game.applyMove(state, { choice: 'paper' }, 'player2');
313313
state = game.applyMove(state, { choice: 'rock' }, 'player1');

mcp-server/src/ai/rock-paper-scissors-ai.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RPSGameState, RPSMove, RPSChoice, Difficulty } from '@turn-based-mcp/shared'
1+
import type { RPSGameState, RPSChoice, Difficulty } from '@turn-based-mcp/shared'
22
import { RockPaperScissorsGame } from '@turn-based-mcp/shared'
33

44
export type Strategy = 'random' | 'adaptive' | 'pattern'
@@ -195,7 +195,7 @@ export class RockPaperScissorsAI {
195195
* Rebuilds the opponent history array from the game state's completed rounds.
196196
* Assumes player1 is the human opponent whose patterns we want to learn.
197197
*/
198-
private updateOpponentHistory(gameState: RPSGameState) {
198+
private updateOpponentHistory(gameState: RPSGameState): void {
199199
// Extract opponent moves from completed rounds
200200
this.opponentHistory = []
201201

mcp-server/src/ai/rock-paper-scissors-security.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { RockPaperScissorsAI } from './rock-paper-scissors-ai'
2-
import { RockPaperScissorsGame } from '@turn-based-mcp/shared'
32
import type { RPSGameState, RPSChoice } from '@turn-based-mcp/shared'
43

54
describe('RockPaperScissorsAI - Current Move Security', () => {
65
let ai: RockPaperScissorsAI
7-
let game: RockPaperScissorsGame
86

97
const createMockGameState = (
108
rounds: Array<{
@@ -31,7 +29,7 @@ describe('RockPaperScissorsAI - Current Move Security', () => {
3129

3230
beforeEach(() => {
3331
ai = new RockPaperScissorsAI()
34-
game = new RockPaperScissorsGame()
32+
// separate game instance not required for these security-focused tests
3533
})
3634

3735
describe('Current Round Security Tests', () => {

mcp-server/src/ai/tic-tac-toe-ai.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TicTacToeAI, type Difficulty } from './tic-tac-toe-ai.js';
1+
import { TicTacToeAI } from './tic-tac-toe-ai.js';
22
import type { TicTacToeGameState, Player } from '@turn-based-mcp/shared';
33
import { TicTacToeGame } from '@turn-based-mcp/shared';
44

@@ -35,7 +35,7 @@ describe('TicTacToeAI', () => {
3535

3636
it('should choose from available moves only', async () => {
3737
// Fill most of the board
38-
let state = initialState;
38+
const state = initialState;
3939
state.board = [
4040
['X', 'O', 'X'],
4141
['O', 'X', 'O'],
@@ -61,7 +61,7 @@ describe('TicTacToeAI', () => {
6161

6262
describe('medium difficulty', () => {
6363
it('should win when possible', async () => {
64-
let state = initialState;
64+
const state = initialState;
6565
// Set up a winning scenario for AI
6666
state.board = [
6767
['O', 'O', null],
@@ -74,7 +74,7 @@ describe('TicTacToeAI', () => {
7474
});
7575

7676
it('should block opponent from winning', async () => {
77-
let state = initialState;
77+
const state = initialState;
7878
// Set up scenario where player can win
7979
state.board = [
8080
['X', 'X', null],
@@ -101,7 +101,7 @@ describe('TicTacToeAI', () => {
101101
});
102102

103103
it('should prefer center when available', async () => {
104-
let state = initialState;
104+
const state = initialState;
105105
state.board = [
106106
['X', null, null],
107107
[null, null, null],
@@ -113,7 +113,7 @@ describe('TicTacToeAI', () => {
113113
});
114114

115115
it('should choose corners when center is taken', async () => {
116-
let state = initialState;
116+
const state = initialState;
117117
state.board = [
118118
[null, null, null],
119119
[null, 'X', null],
@@ -130,7 +130,7 @@ describe('TicTacToeAI', () => {
130130
});
131131

132132
it('should prioritize winning over blocking', async () => {
133-
let state = initialState;
133+
const state = initialState;
134134
// Both AI and player can win
135135
state.board = [
136136
['O', 'O', null], // AI can win here
@@ -145,7 +145,7 @@ describe('TicTacToeAI', () => {
145145

146146
describe('hard difficulty', () => {
147147
it('should play optimally using minimax', async () => {
148-
let state = initialState;
148+
const state = initialState;
149149
// Classic opening: AI should respond optimally to corner play
150150
state.board = [
151151
['X', null, null],
@@ -158,7 +158,7 @@ describe('TicTacToeAI', () => {
158158
});
159159

160160
it('should never lose from a winning position', async () => {
161-
let state = initialState;
161+
const state = initialState;
162162
// AI is in a winning position
163163
state.board = [
164164
['O', 'X', null],
@@ -171,7 +171,7 @@ describe('TicTacToeAI', () => {
171171
});
172172

173173
it('should force a draw from losing position', async () => {
174-
let state = initialState;
174+
const state = initialState;
175175
// Player has advantage but AI should force draw
176176
state.board = [
177177
['X', null, null],
@@ -206,7 +206,7 @@ describe('TicTacToeAI', () => {
206206
});
207207

208208
it('should default to easy difficulty for invalid difficulty', async () => {
209-
const move = await ai.makeMove(initialState, 'invalid' as Difficulty);
209+
const move = await ai.makeMove(initialState, 'invalid' as any);
210210
expect(game.validateMove(initialState, move, 'ai')).toBe(true);
211211
});
212212
});
@@ -223,7 +223,7 @@ describe('TicTacToeAI', () => {
223223
});
224224

225225
it('should detect winning opportunities', () => {
226-
let state = initialState;
226+
const state = initialState;
227227
state.board = [
228228
['O', 'O', null],
229229
['X', null, null],
@@ -235,7 +235,7 @@ describe('TicTacToeAI', () => {
235235
});
236236

237237
it('should detect player threats', () => {
238-
let state = initialState;
238+
const state = initialState;
239239
state.board = [
240240
['X', 'X', null],
241241
['O', null, null],
@@ -250,7 +250,7 @@ describe('TicTacToeAI', () => {
250250
});
251251

252252
it('should analyze board state correctly', () => {
253-
let state = initialState;
253+
const state = initialState;
254254
state.board = [
255255
['X', null, 'O'],
256256
[null, 'X', null], // Center has X
@@ -264,7 +264,7 @@ describe('TicTacToeAI', () => {
264264
});
265265

266266
it('should handle game-ending scenarios', () => {
267-
let state = initialState;
267+
const state = initialState;
268268
state.board = [
269269
['X', 'X', 'X'],
270270
['O', 'O', null],
@@ -280,7 +280,7 @@ describe('TicTacToeAI', () => {
280280

281281
describe('edge cases and robustness', () => {
282282
it('should handle full board gracefully', async () => {
283-
let state = initialState;
283+
const state = initialState;
284284
state.board = [
285285
['X', 'O', 'X'],
286286
['O', 'X', 'O'],
@@ -304,7 +304,7 @@ describe('TicTacToeAI', () => {
304304
});
305305

306306
it('should maintain consistent behavior across difficulties', async () => {
307-
const difficulties: Difficulty[] = ['easy', 'medium', 'hard'];
307+
const difficulties: any[] = ['easy', 'medium', 'hard'];
308308

309309
for (const difficulty of difficulties) {
310310
const move = await ai.makeMove(initialState, difficulty);
@@ -313,7 +313,7 @@ describe('TicTacToeAI', () => {
313313
});
314314

315315
it('should handle near-end game scenarios', async () => {
316-
let state = initialState;
316+
const state = initialState;
317317
// Only one move left
318318
state.board = [
319319
['X', 'O', 'X'],

mcp-server/src/ai/tic-tac-toe-ai.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TicTacToeGameState, TicTacToeMove, Difficulty } from '@turn-based-mcp/shared'
1+
import type { TicTacToeGameState, TicTacToeMove, Difficulty, PlayerId } from '@turn-based-mcp/shared'
22
import { TicTacToeGame } from '@turn-based-mcp/shared'
33

44
/**
@@ -193,11 +193,11 @@ export class TicTacToeAI {
193193
* Tests each valid move to see if it results in an immediate win.
194194
* Used for both finding AI wins and blocking opponent wins.
195195
*/
196-
private findWinningMove(gameState: TicTacToeGameState, playerId: string): TicTacToeMove | null {
197-
const validMoves = this.game.getValidMoves(gameState, playerId as any)
196+
private findWinningMove(gameState: TicTacToeGameState, playerId: PlayerId): TicTacToeMove | null {
197+
const validMoves = this.game.getValidMoves(gameState, playerId)
198198

199199
for (const move of validMoves) {
200-
const tempGameState = this.game.applyMove(gameState, move, playerId as any)
200+
const tempGameState = this.game.applyMove(gameState, move, playerId)
201201
const result = this.game.checkGameEnd(tempGameState)
202202

203203
if (result && result.winner === playerId) {

0 commit comments

Comments
 (0)