WE HAVE JS: var gameState = [ [[1,1], [-1, -1], [8,2], [8,2], [-1 ,-1], [9,2], [9,2]],…
- User
WE HAVE JS:
var gameState = [ [[1,1], [-1, -1], [8,2], [8,2], [-1 ,-1], [9,2], [9,2]], [[1,1], [-1,-1], [10,2], [10,2], [-1,-1], [-1,-1], [7,1]], [[0,2], [0,2], [0,2], [3,1], [-1,-1], [5,1], [7,1]], [[2,1], [11,2], [11,2], [3,1], [-1,-1], [5,1], [6,1]], [[2,1], [-1,-1], [4,2], [4,2], [12,2], [12,2], [6,1]] ];
var goal1 = {x:6,y:2}; var playerColor1 = 0;
var carColors = { 0: 'red', 1: 'blue', 2: 'green', 3: 'yellow', 4: 'purple', 5: 'orange', 6: 'pink', 7: 'brown', 8: 'gray', 9: 'black', 10: 'darkgrey', 11: 'turquoise', 12: 'silver' };
var selectedCar = null;
function drawGameState() { ctx.clearRect(0, 0, canvas.width, canvas.height); gameState.forEach((row, y) => { row.forEach((cell, x) => { if (cell[0] !== -1) { ctx.fillStyle = carColors[cell[0]]; ctx.fillRect(x * 100, y * 100, 100, 100); ctx.fillStyle = 'black'; ctx.font = '24px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(cell[0], x * 100 + 50, y * 100 + 50); } else { ctx.fillStyle = 'white'; ctx.fillRect(x * 100, y * 100, 100, 100); } }); }); }
canvas.addEventListener('touchstart', (event) => { event.preventDefault(); const touch = event.touches[0]; const rect = canvas.getBoundingClientRect(); const x = Math.floor((touch.clientX - rect.left) / 100); const y = Math.floor((touch.clientY - rect.top) / 100); if (gameState[y][x][0] !== -1) { selectedCar = [x, y]; } });
canvas.addEventListener('touchend', (event) => { event.preventDefault(); if (selectedCar !== null) { const touch = event.changedTouches[0]; const rect = canvas.getBoundingClientRect(); const x = Math.floor((touch.clientX - rect.left) / 100); const y = Math.floor((touch.clientY - rect.top) / 100);
codeconst [carX, carY] = selectedCar; const [carId, carOrientation] = gameState[carY][carX]; const dx = x - carX; const dy = y - carY; const moveAxis = carOrientation === 1 ? 'y' : 'x'; const moveDir = moveAxis === 'x' ? dx : dy; if (moveDir !== 0) { const [newX, newY, carLength] = getCarInfo(carX, carY, carOrientation); const newPosition = moveAxis === 'x' ? newX + dx : newY + dy; const isValidMove = checkValidMove(newX, newY, newPosition, moveAxis, carLength); if (isValidMove) { moveCar(newX, newY, newPosition, carId, carOrientation, carLength); } } selectedCar = null; drawGameState(); if(gameState[goal1.y][goal1.x][0]==playerColor1)console.log(1111); Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.