Soon we're going to start creating our Battleship game.
And I really feel like this is the game that really emphasizes what I went over in the first section
which is how to approach problems and how to have a specific methodology for doing so.
I think this one's going to illustrate that the best and if you remember the picture programming that
I have in my head you'll know that since we have this picture we you should notice that every time we've
solved again we always start with understanding the problem first.
Right.
This is kind of the output of it all right.
And I always said that first you understand the problem then you kind of understand the data and then
you do kind of all the transforms.
In other words algorithms.
This is really understanding the problem is always the first part.
And so in a read through the description try to understand what will need right all the input that will
need and that will give us a very good way of creating the algorithms.
This would be the kind of top down design part.
And in this lecture I want to focus on the both the output and the input of the game.
So skill through this so game Battleship game is played on for 10 by 10 grids by two players each with
each player having two grids each the rows of the grid go from eight J in the rows and one to ten in
the columns each player will arrange their ships on their respective ship board before the main game
starts.
Each ship occupies a number of consecutive squares on the grid arrange either horizontally or vertically
the number of squares for each ship is determined by the type of the ship the ships cannot overlap.
And we have five ships here the aircraft carrier and the site size is five.
About ship is order cruisers 3 and Sawyer is also three and the submarine is two.
And so these are going to be sizes on the grid.
So they're going off by for example the aircraft carrier is going to occupy five spots or I've squares
on the grid.
And so after the ship has been positioned the game proceeds in a series of rounds each round.
Each player takes a turn to announce the target square in the opponent's grid which is to be shot at
the opponent announces whether or not the square is occupied by a ship and if it is Miss the player
marks there guest board as a miss.
And if it is a hit the market has hit.
This is the build up a picture of the opponent's fleet.
If the guess was a hit the attacked player will mark their ship as it has hit in the best location and
that will end the turn.
When all of these squares the ship had been hit.
The ship will is sunk.
And there is output about what ship was sunk.
If player ships have been sunk the game is over and their opponent is king.
So so now that we sort of understand what the game is I think we all play of before we should start
trying to understand what kind of input we're going to need for our.
So it's kind of start doing that right here.
So in general I've noticed
three or four things.
Generally I have noticed that there are ships.
I've noticed that there are boards
and players and we have this kind of gas as well or the guess is really a position on board
Kay.
So of of those kind of for general things in here from just reading the description now let's kind of
break down each one and see what they are or what they can consist of.
So it's sort of a ship's
in there are five types.
OK that's one thing that the ship has sort of a type in it listed above it was out of
say five types
in its There are they have a size right.
So if those here an aircraft carriers five spots on board so each one has some science.
Ok
one has a position on the board.
Right.
So the roads are between a and J and columns between one and 10 or so some position.
And they have an orientation on the board.
Right.
So either vertical or horizontal.
So
right here so each ship occupies a number of consecutive squares on that grid arrange either horizontally
or vertically so they have some position and they occupy some size or some consecutive number of squares
on the board and their position horizontally orbit.
Right.
So we're just trying to understand kind of what a ship is.
That's what we're doing here.
And the can be damage rate because if you guess and on one of their spots then and if it's a hit they
were hit in that specific spot right in a specific spot.
And that's kind of really it for ships there's nothing much more really.
So let's move on to the board.
It's
so if you have ever seen a picture of someone playing battleship you'll know that the top ored is kind
of your
Europe like your view of your opponent's sport.
So they're really two different kinds of ball.
So two different kinds different or really.
And that is your he going to say the ship or where you place all your ships and
right in your I'm going to say it's the guess or in fact set it up here.
So
it's somewhere here.
You turn the page.
I've said so right here.
So that's going to be kind of your
your view of the pones
or you.
It's
OK.
There's kind of can be two different one.
It's so
the chess board
and be in three states re.
So it can either contain Like or so each spot on board.
Each
sition on the board can be in three states right.
So you either be hit there could be a miss.
It's like you didn't hear anything there or we haven't guessed there.
Right.
So
that's really it for that.
And there's only there's only three states that can get in.
And there is a board for your your ships.
Right.
So in or for ships
so this will just contain all the players ships at certain locations.
So we don't really know what that means but also there is one other part of that which is you know in
the traditional game the place markers
on the spots where our ships have been hit
so you hit so your opponent guessed and they guessed correctly.
We as the attack player also mark our ships as being hit right so so so so the gas was hit the attack
where I will mark the ship hit the guest location.
Right.
So we also do this just so we know what's been hit and what what hasn't.
OK.
So that's kind of it for the Bortz.
The other thing was here's.
So the players have kind of.
So we're just going to say how I want the players to have a name and name
and they have all their ships.
The ships and they have board or and they have the ship board.
Right.
So they actually contain all these things.
And of course the last thing I notice or I put down here which is guess really I guess is just a position
on the board.
And those position
has a row which goes for a to J right.
That's from you know if it was one in ten or eight and from columns
1
in that's kind of really it's so sort of broken down now.
The
what.
What they have and notice or what battleship has you know so we're really just kind of describing the
problem again but we're just describing the problem again kind of more broken down into its individual
elements.
And in the next lecture I'm going to take everything that we have here and turn it into actual user
defined types and so that we can actually describe our problem in those types and actually writing code
in those types.
So I'll see you in the next lecture.