G
G
Gagatyn2016-10-23 15:59:14
Programming
Gagatyn, 2016-10-23 15:59:14

Knight's move in C++?

I don't know where to start writing a "knight's move" program. The matrix is ​​3 by 3, the elements are numbered from 1 to 9, at the end you need to indicate which numbers the horse went to,. At first I thought that the sum i+j should always be equal in the course of 1->2->3->(6) and so on with all the variations. Then I thought, even and not even. Added the values ​​themselves and also checked for parity. There is a pattern between sums and parity, so what, I can't use it. I can’t figure out how to get to a cell/element that is 3 steps forward/backward and 1 to the right/left (to get to the original element, you need to overcome 6 elements horizontally/vertically). What to do? How does it work with arrays?

for (i=0 i<3 i++){
    for (j=0 j<3 j++){ 
     n++;       
     if(n==6)
       mmr += a[i][j];
   }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AtomKrieg, 2016-10-23
@AtomKrieg

evrikak.ru/wp-content/uploads/2014/08/hody_konya.gif
sort through all options from the image (nx = x+2; ny = y+1... nx = nx+2; ny = ny-1). All values ​​nx, ny that fall out of the range [0-2;0-2] do not print
. Sports programming is what it is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question