A Battleship game that has a five by five playing board and has to save the highest score and display it at the begenning of the game

Posted on 2005-05-15
Medium Priority
Last Modified: 2013-12-04
---->Sorry I never asked you my question, like I was saying before my problem is probably so easy for you experts that i'm embarassed to ask BUT...I'm not sure how to  do a coulple things, one is the positioning of the ships on a playing board using an array, and then tellling the opponent the ship has been HIT --->(how will the program know that a ship was hit)<---, AND i'm having trouble figuring out what to use to save the highest score and displaying it at the begining of the game at the top  --->I'm just learing the basics of programming and I haven't put all the puzzel pieces together to write this simple program ---->Please Help me out as much as you can<------        Thank you     ----> GOOD FOR 500 Points<------
Question by:supermotoxxx23
  • 6
  • 3
LVL 25

Expert Comment

ID: 14006927

firstly: no question is stupid; it's only stupid not to ask the question.

Anyways, onto it: I'm not sure if you've already posted a question related to this previously, but either way, I need to know a few things: what programming language are you using? What problems are you having so far?


Expert Comment

ID: 14007148
I am going to try to sneak in for the points by answering this question in very general concepts that apply to all programming languages.

I am assuming you already have your multidimensional array set up, and that you are able to assign the position of each ship to that array. With that, all you need to do is detect whether a ship is hit. Do not be afraid to create another array. What I mean is you have the one array that holds the ships positions; so create another to hold the status of each ship. I am just throwing in these ideas because there are three ways I can think of to do this:

1. Each ship has its own array for position and another array for the status for each section of the ship      
2. The board is a big 2D array that has True of False for each little location of the board for every piece, and each ship has its own array for whether each section is hit or still alive (true or false)
3. The board is a big 2D array that has the value of 0, 1, or 2 for each little location on the board for every piece. 0 meaning the ship is not there, 1 meaning the ship is there and alive, and 2 meaning the ship is there, but down.

In any case (I recommend #3) you should have noted in some variable the start and end of each ship so you can say "You sunk my battleship!".

As for the top score thing: I don't see how you plan to have a scoring system on Battleship. Isn't that a win or lose game? Anyway... You are going to have to learn to save text (or other) files to the hard drive. But that can often be an ugly chunk of code in the programming languages I've studied. Best not to get in to that if you are a beginner. Good luck. Hope you can solve your problem.

I would also like to add: sorry for trying to steal points from your question InteractiveMind.  LOL, I have like 0, so I'm point hunting.

Expert Comment

ID: 14007169
LOL that doesn’t make any sense... Pay no attention to the second block of sentences where there are errors in grammar.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Accepted Solution

mathbiol earned 1000 total points
ID: 14007403

I can't find any other questions or comments posted previously by you -- so I don't understand either why you say
>like I was saying before

But anyway,  I think the best way to help you is to give you guidance as Sid did without writing code.  So I don't think we need to know what your programming language is.

I have played battleship with pencil and paper.  The way I was taught to play is a little different than the way Sid plays.  In my version, you are not told when you have sunk a ship.  Suppose the ships are laid out like this:

  A B C D etc.
1 x x x
2     x
3     x
4     x
5     x

Looking at this, we don't know whether we have sunk the 2-square ship and the 5-square ship, or we have sunk the 3-square and the 4-square ships.  We can only determine this by process of elimination, after finding some more ships.

Notice that in my version that if the player starts out guessing, in the example, "A-1", then guesses "A-2", and then "A-3", all he knows is that those squares are occupied.  He doesn't get told that the ship is sunk.  So he has to use another turn to guess "A-4".  (He wouldn't have to in Sid's version.)

My version is easy to program.  You can use Sid's #3 approach, with a simplification: each element in the two-dimensional array is either "occupied" or "not occupied".

By the way, even though it's a little more typing, I recommend that you not use the slightlycryptic values of 0 and 1 in your implementation.  If the 2-d array is an array of booleans named something suggestive like
then you'll have values of true and false.  The program will be easier to develop that way in my opinion.

So in my version you don't need to know where each ship starts and ends.

If the player guesses "6-C", you just check the appropriate element of the 2-d array.  If it's occupied, you tell him he got a hit, or display an X in the appropriate place on the screen.

You didn't ask about how to come up with the (random?) layout of ships.  Maybe that part is already clear to you.

Regarding scoring: when I have played Battleship with pencil and paper, player A would make a guess, then player B would make a guess.  They would continue alternating.  Whoever found all the ships first won.  But as a solitaire, I would guess that the "score" would keep track of how many guesses were required to find all the ships.  In this sort of score, lower is better.  So we would want to display the lowest score at the top.

I can think of two ways to display the best score at the top:
1. After a game has been played, write the score to a file (assuming it is better than the best-score-so-far that was stored in that file).
2. Don't close the program after the game has been played.  In other words, the code that plays the game will be inside a while loop.  As long as the player keeps saying, "yes, I want to play again," the program keeps looping.  Then you can save the best-score-so-far in a variable.  Initialize it to some very high number before the while-loop.  At the end of the while-loop:
   if score better than best-score-so-far
      let best-score-so-far = score

Good luck with your program.  You're right, there are lots of pieces to put together.  Ask some more questions when you're ready.


Assisted Solution

Sid_The_Kid earned 1000 total points
ID: 14007850
Come on supermotoxxx23, tell us your programming language so that the real battle can begin. As for Mathbiol, what supermotoxxx23 meant by "as I was saying" is what was said in the title of this question (as I interpeted it). Thanks for suggesting a possible scoring system. supermotoxxx23, if you do use that scoring system, there are a few flaws:

1. Some games will be easyer than others because of randomness and of smart people who can read minds and stuff
2. Once you have a perfect score, there is no going higher. So it destroys the point of playing on
3. The scoring system is boring

I have no idea what scoring system you are going to use, or if you are ever going to read this, supermotoxxx23. But I am going to suggest a new scoring system because I really need points.

My friends and I play a game called Halo PC. In this game, we take turns fighting other people online, and then we keep track of the scores to see who is better. But since some games are longer than others, and some have more players, we needed a scoring system. So I created a program on Visual Basic 6. The new scoring system is as follows:

grade = 10 * (OwnScore + assists / 2) / (deaths + 1) + OwnScore - (score1 + score2 + score3) / 3

This has no use to you, but it is a good template to use because it has a few things that no scoring system should be without.

-It compares you to other players
-It takes into account your deaths (or for your purposes misses)
-It includes miscellaneous data: assists (of for your purposes the length of the game)
-You want the score to be high (high score)
-It multiplies the score to make it a big number! -- Make sure your scores to not turn out negative or as decimals, and add excitement. The higher the score, the more excitement in winning. I would go for 25000 times the original score... even though my Halo score calculator does not (smaller numbers are easier to deal with).

Here is where we start:
1. When you win, divide your hits by the number of the opponents hits. This will generate a number greater than 0, but the less you get hit, the higher your score
2. Divide that score by the amount of minutes you played for times your amount of misses
3. Multiply that number by 25000 (ok... You may want to settle for 15000)
-Keep track of more than one score and all the names. It is always good to see yourself compared to others.

In the end you will have this equation:

Score = 25000 * (YourHits / OppHits + 1) / ((TimeOfGame * YourMisses) + 1 )

The +1's is to avoid division by 0.

I think the best way would be not to take this equation as it is, but to move some numbers around because there are a lot of different ways to do this.

Ok, now reply to your own question so I can continue my point hunting!

Expert Comment

ID: 14021730

Expert Comment

ID: 14023021
What does WOOT mean?

Expert Comment

ID: 14024279
There is a long history behind the word: W00T. It is both an acronym standing for many different terms, and an expression of happyness.

Woot can stand for the following:
-We Owned the Other Team
-Want One Of Those
-Waste Of Our Time
-Wonderful Loot (Everquest gaming slang)

And there is a legend that says in one of the first games around, there was a boss the sait "woot woot" whenever he killed you (from what I've heard). But internet slang is becoming more and more popular, and woot is one of those abstact terms. It is something you say when you feel like cheering. It is the modern day version of "yaaaahoooo!" It is most comonly used by people of younger ages, and those who play games on the internet.

There is no real definition of woot. Its definition changes as much as it is used. But one thing I can tell you, is that this particualr use of it did have meaning: Thankyou. Thanks for requesting the assist, I was happy to recieve the "nice assist" message even though I didn't get the points I was so searching for. At least I got the 1000 expert points, and yet another question answer on my profile. I have asked a whole bunch of questions and have only answerd 2 (including the answer point from this one). That is what you get for being a 16-year-old programmer. But its all good, because I am getting great experience here.

Sorry, I know you were only expecting like 1 sentence LOL.

Expert Comment

ID: 14024351
Sid, thanks for explaining.  Why are you so anxious to get points?  Are you trying to get free premium services?

You may be able to answer some of the math review questions posted by InteractiveMind, who is also young, I believe.  He posts them from time to time in the math topic area.


Expert Comment

ID: 14026272
K, thanks.

The reason I want points is because if I had enough, I would be asking questions every day.

I was just reading the premium services page. That’s all I need to do? Answer 12 questions? That’s easy enough. All I have to do is answer 10 more. But if experts have the ability to ask unlimited questions, what is the point of currency points in this? Or is that just a product of the "Premium Membership" that you have to buy? It just seems a bit over-rewarding for such a small amount of questions answerd. And what is with these yearly subscriptions? Anyways, I really don't know what awats for me on this site, or how the site actually works. But it doesn't even matter that much. I am just as happy with this non-premium package. The only thing is that I need points!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Simple Linear Regression
Loops Section Overview

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question