make an object move from one space to another in a grid

I have a two dimensional grid of spaces.
Each space is either empty (unoccupied) or it's occupied by an object.
An object gets a random number of moves ,when it is its turn to move.
The object can only move to a unoccu
pied space.
An object can only move , to the space in front of it (straight ahead), diagonally to right or diagonally to left.
Each move straight ahead counts as 1 move.
Each move diagonally right or left counts as 2 moves.
The moving object must move to the farthest space it can get to with the number of moves it has.
If all the spaces straight ahead are unoccupied
,the object would move straight ahead the full number of moves it has.
How do i get the object to check each space ,one after another, to see if they are unoccupied and determine which space is the farthest one the object can move to.


I would create a class Grid that encapsulates a two dimensional array of objects.
Each objects stores it's location(row and col) and a reference to the Grid.

Lets say the object you are interested in is on row 5 and col 5. It's easy tho check if the adjacent cells are empty or not.
Topic archived. No new replies allowed.