How to write an algorithm for a horse's movement on a 32 square array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • subsperm
    New Member
    • Jan 2011
    • 2

    #1

    How to write an algorithm for a horse's movement on a 32 square array?

    I have read a bit of codes from Sircool and DC a.
    Sircool wrote his codes in a Turkish language. While 'DC a' wrote something that is logically sensible: I noticed that it doesn't build and run well in CODE:BLOCKS. I just hope that someone will guide me in the right direction here.
    ---------------------------------------------------------
    Code:
    //Main.cpp: 'DC a' defines the entry point for the console application
    
    int solve (int chess_board[][], int last_col, int last_row, int count)
    {
        if (count == 64)
        {
    //print the entire chess board;
    //stopping cas
        }
        // up 2, left 1 case
        if((last_row > 1) && (last_col > 0))
        {
            if(chess_board[last_col-1] [last_row-2] == 0) // not occupied
            {
    chess_board[last_col-1] [last_row-2] = count;
    solve(&chess_board, last_col, last_row-2, count=1);
    chess_board[last_col-1] [last_row-2] = 0
            }
        }
        //similarly for the other seven possibilities
    }
    
    int main ()
    {
        for each row (0 - 7)
        {
            for each col (0 - 7)
            {
      chess_board[col] [row] = 1
      solve (&chess_board, col, row, 1);
      chess_board[row] [col] = 0;
            }
        }
       system ("PAUSE");
       return EXIT_SUCESS;
    }
    Last edited by Niheel; Jan 21 '11, 03:38 PM. Reason: added code tags to code
  • subsperm
    New Member
    • Jan 2011
    • 2

    #2
    This is so precise. I think I have a lot to learn here. Thanks to the moderator.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      That would be because it is PSEUDO code, if you want to compile it you will need to re-write it in C (or C++).

      PSEUDO code is a way of describing the logical steps a program needs to take without actually conforming to the syntax of a specific language.

      Comment

      Working...