• Print

Author Topic: Battleship with AI  (Read 299 times)

Petr

  • Hero Member
  • *****
  • Posts: 656
Re: Battleship with AI
« Reply #15 on: April 26, 2018, 01:22:04 pm »
Hi BPlus. Yes, for it they are used to deploy a function named Rozmisti_LodeX (named as set ships in X axis), Rozmisti_LodeY (named as set ships in Y axis), this is for "A" map (left). The same functions, contains B in name, this set ships for computer map (right). "Pocty_Lodi" SUB Calculate number not destroyed ships, for both players and Function "VolnoA" return value if is the free space for inserting ships into Map A and "VolnoB" function return this for the enemy map. "InsertShipsManually" SUB allows a player to place a boat on the map manually.

I like waiting for your next version.
Coding is relax.

bplus

  • Hero Member
  • *****
  • Posts: 756
  • B = B + _
Re: Battleship with AI
« Reply #16 on: April 26, 2018, 09:01:09 pm »
Hi Petr,

I hope your wait wasn't too long, the next update has been loaded in the Original Post.

Thanks for your ideas!

Now has a play again loop and auto-setup for the Player.
Using 3 png image tiles and 6 wav sound files thanks to Johnno at TJP!
Plus the NewPlayer Instructions.txt file as promised.
Will you still love me, will you still need me, when I'm (QB) 64?

SMcNeill

  • Moderator
  • Hero Member
  • *****
  • Posts: 6248
Re: Battleship with AI
« Reply #17 on: April 26, 2018, 10:11:13 pm »
Quote from: bplus on April 26, 2018, 09:01:09 pm
Hi Petr,

I hope your wait wasn't too long, the next update has been loaded in the Original Post.

Thanks for your ideas!

Now has a play again loop and auto-setup for the Player.
Using 3 png image tiles and 6 wav sound files thanks to Johnno at TJP!
Plus the NewPlayer Instructions.txt file as promised.

Now you just need to modify it so it replicates the old Atarii 400 game, "Submarine Commander".  Instead of a 2D grid where you try and find and destroy battleships, you play on a 3D grid and try and find and destroy submarines at various depths.   It'd be a nice next step in the game evolution and could be a perfect way to help showcase 3D graphics for BASIC programmers.  ;)
http://bit.ly/Color32BI -- A set of color CONST for use in 32 bit mode, as a BI library.

bplus

  • Hero Member
  • *****
  • Posts: 756
  • B = B + _
Re: Battleship with AI
« Reply #18 on: April 27, 2018, 06:39:07 am »
Ahoy Admiral!

3D would be a nice next step in the evolution of this coder.  ;)

Where is King Ashish when you need his tutorial?  ;D
Will you still love me, will you still need me, when I'm (QB) 64?

Prithak

  • Jr. Member
  • **
  • Posts: 98
  • Programmer: A machine turns Coffee into Code.
Re: Battleship with AI
« Reply #19 on: April 27, 2018, 07:22:57 am »
Quote from: bplus on April 26, 2018, 06:48:32 am
Thanks QBExile,
(only don't try the link with () around game, you will get a query because the ) is missing (at least that's how it didn't work for me and my browser).

Update: Ha! well your link does work! ???

BTW How is your game coming? When I was searching the forum, I read a reply from you (I think) that you were working on a Battleship Game too; but I did not find another post related to that.



Hi Prithak and all players new to Battleship,

I have written up an New Player Instruction.txt file that should word wrap OK.
Quote
The object of the game is to sink all the Computer's ships before it sinks all yours.

Both the Player and the Computer are given 5 ships to lay out on a 10x10 grid.

The ships are a straight line of squares (2 to 5 squares) forming a long rectangle.
The ships are laid vertically or horizontally on the 10x10 cell grid without overlap.
Each square must be hit by the opponent in order to sink the ship.

The 5 ships are:
Carrier    - 5 squares to hit
Battleship - 4 squares to hit
Cruiser    - 3 squares to hit
Submarine  - 3 squares to hit
Destroyer  - 2 squares to hit

The game is started by each opponent laying out their ships secretly to the other.
You the Player must setup your ships on the right board.
They are setup in same order I listed above.

So the first ship to set up will be the Carrier that is 5 squares long.
First you will be prompted whether you want to lay it out horizontally or vertically, h or v ?

Then if horizontally is chosen, you click the cell where you want the left most square of the ship to go.
Like wise if vertical v was chosen, you click the board cell where you want the top most square to go.

If there is room on board to lay out all 5 across AND this ship does not overlap another, then the rest of the ship will be drawn in.
(Of course, the first ship can't overlap another but every other ship has that potential.)
If there is not room or the ship would overlap another, then you must start over with the prompt to lay the ship horizontally or vertically...

When you get all 5 of your ships laid out on the 10x10 grid on the left, the shooting match begins!

You will be prompted to click a cell on the left 10x10 board to guess where a Computer's ship might be.
If you hit a square on one of the Computers ships a red dot = hit appears at that cell.
If you miss all the Computers ships, a white dot will appear = miss

The Computer will then take a shot and your board will show a red or white dot according to the Computer's hit or miss.

Then it's your turn again. If you had a hit the last turn you will likely want to find the rest of the ship to sink it.
So click above, below, left or right of the hit = red dot.
A 2nd hit will tell you if the ship is laid out horizontally or vertically.
A 2nd hit would actually sink a Destroyer because it is only 2 squares long.

So you scout around the 10x10 board making random shots (or systematically cover the board with shots)
until you find a ship, sink it and go hunting for the next ship to sink until you get all 5.

Meanwhile the Computer is doing the same thing, so which ever opponent sinks all the ships first, wins!

Oh a caveat!
It is possible to align the ships side by side or one end up next to another ship (as long as they don't overlap).
This makes it confusing as you might be hitting 2 different ships with your shots, so pay close attention to which ship is announced sunk
you might have more hits in the same area than how many it took to sink the ship.

https://en.wikipedia.org/wiki/Battleship_game


Thanks Prithak, I guess I assumed everyone knew this game, my bad. Let me know if this helps get you going. I will include a modified New Player Instruction file with the zip pack, in next update with help from your feedback.

Thank you so much for the help. I understand the game now !YAY! and yeah many people don't know what a battleship game is. I asked many of my friends (Who are gamers and programmers) and out of 20 I think only 2-3 people knew what it was.
We got some juicy future programmers in Nepal's hands though (They all want to be Software Engineers One day). And yes, it would be nice if you added a tutorial file in the ZIP...

Thanks,
Arigatto,

Prithak   :)
Q: 0 is False and 1 is True, right?
A: 1

bplus

  • Hero Member
  • *****
  • Posts: 756
  • B = B + _
Re: Battleship with AI
« Reply #20 on: April 27, 2018, 07:40:47 am »
Hi Prithak,

Thanks for your feedback, sounds like the instructions did their job.

I don't know about tutorials. I don't know what noobies don't know. I don't know too much.  :D

I do know I like dialogging and helping others get started very much!
Will you still love me, will you still need me, when I'm (QB) 64?

bplus

  • Hero Member
  • *****
  • Posts: 756
  • B = B + _
Re: Battleship with AI
« Reply #21 on: April 28, 2018, 11:51:43 am »
To BasicKing: Warning this will not likely compile under Regular DOS QBasic 4.5  :D
Will you still love me, will you still need me, when I'm (QB) 64?

bplus

  • Hero Member
  • *****
  • Posts: 756
  • B = B + _
Re: Battleship with AI
« Reply #22 on: April 28, 2018, 02:38:46 pm »
But maybe Fellippe will check it for you.  :D
Will you still love me, will you still need me, when I'm (QB) 64?

  • Print