Real Software Forums
http://forums.realsoftware.com/

Battleships, Please Help
http://forums.realsoftware.com/viewtopic.php?f=4&t=30848
Page 1 of 1

Author:  Jamarts-1874 [ Wed Nov 04, 2009 1:13 pm ]
Post subject:  Battleships, Please Help

Hey iam new to the forums here. I was wondering if anyone has any basic battleship games that they have made in RB that i could have to look at so as i know how it works. I am doing Advance Higher computing at high school and i have chosen to do battleships for my project. I have no previous experiance with RB and i do not have a clue how to start doing a game. I have never programmed a game before using any language. oh we use Macs at the skl

- i need to make a battleship game with a nice easy to use GUI
- a basic computer AI
- it has to save the players name and score to a document on the computer
- it has to sort the document of player names and scores so as the best one is at the top
- it is 2-D

Any help will be greatly appreciated and it is badly needed :)

or if any1 knows of any good websites for starting out programming games on Realbasic

Author:  DaveS [ Wed Nov 04, 2009 3:21 pm ]
Post subject:  Re: Battleships, Please Help

Sorry... if you are in "Advanced Higher" computing classes, then the design and implementaion of a game like Battleship should be a trivial matter. The most difficult part might be the LAN/TCP connection assuming you want it to play between two players on different computers.

Were I iso nclined, I could probably punch out a reasonable version in 3 or 4 hours..... but then thats why its called homework.

We will help you with specific questions and topics.... but your "question" is very vague and very very broad.

Author:  msssltd [ Wed Nov 04, 2009 7:41 pm ]
Post subject:  Re: Battleships, Please Help

Jamarts-1874 wrote:
I have no previous experiance with RB and i do not have a clue how to start doing a game. I have never programmed a game before using any language.
I should start by reading the RB User Guide and working through the tutorials. You might want to read an Object Oriented Programming primer or two (google is your friend), as well.

Then I would probably get a big bit of paper and write some headings along how I want my application partitioned. Then under those headings I might sketch out roughly what the objects will look like. And I would know that objects are called classes in RB, because I would have read the User Guide and followed the tutorials. Then I would put some arrows in describing what messages these objects would need to send to each other (events). And those arrows would give me an idea of what properties my objects are going to need. Then I might fill in how data flows between the objects and what methods these objects need to process the data (scope). I definitely would not start thinking too hard about the GUI until I had a good idea what the back end processing engine is going to look like.

Your started for 10.
The game is played on a 2D grid, also known as a matrix. The elemental unit of a matrix is a cell. X and Y coordinates are what make a Cell a Cell. In combination those coordinate values identify the cell, with a meaningful name.
Class Cell
Property X as Integer
Property Y as Integer
Computed Property Name
Sub Name.Get as String
Return Chr(X + 64) + CStr(Y)
End Sub
End Class

...And there is the start of your first object. You can probably think of a few more properties this object is going to need, but they can be added later.

Next you will need a Playing Board object which holds a matrix of cells in a 10 x 10 grid.

Please do keep us informed of how you are getting on. Battleships is a neat little project for learning OOP, and RB is a really easy to use OOP tool. I am sure you will find a few people here willing to point you in the right direction and critique your ideas. You might find someone willing to lead you by the hand but you will not learn anything by allowing them to.

Best of luck.

Author:  mojiferous [ Fri Nov 06, 2009 5:05 pm ]
Post subject:  Re: Battleships, Please Help

Actually, designing a decent AI for something as simple as a battleship game can be challenging -- you should determine the best method for finding the user's ships. My first thought would be to start off with shots across the board (assuming a 10x10 board) like so:

x--------x
-x------x-
--x----x--
---x--x---
----xx----
---x--x---
--x----x--
-x------x-
x--------x

and then filling in holes so that you have covered all possible spaces for the battleship (4x1) and cruisers (3x1). Of course you also have to take into account hitting and sinking ships - determining orientation, keeping track of which ships have been sunk, how many spaces they take up, and therefore altering your algorithm to account for the change (because if you're only searching for submarines, you better close all those 2x1 gaps.) Of course, the easiest way to fool a badly-programmed battleship algorithm is to place two ships directly next to each other and hope that the computer aims perpendicular to the facing of the ships, counting the single hits on the ships as a submarine and moving on -- adding logic to counter this would prevent a meltdown within your search algorithm.

My method here would be to build the AI separately and have it run without user interaction (e.g. without the user shooting back at the computer's ships) over and over again while tweaking the AI -- ideally you would want it winning quickly and efficiently (within 30 turns? maybe. I don't know how long the average battleship games lasts.) Run this on a standard board that you set up before hand, so you have an equal base to measure it by...

The logic and theory surrounding AI ship placement could probably occupy another equally long paragraph... I would run the same thing as above, but instead of a standard placement, obviously you would have the computer place its ships and then run your finished shooting algorithm.

Then you can worry about the UI and graphics and all that stuff.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/