Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
int64
1
120
prompt
stringlengths
87
1.21k
entry_point
stringlengths
4
27
canonical_solution
stringlengths
8
2.93k
test
stringclasses
1 value
1
public class Solution { /** Creates and displays a grid-based game board of specified dimensions. */ public void createGameBoard() {
createGameBoard
// Board dimensions are defined by GRID_WIDTH and GRID_HEIGHT. // The board is rendered in the paintComponent method. } }
def check(candidate): pass
2
public class Solution { /** Places the snake on the game board with an initial length and starting position, and sets the initial moving direction. */ public void initializeSnake() {
initializeSnake
snake = new LinkedList<>(); int startX = GRID_WIDTH / 2; int startY = GRID_HEIGHT / 2; // Initial length of 3 segments. snake.add(new Position(startX, startY)); snake.add(new Position(startX - 1, startY)); snake.add(new Position(startX - 2, startY)); curre...
def check(candidate): pass
3
public class Solution { /** Renders the current state of the game board including the snake and food positions. */ public void renderGameBoard() {
renderGameBoard
} }
def check(candidate): pass
4
public class Solution { /** Processes arrow key inputs to update the snake's direction. */ public void handleKeyPress(int keyCode) {
handleKeyPress
if (keyCode == KeyEvent.VK_UP && currentDirection != Direction.DOWN) { currentDirection = Direction.UP; } if (keyCode == KeyEvent.VK_DOWN && currentDirection != Direction.UP) { currentDirection = Direction.DOWN; } if (keyCode == KeyEvent.VK_LEFT && currentDirectio...
def check(candidate): pass
5
public class Solution { /** Continuously moves the snake in the current direction and updates its position on the grid. Dependencies: - public void detectCollision(): Checks for collisions between the snake's head and boundaries or its own body. - public void handleFoodConsumption(): Determines if the snake's head has...
moveSnake
if (!inGame) { return; } Position head = snake.getFirst(); Position newHead = new Position(head.x, head.y); switch (currentDirection) { case UP: newHead.y--; break; case DOWN: newHead.y++; break; case LEFT: n...
def check(candidate): pass
6
public class Solution { /** Generates food at a random valid position on the game board ensuring it does not appear on the snake's body. */ public Position generateFood() {
generateFood
Random rand = new Random(); Position pos; do { int x = rand.nextInt(GRID_WIDTH); int y = rand.nextInt(GRID_HEIGHT); pos = new Position(x, y); } while (snake.contains(pos)); return pos; } }
def check(candidate): pass
7
public class Solution { /** Checks for collisions between the snake's head and boundaries or its own body. */ public boolean detectCollision(Position headPosition) {
detectCollision
if (headPosition.x < 0 || headPosition.x >= GRID_WIDTH || headPosition.y < 0 || headPosition.y >= GRID_HEIGHT) { return true; } for (int i = 1; i < snake.size(); i++) { if (headPosition.equals(snake.get(i))) { return true; } } return false; } }
def check(candidate): pass
8
public class Solution { /** Determines if the snake's head has collided with food. If true, increases snake length and updates the score. Dependencies: - public void generateFood(): Generates food at a random valid position on the game board ensuring it does not appear on the snake's body. - public void updateScoreDis...
handleFoodConsumption
this.x = x; this.y = y; } }
def check(candidate): pass
9
public class Solution { /** Updates and displays the current score on the screen. */ public void updateScoreDisplay(int score) {
updateScoreDisplay
score = newScore; } }
def check(candidate): pass
10
public class Solution { /** Handles the game over logic when the snake collides with the boundaries or itself, displays a game over message, and allows for restart. Dependencies: - public void restartGame(): Resets the game state to initial conditions allowing the player to start a new game. */ public void gameOve...
gameOver
inGame = false; timer.stop(); JOptionPane.showMessageDialog(this, "Game Over! Your score: " + score + " Press Enter to restart.", "Game Over", JOptionPane.INFORMATION_MESSAGE); } }
def check(candidate): pass
11
public class Solution { /** Resets the game state to initial conditions allowing the player to start a new game. Dependencies: - public void createGameBoard(): Creates and displays a grid-based game board of specified dimensions. - public void initializeSnake(): Places the snake on the game board with an initial lengt...
restartGame
inGame = true; score = 0; createGameBoard(); initializeSnake(); food = generateFood(); updateScoreDisplay(score); if (timer != null) { timer.stop(); } timer = new Timer(DELAY, this); timer.start(); repaint(); } }
def check(candidate): pass
12
public class Solution { /** Main game loop that updates the game state, moves the snake, checks for collisions, and renders the board continuously. Dependencies: - public void moveSnake(): Continuously moves the snake in the current direction and updates its position on the grid. - public void renderGameBoard(): Rende...
gameLoop
moveSnake(); repaint(); } }
def check(candidate): pass
13
public class Solution { /** Sets up the game by initializing the game board, paddle, bricks, ball, and score. Dependencies: - public void initializeGameBoard(): Creates the game board with a grid-based layout and defined dimensions. - public void setupPaddle(): Initializes the paddle at the bottom of the screen and se...
initializeGame
GameBoard board = new GameBoard(width, height, gridRows, gridColumns); drawGraphics(board, null, null, null, null, 0); return board; } }
def check(candidate): pass
14
public class Solution { /** Creates the game board with a grid-based layout and defined dimensions. Dependencies: - public void drawGraphics(): Renders the game board, paddle, ball, bricks, power-ups, and score on the screen. */ public GameBoard initializeGameBoard(int width, int height, int gridRows, int gridColu...
initializeGameBoard
Paddle p = new Paddle(startX, startY, paddleWidth, paddleHeight); handlePaddleInput(null); return p; } }
def check(candidate): pass
15
public class Solution { /** Initializes the paddle at the bottom of the screen and sets up control input. Dependencies: - public void handlePaddleInput(): Processes input events (keyboard or touch) to update the paddle's position. */ public Paddle setupPaddle(int startX, int startY, int paddleWidth, int paddleHeig...
setupPaddle
for (int col = 0; col < columns; col++) { int x = col * brickWidth; int y = row * brickHeight + 50; String type = assignBrickType(row, col); Color color = (type.equals("strong")) ? Color.RED : Color.ORANGE; brickList.add(new Brick(x, y, brickWidth - 2, brickHeight - 2, ty...
def check(candidate): pass
16
public class Solution { /** Generates a formation of bricks at the top of the screen with specified rows and columns. */ public List<Brick> createBricks(int rows, int columns) {
createBricks
for (int col = 0; col < columns; col++) { int x = col * brickWidth; int y = row * brickHeight + 50; String type = assignBrickType(row, col); Color color = (type.equals("strong")) ? Color.RED : Color.ORANGE; brickList.add(new Brick(x, y, brickWidth - 2, brickHeight - 2, ty...
def check(candidate): pass
17
public class Solution { /** Places the ball on the paddle at the beginning of the game. */ public Ball initializeBall(Paddle paddle) {
initializeBall
int radius = 8; int x = paddle.x + paddle.width / 2 - radius; int y = paddle.y - radius * 2; return new Ball(x, y, radius); } }
def check(candidate): pass
18
public class Solution { /** Starts the ball's movement, allowing the player to launch it from the paddle. */ public void launchBall(Ball ball) {
launchBall
if (!ballLaunched) { ball.dx = 2; ball.dy = -3; ballLaunched = true; } } }
def check(candidate): pass
19
public class Solution { /** Updates the ball's position based on physics and handles collisions. Dependencies: - public void handleWallCollision(): Handles ball collisions with the game board walls and adjusts its direction accordingly. - public void handlePaddleCollision(): Detects and handles the collision between t...
updateBallPosition
ball.x += ball.dx; ball.y += ball.dy; handleWallCollision(ball, gameBoard); handlePaddleCollision(ball, paddle); Optional<Brick> hitBrick = handleBrickCollision(ball, bricks); hitBrick.ifPresent(brick -> { removeBrick(brick, bricks); score = updateScore(br...
def check(candidate): pass
20
public class Solution { /** Detects collisions between the ball and paddle, bricks, and walls. Dependencies: - public void handlePaddleCollision(): Detects and handles the collision between the ball and the paddle. - public void handleBrickCollision(): Detects collisions between the ball and bricks, and processes bric...
handleCollisionDetection
CollisionResult result = new CollisionResult(); handlePaddleCollision(ball, paddle); Optional<Brick> brickCollision = handleBrickCollision(ball, bricks); brickCollision.ifPresent(b -> result.hitBrick = b); handleWallCollision(ball, gameBoard); return result; } }
def check(candidate): pass
21
public class Solution { /** Handles ball collisions with the game board walls and adjusts its direction accordingly. */ public void handleWallCollision(Ball ball, GameBoard gameBoard) {
handleWallCollision
if (ball.x <= 0 || ball.x + ball.radius * 2 >= gameBoard.width) { ball.dx = -ball.dx; } if (ball.y <= 0) { ball.dy = -ball.dy; } } }
def check(candidate): pass
22
public class Solution { /** Detects and handles the collision between the ball and the paddle. */ public void handlePaddleCollision(Ball ball, Paddle paddle) {
handlePaddleCollision
Rectangle ballRect = new Rectangle(ball.x, ball.y, ball.radius * 2, ball.radius * 2); Rectangle paddleRect = new Rectangle(paddle.x, paddle.y, paddle.width, paddle.height); if (ballRect.intersects(paddleRect)) { ball.dy = -Math.abs(ball.dy); int paddleCenter = paddle.x + paddle.w...
def check(candidate): pass
23
public class Solution { /** Detects collisions between the ball and bricks, and processes brick destruction, scoring, and power-up generation. Dependencies: - public void removeBrick(): Removes a brick from the game once it has been hit by the ball. - public void updateScore(): Updates the player's score based on the ...
handleBrickCollision
Rectangle ballRect = new Rectangle(ball.x, ball.y, ball.radius * 2, ball.radius * 2); for (Brick brick : new ArrayList<>(bricks)) { Rectangle brickRect = new Rectangle(brick.x, brick.y, brick.width, brick.height); if (ballRect.intersects(brickRect)) { ball.dy = -ball.dy; ...
def check(candidate): pass
24
public class Solution { /** Removes a brick from the game once it has been hit by the ball. */ public void removeBrick(Brick brick, List<Brick> bricks) {
removeBrick
// This method is called from paintComponent; implementation is in paintComponent. } }
def check(candidate): pass
25
public class Solution { /** Updates the player's score based on the type of brick destroyed. */ public int updateScore(String brickType) {
updateScore
int points = brickType.equals("strong") ? 20 : 10; score += points; return score; } }
def check(candidate): pass
26
public class Solution { /** Generates a power-up at the location of a destroyed brick if applicable. */ public Optional<PowerUp> generatePowerUps(Brick brick, Coordinate position) {
generatePowerUps
Random rand = new Random(); if (rand.nextFloat() < 0.2f) { String[] types = {"extraBall", "largerPaddle", "slowBall"}; String type = types[rand.nextInt(types.length)]; return Optional.of(new PowerUp(position.x, position.y, type)); } return Optional.empty(); } ...
def check(candidate): pass
27
public class Solution { /** Applies the effect of a collected power-up to the game. */ public void applyPowerUp(PowerUp powerUp, BrickBreakerGame game) {
applyPowerUp
switch (powerUp.type) { case "largerPaddle": updatePaddleSize(game.paddle, 20); break; case "extraBall": addExtraBall(); break; case "slowBall": slowBallSpeed(); break; default: break; } } }
def check(candidate): pass
28
public class Solution { /** Advances the game to the next level when conditions are met, creating a new brick formation. Dependencies: - public void createBricks(): Generates a formation of bricks at the top of the screen with specified rows and columns. */ public int updateGameLevel(int currentLevel, int bricksRe...
updateGameLevel
// The message will be displayed in paintComponent } }
def check(candidate): pass
29
public class Solution { /** Determines if the game is over (e.g., ball goes below the paddle) and triggers game over actions. Dependencies: - public void showGameOverMessage(): Displays a game over message along with the final score. - public void restartGame(): Resets the game to its initial state, allowing the playe...
checkGameOver
if (ball.y > gameBoard.height) { showGameOverMessage(score); restartGame(); return true; } return false; } }
def check(candidate): pass
30
public class Solution { /** Displays a game over message along with the final score. */ public void showGameOverMessage(int score) {
showGameOverMessage
// The message will be displayed in paintComponent } }
def check(candidate): pass
31
public class Solution { /** Resets the game to its initial state, allowing the player to start over. Dependencies: - public void initializeGame(): Sets up the game by initializing the game board, paddle, bricks, ball, and score. */ public void restartGame() {
restartGame
initializeGame(boardWidth, boardHeight, brickRows, brickColumns); } }
def check(candidate): pass
32
public class Solution { /** Renders the game board, paddle, ball, bricks, power-ups, and score on the screen. */ public void drawGraphics(GameBoard gameBoard, Paddle paddle, Ball ball, List<Brick> bricks, List<PowerUp> powerUps, int score) {
drawGraphics
// This method is called from paintComponent; implementation is in paintComponent. } }
def check(candidate): pass
33
public class Solution { /** Processes input events (keyboard or touch) to update the paddle's position. */ public Direction handlePaddleInput(InputEvent event) {
handlePaddleInput
// Not used directly; implementation in key event processing. return Direction.NONE; } }
def check(candidate): pass
34
public class Solution { /** Sets up the initial game state including bird, pipes, score, and starts the game loop. Dependencies: - public void createBird(): Creates and returns a new Bird object with default properties (position, speed, and appearance). - public void resetScore(): Resets the game score to zero. - publ...
initializeGame
bird = createBird(); resetScore(); pipes = spawnInitialPipes(); isGameOver = false; pipeSpawnTimer = 0; startGameLoop(); } }
def check(candidate): pass
35
public class Solution { /** Creates and returns a new Bird object with default properties (position, speed, and appearance). */ public void createBird() {
createBird
int birdSize = 30; Bird newBird = new Bird(100, HEIGHT/2 - birdSize/2, birdSize, birdSize, 0); return newBird; } }
def check(candidate): pass
36
public class Solution { /** Resets the game score to zero. */ public void resetScore() {
resetScore
score = 0; } }
def check(candidate): pass
37
public class Solution { /** Creates and returns a new Pipe object with a randomized gap height for the bird to pass through. */ public void spawnPipe() {
spawnPipe
int gapYMin = 50; int gapYMax = (int) (GROUND_Y - PIPE_GAP - 50); int gapY = gapYMin + (int)(Math.random() * (gapYMax - gapYMin + 1)); Pipe newPipe = new Pipe(WIDTH, gapY, PIPE_WIDTH, PIPE_GAP); return newPipe; } }
def check(candidate): pass
38
public class Solution { /** Generates the initial set of pipes for the game. Dependencies: - public void spawnPipe(): Creates and returns a new Pipe object with a randomized gap height for the bird to pass through. */ public void spawnInitialPipes() {
spawnInitialPipes
List<Pipe> initialPipes = new ArrayList<>(); int initialCount = 3; int spacing = 300; for (int i = 0; i < initialCount; i++) { Pipe pipe = spawnPipe(); pipe.x += i * spacing; initialPipes.add(pipe); } return initialPipes; } }
def check(candidate): pass
39
public class Solution { /** Updates the bird's position by applying gravity and integrating the elapsed time. */ public void updateBird(Bird bird, double deltaTime) {
updateBird
bird.velocity += GRAVITY * deltaTime; bird.y += bird.velocity * deltaTime; } }
def check(candidate): pass
40
public class Solution { /** Handles the left mouse click event to make the bird flap (jump). */ public void handleFlap(Bird bird) {
handleFlap
bird.velocity = FLAP_STRENGTH; } }
def check(candidate): pass
41
public class Solution { /** Updates the positions of all pipes and removes any that have moved off-screen. Dependencies: - public void removeOffScreenPipe(): Removes pipes from the list that have moved beyond the left side of the screen. */ public void updatePipes(List<Pipe> pipes, double deltaTime) {
updatePipes
for (Pipe pipe : pipes) { pipe.x -= PIPE_SPEED * deltaTime; } removeOffScreenPipe(pipes); } }
def check(candidate): pass
42
public class Solution { /** Removes pipes from the list that have moved beyond the left side of the screen. */ public void removeOffScreenPipe(List<Pipe> pipes) {
removeOffScreenPipe
Iterator<Pipe> it = pipes.iterator(); while(it.hasNext()){ Pipe pipe = it.next(); if(pipe.x + pipe.width < 0){ it.remove(); } } } }
def check(candidate): pass
43
public class Solution { /** Checks for collisions between the bird and pipes or between the bird and the ground. Dependencies: - public void pipeCollision(): Determines if the bird collides with a specific pipe. - public void groundCollision(): Determines if the bird has hit the ground. */ public void detectCollis...
detectCollisions
if(groundCollision(bird, groundY)){ return true; } for(Pipe pipe : pipes){ if(pipeCollision(bird, pipe)){ return true; } } return false; } }
def check(candidate): pass
44
public class Solution { /** Determines if the bird collides with a specific pipe. */ public void pipeCollision(Bird bird, Pipe pipe) {
pipeCollision
Rectangle birdRect = new Rectangle((int)bird.x, (int)bird.y, bird.width, bird.height); // Top pipe rectangle Rectangle topPipe = new Rectangle((int)pipe.x, 0, pipe.width, pipe.gapY); // Bottom pipe rectangle Rectangle bottomPipe = new Rectangle((int)pipe.x, pipe.gapY + pipe.gapHe...
def check(candidate): pass
45
public class Solution { /** Determines if the bird has hit the ground. */ public void groundCollision(Bird bird, double groundY) {
groundCollision
if(bird.y + bird.height >= groundY){ return true; } return false; } }
def check(candidate): pass
46
public class Solution { /** Increments the game score based on the distance traveled by the bird. */ public void incrementScore(int currentScore, int increment) {
incrementScore
// This function is integrated into the paintComponent method. repaint(); } }
def check(candidate): pass
47
public class Solution { /** Triggers the game over sequence, stopping the game loop and displaying a game over message. Dependencies: - public void displayGameOverMessage(): Displays a game over message on the screen. - public void stopGameLoop(): Stops the main game loop to end the game. */ public void gameOver()...
gameOver
displayGameOverMessage(); stopGameLoop(); isGameOver = true; } }
def check(candidate): pass
48
public class Solution { /** Displays a game over message on the screen. */ public void displayGameOverMessage() {
displayGameOverMessage
// This will be handled in the render method (drawString) } }
def check(candidate): pass
49
public class Solution { /** Stops the main game loop to end the game. */ public void stopGameLoop() {
stopGameLoop
if(gameTimer != null){ gameTimer.stop(); } } }
def check(candidate): pass
50
public class Solution { /** Resets the game state and starts a new game after a game over. Dependencies: - public void initializeGame(): Sets up the initial game state including bird, pipes, score, and starts the game loop. */ public void restartGame() {
restartGame
initializeGame(); } }
def check(candidate): pass
51
public class Solution { /** Renders all game elements including the bird, pipes, ground, and score on the screen. Dependencies: - public void drawBird(): Renders the bird on the screen. - public void drawPipes(): Renders all pipes on the screen. - public void drawGround(): Renders the ground or background on the scree...
renderGame
// This function is integrated into the paintComponent method. repaint(); } }
def check(candidate): pass
52
public class Solution { /** Renders the bird on the screen. */ public void drawBird(Bird bird) {
drawBird
g.setColor(Color.yellow); g.fillOval((int)bird.x, (int)bird.y, bird.width, bird.height); } }
def check(candidate): pass
53
public class Solution { /** Renders all pipes on the screen. */ public void drawPipes(List<Pipe> pipes) {
drawPipes
g.setColor(Color.green.darker()); for(Pipe pipe : pipes) { // Top pipe g.fillRect((int)pipe.x, 0, pipe.width, pipe.gapY); // Bottom pipe g.fillRect((int)pipe.x, pipe.gapY + pipe.gapHeight, pipe.width, (int)(GROUND_Y - (pipe.gapY + pipe.gapHeight))); } } }
def check(candidate): pass
54
public class Solution { /** Renders the ground or background on the screen. */ public void drawGround(double groundY) {
drawGround
g.setColor(new Color(222, 184, 135)); g.fillRect(0, (int)groundY, WIDTH, HEIGHT - (int)groundY); } }
def check(candidate): pass
55
public class Solution { /** Displays the current score on the screen. */ public void drawScore(int score) {
drawScore
g.setColor(Color.white); g.setFont(new Font("Arial", Font.BOLD, 24)); g.drawString("Score: " + score, 10, 30); } }
def check(candidate): pass
56
public class Solution { /** Starts the main game loop that continuously updates game state and renders the game. Dependencies: - public void updateBird(): Updates the bird's position by applying gravity and integrating the elapsed time. - public void updatePipes(): Updates the positions of all pipes and removes any th...
startGameLoop
lastTime = System.nanoTime(); gameTimer = new Timer(TIMER_DELAY, this); gameTimer.start(); } }
def check(candidate): pass
57
public class Solution { /** Initializes the game state including the game board, tanks, obstacles, score, and rendering. Dependencies: - public void createBoard(): Creates a grid-based game board with specified dimensions. - public void initializeTanks(): Places two tanks on the game board with initial positions and s...
initializeGame
board = createBoard(15, 20); tanks = initializeTanks(board); obstacles = createObstacles(board); projectiles.clear(); resetScore(); renderGame(); } }
def check(candidate): pass
58
public class Solution { /** Creates a grid-based game board with specified dimensions. */ public Board createBoard(int rows, int columns) {
createBoard
for (int j = 3; j < board.columns - 3; j += 4) { obsList.add(new Obstacle(new Position(i, j))); } } }
def check(candidate): pass
59
public class Solution { /** Renders the game board on the screen. */ public void displayBoard(Board board) {
displayBoard
gamePanel.repaint(); } }
def check(candidate): pass
60
public class Solution { /** Places two tanks on the game board with initial positions and sets up player controls. */ public List<Tank> initializeTanks(Board board) {
initializeTanks
List<Tank> tankList = new ArrayList<>(); Tank tank1 = new Tank(new Position(1, 1), Color.GREEN, 100, "Player1"); Tank tank2 = new Tank(new Position(board.rows - 2, board.columns - 2), Color.RED, 100, "Player2"); tankList.add(tank1); tankList.add(tank2); return tankList; ...
def check(candidate): pass
61
public class Solution { /** Generates obstacles strategically on the game board. */ public List<Obstacle> createObstacles(Board board) {
createObstacles
List<Obstacle> obsList = new ArrayList<>(); for (int i = 3; i < board.rows - 3; i += 3) { for (int j = 3; j < board.columns - 3; j += 4) { obsList.add(new Obstacle(new Position(i, j))); } } return obsList; } }
def check(candidate): pass
62
public class Solution { /** Resets the game score at the start of the game. */ public void resetScore() {
resetScore
score = 0; } }
def check(candidate): pass
63
public class Solution { /** Processes keyboard input to control tank movement and firing actions. Dependencies: - public void moveTank(): Moves a tank in the specified direction if no collision with obstacles occurs. - public void fireProjectile(): Fires a projectile from the tank's current position if allowed by the ...
handleKeyPress
int key = event.getKeyCode(); // Player1 controls: W, A, S, D and F to fire Tank tank1 = tanks.get(0); // Player2 controls: Arrow Keys and Space to fire Tank tank2 = tanks.get(1); switch (key) { case KeyEvent.VK_W: moveTank(tank1, Direction.UP); br...
def check(candidate): pass
64
public class Solution { /** Moves a tank in the specified direction if no collision with obstacles occurs. Dependencies: - public void checkCollisionWithObstacles(): Checks if a tank collides with any obstacles on the game board. */ public boolean moveTank(Tank tank, Direction direction) {
moveTank
Position newPos = new Position(tank.position.row, tank.position.col); switch (direction) { case UP: newPos.row -= 1; break; case DOWN: newPos.row += 1; break; case LEFT: newPos.col -= 1; break; case RIGHT: newPos.col...
def check(candidate): pass
65
public class Solution { /** Checks if a tank collides with any obstacles on the game board. */ public boolean checkCollisionWithObstacles(Tank tank, List<Obstacle> obstacles) {
checkCollisionWithObstacles
for (Obstacle obs : obstacles) { if (tank.position.equals(obs.position)) { return true; } } return false; } }
def check(candidate): pass
66
public class Solution { /** Fires a projectile from the tank's current position if allowed by the firing rate limit. Dependencies: - public void limitFiringRate(): Determines if the tank is allowed to fire based on time constraints. - public void displayProjectile(): Renders the projectile on the screen. */ public...
fireProjectile
if (!limitFiringRate(tank)) { return null; } Position projPos = new Position(tank.position.row, tank.position.col); Projectile proj = new Projectile(projPos, tank.lastDirection, tank); tank.lastFiredTime = System.currentTimeMillis(); return proj; } }
def check(candidate): pass
67
public class Solution { /** Determines if the tank is allowed to fire based on time constraints. */ public boolean limitFiringRate(Tank tank) {
limitFiringRate
long currentTime = System.currentTimeMillis(); return (currentTime - tank.lastFiredTime) >= 500; } }
def check(candidate): pass
68
public class Solution { /** Renders the projectile on the screen. */ public void displayProjectile(Projectile projectile) {
displayProjectile
projectiles.add(projectile); } }
def check(candidate): pass
69
public class Solution { /** Updates positions of all active projectiles and detects collisions. Dependencies: - public void detectProjectileCollision(): Detects collisions between a projectile and tanks or obstacles. */ public void updateProjectiles() {
updateProjectiles
List<Projectile> toRemove = new ArrayList<>(); for (Projectile proj : projectiles) { proj.updatePosition(); CollisionResult result = detectProjectileCollision(proj); if (result.collision) { if (result.tank != null) { applyDamage(result.tank, 20); if (resul...
def check(candidate): pass
70
public class Solution { /** Detects collisions between a projectile and tanks or obstacles. Dependencies: - public void applyDamage(): Applies damage to a tank when hit by a projectile. - public void removeProjectile(): Removes a projectile from play after collision or when it goes off-screen. */ public CollisionR...
detectProjectileCollision
CollisionResult result = new CollisionResult(); for (Tank t : tanks) { if (!t.equals(projectile.owner) && t.position.equals(projectile.position)) { result.collision = true; result.tank = t; return result; } } for (Obstacle obs : obstacles) { ...
def check(candidate): pass
71
public class Solution { /** Applies damage to a tank when hit by a projectile. */ public void applyDamage(Tank tank, int damage) {
applyDamage
tank.health -= damage; if(tank.health < 0) { tank.health = 0; } } }
def check(candidate): pass
72
public class Solution { /** Removes a projectile from play after collision or when it goes off-screen. */ public void removeProjectile(Projectile projectile) {
removeProjectile
projectiles.remove(projectile); } }
def check(candidate): pass
73
public class Solution { /** Updates the health bar display for all tanks. */ public void updateHealthBars() {
updateHealthBars
// Health bars are rendered in GamePanel, so just trigger repaint. gamePanel.repaint(); } }
def check(candidate): pass
74
public class Solution { /** Displays an explosion animation at the given position. */ public void displayExplosion(Position position) {
displayExplosion
Graphics g = gamePanel.getGraphics(); if (g != null) { g.setColor(Color.ORANGE); int cellWidth = board.getCellWidth(gamePanel.getWidth()); int cellHeight = board.getCellHeight(gamePanel.getHeight()); int x = position.col * cellWidth; int y = position.row * cellHei...
def check(candidate): pass
75
public class Solution { /** Updates the score when a tank is destroyed. */ public void updateScore(Tank tank) {
updateScore
score += 100; } }
def check(candidate): pass
76
public class Solution { /** Checks if any tank's health has reached zero to trigger game over. Dependencies: - public void displayGameOver(): Displays a game over message on the screen. */ public boolean checkGameOver() {
checkGameOver
for (Tank t : tanks) { if (t.health <= 0) { return true; } } return false; } }
def check(candidate): pass
77
public class Solution { /** Displays a game over message on the screen. */ public void displayGameOver() {
displayGameOver
JOptionPane.showMessageDialog(this, "Game Over! Press R to restart."); } }
def check(candidate): pass
78
public class Solution { /** Resets the game state to allow players to start a new game. Dependencies: - public void initializeGame(): Initializes the game state including the game board, tanks, obstacles, score, and rendering. */ public void restartGame() {
restartGame
initializeGame(); gameTimer.restart(); } }
def check(candidate): pass
79
public class Solution { /** Renders all game elements including the board, tanks, projectiles, obstacles, health bars, and score. Dependencies: - public void displayBoard(): Renders the game board on the screen. - public void updateHealthBars(): Updates the health bar display for all tanks. - public void updateScore()...
renderGame
displayBoard(board); updateHealthBars(); gamePanel.repaint(); } }
def check(candidate): pass
80
public class Solution { /** Initializes the game state including the game board and current player. Dependencies: - public void createGameBoard(): Creates a 15x15 grid representing the Caro game board and initializes each cell as empty. - public void resetGameState(): Resets game state variables such as board occupanc...
initializeGame
GameState gameState = new GameState(); gameState.board = createGameBoard(); resetGameState(); gameState.currentPlayer = 'X'; return gameState; } }
def check(candidate): pass
81
public class Solution { /** Creates a 15x15 grid representing the Caro game board and initializes each cell as empty. */ public char[][] createGameBoard() {
createGameBoard
char[][] board = new char[BOARD_SIZE][BOARD_SIZE]; for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { board[i][j] = '.'; } } return board; } }
def check(candidate): pass
82
public class Solution { /** Resets game state variables such as board occupancy and turn count. */ public void resetGameState() {
resetGameState
// In this implementation, resetGameState doesn't need to do extra work // as the board is reinitialized in createGameBoard and currentPlayer is set in initializeGame. } }
def check(candidate): pass
83
public class Solution { /** Displays the current state of the game board on the console or GUI. */ public void displayGameBoard(char[][] board) {
displayGameBoard
System.out.print(" "); for (int i = 0; i < BOARD_SIZE; i++) { System.out.printf("%2d ", i); } System.out.println(); for (int i = 0; i < BOARD_SIZE; i++) { System.out.printf("%2d ", i); for (int j = 0; j < BOARD_SIZE; j++) { System.out.print(" " +...
def check(candidate): pass
84
public class Solution { /** Handles input for a player's move and returns valid move coordinates. Dependencies: - public void validateMove(): Validates the move ensuring the selected cell is within bounds and empty. */ public int[] handlePlayerInput(char currentPlayer, char[][] board) {
handlePlayerInput
if (row < 0 || row >= BOARD_SIZE || col < 0 || col >= BOARD_SIZE) { return false; } return board[row][col] == '.'; } }
def check(candidate): pass
85
public class Solution { /** Validates the move ensuring the selected cell is within bounds and empty. */ public boolean validateMove(char[][] board, int row, int col) {
validateMove
if (row < 0 || row >= BOARD_SIZE || col < 0 || col >= BOARD_SIZE) { return false; } return board[row][col] == '.'; } }
def check(candidate): pass
86
public class Solution { /** Updates the game board with the player's move at the specified position. */ public void updateBoard(char[][] board, int row, int col, char playerMark) {
updateBoard
board[row][col] = playerMark; } }
def check(candidate): pass
87
public class Solution { /** Checks if placing a mark at the given position results in a win by achieving five consecutive marks in any direction. Dependencies: - public void countMarksInDirection(): Counts consecutive marks of the same player in a specified direction starting from the given cell. */ public boolean...
checkWinCondition
int[][] directions = { {0, 1}, {1, 0}, {1, 1}, {1, -1} }; for (int[] dir : directions) { int count = countMarksInDirection(board, row, col, dir[0], dir[1], playerMark) + countMarksInDirection(board, row, col, -dir[0], -dir[1], playerMark) - 1; if (count >= 5) { return tru...
def check(candidate): pass
88
public class Solution { /** Counts consecutive marks of the same player in a specified direction starting from the given cell. */ public int countMarksInDirection(char[][] board, int row, int col, int deltaRow, int deltaCol, char playerMark) {
countMarksInDirection
int count = 0; int r = row, c = col; while (r >= 0 && r < BOARD_SIZE && c >= 0 && c < BOARD_SIZE && board[r][c] == playerMark) { count++; r += deltaRow; c += deltaCol; } return count; } }
def check(candidate): pass
89
public class Solution { /** Determines if the game is a draw by checking if the board is completely filled. */ public boolean checkDraw(char[][] board) {
checkDraw
for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { if (board[i][j] == '.') { return false; } } } return true; } }
def check(candidate): pass
90
public class Solution { /** Switches the current player turn from one mark to the other. */ public char switchPlayer(char currentPlayer) {
switchPlayer
return currentPlayer == 'X' ? 'O' : 'X'; } }
def check(candidate): pass
91
public class Solution { /** Prompts the user for confirmation before executing actions such as restart or exit. */ public boolean confirmAction(String actionType) {
confirmAction
System.out.print("Do you want to " + actionType + "? (Y/N): "); String input = scanner.nextLine().trim(); return input.equalsIgnoreCase("Y"); } }
def check(candidate): pass
92
public class Solution { /** Restarts the game by reinitializing the game state. Dependencies: - public void initializeGame(): Initializes the game state including the game board and current player. */ public void restartGame() {
restartGame
GameState newState = initializeGame(); startGame(newState); } }
def check(candidate): pass
93
public class Solution { /** Exits the game application. */ public void exitGame() {
exitGame
System.out.println("Exiting game. Goodbye!"); System.exit(0); } }
def check(candidate): pass
94
public class Solution { /** Main game loop that manages turn-taking, input handling, board updating, win/draw detection, and game restart/exit options. Dependencies: - public void initializeGame(): Initializes the game state including the game board and current player. - public void displayGameBoard(): Displays the cu...
startGame
GameState newState = initializeGame(); startGame(newState); } }
def check(candidate): pass
95
public class Solution { /** Initializes the application by loading tasks from file and setting up the user interface. Dependencies: - public void loadTasks(): Loads tasks from a file (JSON or CSV) into the application's task list. - public void initializeUI(): Initializes the user interface by displaying the main menu...
initializeApp
tasks = loadTasks(); if (!tasks.isEmpty()) { for (Task t : tasks) { if (t.getId() >= currentId) { currentId = t.getId() + 1; } } } initializeUI(); } }
def check(candidate): pass
96
public class Solution { /** Loads tasks from a file (JSON or CSV) into the application's task list. Dependencies: - public void readFromFile(): Reads data from a file and returns the content. */ public void loadTasks() {
loadTasks
List<Task> loadedTasks = new ArrayList<>(); String fileContent = readFromFile(FILE_PATH); if (fileContent != null && !fileContent.isEmpty()) { String[] lines = fileContent.split(" "); for (String line : lines) { Task task = Task.fromCSV(line.trim()); if(ta...
def check(candidate): pass
97
public class Solution { /** Saves the current task list to a file (JSON or CSV). Dependencies: - public void writeToFile(): Writes data to a file. */ public void saveTasks(List<Task> tasks) {
saveTasks
StringBuilder sb = new StringBuilder(); for (Task task : tasks) { sb.append(task.toCSV()).append(" "); } return writeToFile(FILE_PATH, sb.toString()); } }
def check(candidate): pass
98
public class Solution { /** Initializes the user interface by displaying the main menu and task list. Dependencies: - public void displayMenu(): Displays the user interface menu with options to add, edit, delete, mark as completed, and filter tasks. - public void displayTaskList(): Displays the list of tasks in a read...
initializeUI
boolean exit = false; while (!exit) { displayMenu(); String option = scanner.nextLine(); switch(option) { case "1": // Add Task System.out.print("Enter task name: "); String name = scanner.nextLine(); System.out.print("Is task completed? (t...
def check(candidate): pass
99
public class Solution { /** Displays the user interface menu with options to add, edit, delete, mark as completed, and filter tasks. */ public void displayMenu() {
displayMenu
System.out.println(" --- To-Do List App Menu ---"); System.out.println("1. Add Task"); System.out.println("2. Edit Task"); System.out.println("3. Delete Task"); System.out.println("4. Mark Task as Completed (Toggle)"); System.out.println("5. Filter Tasks by Catego...
def check(candidate): pass
100
public class Solution { /** Displays the list of tasks in a readable format including task name, status, and category. */ public void displayTaskList(List<Task> tasks) {
displayTaskList
System.out.println(" --- Task List ---"); if(tasks.isEmpty()) { System.out.println("No tasks available."); return; } for (Task task : tasks) { System.out.println(task.toString()); } } }
def check(candidate): pass
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
3