algorithm to find overlaps

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-03-20T06:50:26Z Indexed on 2010/03/20 7:01 UTC
Read the original article Hit count: 332

Filed under:
|
|
|

Hey,

Basically I've got some structs of type Ship which are going to go on a board which can have a variable width and height. The information about the ships is read in from a file, and I just need to know the best way to make sure that none of the ships overlap.

Here is the structure of Ship:

int x // x position of first part of ship
int y // y position of first part of ship
char dir // direction of the ship, either 'N','S','E' or 'W'
int length // length of the ship

Also, what would be a good way to handle the directions. Something cleaner than using a switch statement and using a different condition for each direction.

Any help would be greatly appreciated!

© Stack Overflow or respective owner

Related posts about c

    Related posts about structs