A knight can move 8 possible ways, so you need 3 bits to encode a movement.
To convert these 3 bits into relative motion on a board, define integer board coordinates, then use a lookup table of (delta x, delta y) pairs to store the coordinate change of each possible move. All the elements of these pairs are +-1 and +-2. The current board position of a piece is just an (x,y) coordinate. One such pair is enough for a single knight. On Mar 24, 8:49 am, snehal jain <learner....@gmail.com> wrote: > Design a data structure to represent the movement of a knight on a > chess board. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.