Thread: Need help w/ Chess-like program assignment!!!

  1. #1
    Unregistered
    Guest

    Need help w/ Chess-like program assignment!!!

    I have an assignment due for a C class which utilizes an array of [5][5] with an initial starting point of [2][2]. You begin with a figure located in the cell, [2][2] of the array. The object is to generate a random number (using the rand () function) and add this number to the initial array position, thus moving the object to a new location on the array board (similar to chess). You must then loop this function over again until the object falls outside the scope of the array. Once outside the scope, the process begins once again (for 1000 loops) and then the averages of the objects presence on each cell, and the average number of steps that it took the object to fall off, are to be printed to screen in table format.

    HEELLLPPPP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Where in the hell do I begin?

    So far I have the rand () function written and understand the "human" logic behind it, but have no earthly idea how to translate into C language.

    Can you help me?

  2. #2
    Unregistered
    Guest
    This is an easy one. Break it down into steps.

    1) You need a 5x5 array. Ok, make one:

    char array[5][5];

    2) Set all the values to "empty".

    for(x=0;x<5;x++)for(y=0;y<5;y++)array[x][y]=0;

    3) Pick a starting point.

    array[2][2] = 1;

    Ok, now that is marked as used because it is not zero.

    4) Move a direction. There are only four. Use rand() for this.

    If a cell is picked as a direction, you cannot move there (or maybe you can, this depends on if it is allowed by your teacher). If it is not used, then you can move there. Update your current coordinates.

    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Programming Assignment
    By JHaney in forum C++ Programming
    Replies: 18
    Last Post: 11-08-2005, 03:45 AM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM