how to move and print squares visited by a knight in following order?
Posted
by josh kant
on Stack Overflow
See other posts from Stack Overflow
or by josh kant
Published on 2010-04-01T01:11:16Z
Indexed on
2010/04/01
1:13 UTC
Read the original article
Hit count: 405
c++
Lets say you have a 5/5 board and you place and the knight started moving form the middle square. Every time knight moves it has to follow the following pattern. its easy if you draw what i mean. I am trying to code for the possible moves and print out the no. of moves in the nXn (in this case 5X5) board. The print out should be the no. of order in which the knight moved. { //move 1 //2 squares up and 1 to the left
//move 2 //2 squares up and 1 to the right
//move 3 //1 square up and 2 to the right
//move 4 //1 square down and 2 to the right
//move 5 //2 squares down and 1 to the right
//move 6 //2 squares down and 1 to the left
//move 7 //1 square down and 2 to the left
//move 8 //one square up and 2 to the left }
Any help would be appreciated. Thank you in advance..
© Stack Overflow or respective owner