Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Dec 08, 2019 6:26 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Battleships, Please Help
PostPosted: Wed Nov 04, 2009 1:13 pm 
Offline

Joined: Wed Nov 04, 2009 12:49 pm
Posts: 1
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Battleships, Please Help
PostPosted: Wed Nov 04, 2009 3:21 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
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.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Battleships, Please Help
PostPosted: Wed Nov 04, 2009 7:41 pm 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
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.

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Battleships, Please Help
PostPosted: Fri Nov 06, 2009 5:05 pm 
Offline

Joined: Sat Nov 24, 2007 3:09 pm
Posts: 159
Location: Denver, CO
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.

_________________
Mojiferous Industries, now 300% more Mojifertastic!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group