|
-
May 25th, 2008, 12:53 PM
#6
Re: battleship in c++
Were it me, I'd simply hold a 2D array of 0s, and then put a row of 5 1s to represent a battleship, 2 2s to represent a patrol boat, etc.
Testing a location simply looks up the index there, and increments the hit count on the hit vessel (if any). Once a vessel takes enough hits it is destroyed.
Of course, you'd need to reject previously guessed positions first for this to work. Maybe use the sign bit to do that (since it doesn't matter if a 0 position is guessed twice).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|