id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2024_08_29_HL_knightMoves
prev  |  next  |  chance

Write a method that returns how many options there are for a knight to move on an otherwise EMPTY chess board, given the knight's starting position on that chess board. The knight is the only piece on the board! A chess board consists of an 8 by 8 grid of squares. We will number the rows 1 through 8 and the columns 1 through 8. So (5,2) would indicate the square in row 5, column 2. Knights move in a very specific way. They go 1 square in one direction, then 2 squares in a perpendicular direction. For example, if a knight is located at (5,2) it could move to any of these squares: (3,1), (3,3), (4,4), (6,4), (7,1), (7,3). There are no other squares it could move to. At most there are 8 squares a knight could move to. In the example above, there were 6 possible squares the knight could move to. On an empty chess board there will always be at least 2 places for the knight to move. Your goal is to return the correct number of squares the knight could possibly move to, given the starting position of the knight. As always, look at the test data for examples.


test2024_08_29_HL_knightMoves(3, 2) → 6
test2024_08_29_HL_knightMoves(3, 3) → 8
test2024_08_29_HL_knightMoves(3, 4) → 8

...Save, Compile, Run (ctrl-enter)

public int test2024_08_29_HL_knightMoves(int row, int col) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 270

Copyright Nick Parlante 2017 - privacy