# Small problem with Battleship AI

This is a discussion on Small problem with Battleship AI within the Game Programming forums, part of the General Programming Boards category; Code: aiMove::aiBomb() { // 13 == Miss; // 11 == Already fire apon; m_oldRandY = m_randY; m_oldRandX = m_randX; whichBoard->bombCoords(randX, ...

1. ## Small problem with Battleship AI

Code:
```aiMove::aiBomb()
{
// 13 == Miss;
// 11 == Already fire apon;

m_oldRandY = m_randY;
m_oldRandX = m_randX;
whichBoard->bombCoords(randX, randY);
do
{
short int bombCoord = whichBoard->bombCoords(m_randX, m_randY);
if (!lastMoveHit)
{

m_randY = 1 + rand() % (m_xCoord - 1);
m_randX = 1 + rand() % (m_yCoord - 1);
short int bombCoord = whichBoard->bombCoords(randX, randY);
if (bombCoord != 13 && bombCoord != 11 && bombCoord => 10)
{
m_lastMoveHit = 1;
} else {
m_lastMoveHit = 0;
}

} else {

// If we hit something last time, but didn't sink it
// we need to check around that position..
// Gawd this hurts my head..

}

} while (bombCoord == 11);```

Where you see the comments, I need to implement some system of checking around the location of the ship.. I don't really require code.. as that would require me to post most of my OO Battleship game (~900 lines)

I can almost get it.. but I've put this project aside for a week because of this difficulty; so I guess it's time to ask for help.

2. If last move (x,y) a hit

4 possible locations
(x-1,y), (x+1,y) , (x,y-1) , (x,y+1)
need to test each until get 2 hits on ship.

if (two_hits or more) first (x,y) second (x+1,y) to (x+n,y)
(two possible outcomes after two hits)

sunk ship -> start again at random

or

two possible locations
(x-1,y) and (x+n+1,y)
(may have previously tested these so need to keep track of 'missed' shots)

maybe recursive function is the answer here?

Also need to record missed shots and locations that it is not possible to have a ship (eg less than minimum remaining ship length apart) This should be tested before the hitting function called and if not a valid point, a new loction generated and tested.

Sort of........

3. Wow, 900 lines for battleship without any ai?
jeez, post the exe or source, i wanna see this.

4. I can make a 900 line hello world program.