Grid.h
#ifndef grid_h
#define grid_h
#include"Game.h"
void printBoardInput (string gameBoard[11][11], string
Display1[11][11]);
void printBoard (string GuessP1[11][11], string
Board1[11][11],string Display1[11][11], int GuessP2[11][11]);
string Board1[11][11] = {
{" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"},
{"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
};
// will display a "O" for guesses that didn't hit a ship.
// will display a "X" for guesses that did.
string GuessP1[11][11] = {
{" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"},
{"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
};
string Display1[11][11] = {
{" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"},
{"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
};
string Board2[11][11] = {
{" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"},
{"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
};
string Display2[11][11] = {
{" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"},
{"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
{"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
};
#endif /* grid_h */
__MACOSX/._Grid.h
Game.h
#ifndef Game_h
#define Game_h
#include<iostream>
#include<vector>
using namespace std;
void endPrintBoard (string Board1[11][11], string
Display1[11][11],string Board2[11][11], string
Display2[11][11],string GuessP1[11][11]);
bool stringInterpreter (vector < char >LocShips, int &row1, int
&Column1);
void setLocShips (string Board1[11][11], int ships, int
shipLengths[5],int p1LocShipss[5][4], string Display1[11][11]);
void setP2ShipLocs (string Board2[11][11], int
p2LocShipss[5][4],int shipLengths[5]);
bool ShipSunk (int shipLocs[5][4], bool isSunk[5], string
board[11][11],int turn);
bool ShipSunk (int shipLocs[5][4], bool isSunk[5], string
board[11][11],int turn, int GuessP2[11][11]);
bool chooseTile (string Board1[11][11], string
Board2[11][11],string GuessP1[11][11], int
p2LocShipss[5][4],bool p2isSunk[5], string
Display1[11][11],int GuessP2[11][11]);
void getP1ShipLocs (string Board1[11][11], int
shipLengths[],int p1LocShipss[5][4], string Display1[11][11]);
void BombingMostProbable (int GuessP2[11][11], int row, int
col,int directions[4]);
void smartComp (int GuessP2[11][11], bool p1isSunk[5],int
shipLengths[5], int &row, int &col);
void displayCPUGuess (int row, int col);
bool BSAI (string Board1[11][11], int GuessP2[11][11],bool
p1isSunk[5], int shipLengths[5],int p1LocShipss[5][4]);
void setDisplayBoard (string board[11][11], int locs[5][4]);
#endif /* Game_h */
__MACOSX/._Game.h
main.cpp
#include <iostream>
#include <string>
#include <time.h>
#include <vector>
#include <stdlib.h>
#include "Game.h"
#include "Grid.h"
using namespace std;
int main ()
{
srand (unsigned (time (NULL)));
int GuessP2[11][11] = { 0 };
int p1LocShip[5][4]; // array with player 1 ship locations [
r1 c1 r2 c2 ]
int p2LocShip[5][4]; // array with player 2 ship locations [
r1 c1 r2 c2 ]
int shipLengths[5] = { 5, 4, 3, 3, 2 }; // remember the
length of each ship.
// if true, the ship is still alive.
bool p1isSunk[5] = { true, true, true, true, true };
bool p2isSunk[5] = { true, true, true, true, true };
// A B C S D
// get the user's ship locations
getP1ShipLocs (Board1, shipLengths, p1LocShip, Display1);
// set the CPU's ship locations
setP2ShipLocs (Board2, p2LocShip, shipLengths);
// set the CPU display board based on the ship locations
setDisplayBoard (Display2, p2LocShip);
// begin play
int turn = 1; // keep track of whose turn it is
while (true)
{
if (turn == 1)
{
if (chooseTile
(Board1, Board2, GuessP1, p2LocShip, p2isSunk,
Display1, GuessP2))
{
cout <<
"n-----------------------------------------------------------
------------------------------------------------------------n";
cout <<
"| You Win!
|";
endPrintBoard (Board1, Display1, Board2, Display2,
GuessP1);
return 0;
} // end if (chooseTile(GuessP1, Board2,
userGuess))
turn = 2; // CPU's turn
} // end if (turn == 1)
else
{
if (BSAI
(Board1, GuessP2, p1isSunk, shipLengths,
p1LocShip))
{
cout <<
"n-----------------------------------------------------------
------------------------------------------------------------n";
cout <<
"| You Lose!
|";
endPrintBoard (Board1, Display1, Board2, Display2,
GuessP1);
return 0;
}
turn = 1;
}
}
}
void
printBoardInput (string gameBoard[11][11], string
Display1[11][11])
{
for (int r = 0; r < 11; r++)
{
for (int c = 0; c < 11; c++)
{
if (r == 0)
{
cout << gameBoard[r][c] << " ";
}
else
{
if (gameBoard[r][c] == "S")
{
cout << Display1[r][c] << " | ";
}
else if (gameBoard[r][c] == " ")
{
cout << gameBoard[r][c] << " | ";
}
else
{
cout << gameBoard[r][c] << " | ";
}
}
}
cout << "n -----------------------------------------n";
}
}
void
printBoard (string GuessP1[11][11], string Board1[11][11],
string Display1[11][11], int GuessP2[11][11])
{
cout <<
"----------------------------------------------------------------------
-------------------------------------------------n";
cout << "|" <<
" YOUR GUESSES
YOUR SHIPS/CPU GUESSES "
<< "|n";
cout <<
"----------------------------------------------------------------------
-------------------------------------------------n";
cout <<
"|
|n";
for (int r = 0; r < 11; r++)
{
cout << "|t";
for (int c = 0; c < 11; c++)
{
if (r == 0)
{
cout << GuessP1[r][c] << " ";
} // end if (r == 0)
else
{
if ((GuessP1[r][c] == "X" || GuessP1[r][c] == "A"
|| GuessP1[r][c] == "B" || GuessP1[r][c] == "C"
|| GuessP1[r][c] == "S" || GuessP1[r][c] == "D")
&& c > 0)
{
cout << GuessP1[r][c] << " | ";
}
else if (GuessP1[r][c] == "O")
{
cout << GuessP1[r][c] << " | ";
} // end else if (GuessP1[r][c] == "O")
else if (GuessP1[r][c] == " ")
{
cout << GuessP1[r][c] << " | ";
}
else
{
cout << GuessP1[r][c] << " | ";
}
}
}
cout << "tt";
for (int c = 0; c < 11; c++)
{
if (r == 0)
{
cout << Board1[r][c] << " ";
}
else
{
if (Board1[r][c] == "S")
{
cout << Display1[r][c] << " | ";
}
else if (Board1[r][c] == "X")
{
if (GuessP2[r][c] == 2 || GuessP2[r][c] == 3)
{
cout << Display1[r][c] << " | ";
}
else
{
cout << Display1[r][c] << " | ";
}
}
else if (Board1[r][c] == "O")
{
cout << Board1[r][c] << " | ";
}
else if (Board1[r][c] == " ")
{
cout << Board1[r][c] << " | ";
}
else
{
cout << Board1[r][c] << " | ";
}
}
}
if (r == 0)
{
cout << " |";
} // end if (r == 0)
else
{
cout << " |";
} // end else: if (r == 0)
cout <<
"n| t ----------------------------------------- tt -------------
---------------------------- |n";
} // end for (int r = 0; r < 11; r++)
cout <<
"|
|";
cout <<
"n--------------------------------------------------------------------
---------------------------------------------------n";
}
bool
stringInterpreter (vector < char >LocShips, int &row1, int
&Column1)
{
if (LocShips.size () < 2)
{
cout <<
" Mistakes were made. Try Again.n Inputs must be a
Letter(A - J) followed by a Number(1 - 10).nn";
return true;
}
if (LocShips[0] == 'A' || LocShips[0] == 'a')
{
row1 = 1;
}
else if (LocShips[0] == 'B' || LocShips[0] == 'b')
{
row1 = 2;
}
else if (LocShips[0] == 'C' || LocShips[0] == 'c')
{
row1 = 3;
}
else if (LocShips[0] == 'D' || LocShips[0] == 'd')
{
row1 = 4;
}
else if (LocShips[0] == 'E' || LocShips[0] == 'e')
{
row1 = 5;
}
else if (LocShips[0] == 'F' || LocShips[0] == 'f')
{
row1 = 6;
}
else if (LocShips[0] == 'G' || LocShips[0] == 'g')
{
row1 = 7;
}
else if (LocShips[0] == 'H' || LocShips[0] == 'h')
{
row1 = 8;
}
else if (LocShips[0] == 'I' || LocShips[0] == 'i')
{
row1 = 9;
}
else if (LocShips[0] == 'J' || LocShips[0] == 'j')
{
row1 = 10;
}
else
{
cout <<
" Mistakes were made. Try Again.n Inputs must be a
Letter(A-J) followed by a Number(1-10).nn";
return true;
}
if (LocShips.size () < 3)
{
if (LocShips[1] == '1')
{
Column1 = 1;
}
else if (LocShips[1] == '2')
{
Column1 = 2;
}
else if (LocShips[1] == '3')
{
Column1 = 3;
}
else if (LocShips[1] == '4')
{
Column1 = 4;
}
else if (LocShips[1] == '5')
{
Column1 = 5;
}
else if (LocShips[1] == '6')
{
Column1 = 6;
}
else if (LocShips[1] == '7')
{
Column1 = 7;
}
else if (LocShips[1] == '8')
{
Column1 = 8;
}
else if (LocShips[1] == '9')
{
Column1 = 9;
}
else
{
cout <<
" Mistakes were made.Try Again.n Inputs must be a
Letter(A - J) followed by a Number(1 - 10).nn";
return true;
}
}
else if (LocShips.size () == 3)
{
if (LocShips[1] == '1' && LocShips[2] == '0')
{
Column1 = 10;
}
else
{
cout <<
" Mistakes were made.Try Again.n Inputs must be a
Letter(A - J) followed by a Number(1 - 10).nn";
return true;
}
}
else
{
cout <<
" Mistakes were made.Try Again.n Inputs must be a
Letter(A - J) followed by a Number(1 - 10).nn";
return true;
}
return false;
}
void
setLocShips (string Board1[11][11], int ships, int
shipLengths[5],
int p1LocShip[5][4], string Display1[11][11])
{
string LocShips;
int row1, Column1;
int row2, Column2;
int temp;
vector < char >location1;
vector < char >location2;
bool secondString;
bool shipsIntersected;
static int p1Ships = 0;
while (true)
{
LocShips = " ";
cout << "Please place your " << shipLengths[ships] << "-
tile ship: ";
cin >> LocShips;
secondString = false;
for (int idx = 0; idx < LocShips.size (); idx++)
{
if (!secondString)
{
if (LocShips[idx] == '-')
{
secondString = true;
}
else
{
location1.push_back (LocShips[idx]);
}
}
else
{
location2.push_back (LocShips[idx]);
}
}
if (!secondString)
{
cout << " Input must be LetterNumber-
LetterNumber.n";
location1.clear ();
location2.clear ();
continue;
}
if (stringInterpreter (location1, row1, Column1))
{
location1.clear ();
location2.clear ();
continue;
}
if (stringInterpreter (location2, row2, Column2))
{
location1.clear ();
location2.clear ();
continue;
}
if (row1 != row2 && Column1 != Column2)
{
cout << " The ships are one dimensional. Try
again.n";
location1.clear ();
location2.clear ();
continue;
}
if (row1 == row2)
{
if (Column2 < Column1)
{
temp = Column1;
Column1 = Column2;
Column2 = temp;
} // end if (Column2 < Column1)
if ((Column2 - Column1 + 1) != shipLengths[ships])
{
cout << " Your input was not the correct size. Try
again.n";
location1.clear (); // if it isn't, clear the vectors
location2.clear ();
continue;
}
}
else
{
if (row2 < row1)
{
temp = row1;
row1 = row2;
row2 = temp;
}
if ((row2 - row1 + 1) != shipLengths[ships])
{
cout << " Your input was not the correct size. Try
again.n";
location1.clear ();
location2.clear ();
continue;
}
}
shipsIntersected = false;
for (int r = row1; r <= row2; r++)
{
for (int c = Column1; c <= Column2; c++)
{
if (Board1[r][c] == "S")
{
shipsIntersected = true;
cout << " Ships may not intersect. Try Again.n";
location1.clear ();
location2.clear ();
break;
}
}
if (shipsIntersected)
{
break;
}
}
if (shipsIntersected)
{
continue;
}
break;
}
for (int r = row1; r <= row2; r++)
{
for (int c = Column1; c <= Column2; c++)
{
Board1[r][c] = "S";
}
}
string shipNames[5] = { "A", "B", "C", "S", "D" };
for (int r = row1; r <= row2; r++)
{
for (int c = Column1; c <= Column2; c++)
{
Display1[r][c] = shipNames[p1Ships];
}
}
int shipLocs[4] = { row1, Column1, row2, Column2 };
if (p1Ships < 5)
{
for (int i = 0; i < 4; i++)
{
p1LocShip[p1Ships][i] = shipLocs[i];
} // for (int i = 0; i < 4; i++)
p1Ships++;
} // if (p1Ships < 5)
}
void
setP2ShipLocs (string Board2[11][11], int p2LocShip[5][4],
int shipLengths[5])
{
int max[] = { 6, 5, 4, 4, 3 };
bool isPlaced = false;
int row = 0;
int col = 0;
enum direction
{
horizontal,
vertical
};
direction whichWay;
for (int ships = 0; ships < 5; ships++)
{
while (!isPlaced)
{
isPlaced = true;
whichWay = (rand () % 2 == 0) ? horizontal : vertical;
if (whichWay == horizontal)
{
col = 1 + rand () % max[ships];
row = 1 + rand () % 10;
for (int c = col; c < col + (11 - max[ships]); c++)
{
if (Board2[row][c] == "S")
{
isPlaced = false;
break;
}
}
}
else
{
row = 1 + rand () % max[ships];
col = 1 + rand () % 10;
for (int r = row; r < row + (11 - max[ships]); r++)
{
if (Board2[r][col] == "S")
{
isPlaced = false;
break;
}
}
}
}
isPlaced = false;
if (whichWay == horizontal)
{
for (int c = 0; c < max[ships] - 1; c++)
{
Board2[row][col + c] = 'S';
} // end for (int c = 0; c < maxGuess - 1; c++)
p2LocShip[ships][0] = row;
p2LocShip[ships][1] = col;
p2LocShip[ships][2] = row;
p2LocShip[ships][3] = col + shipLengths[ships] - 1;
} // end if (whichWay == horizontal)
else
{
for (int r = 0; r < max[ships] - 1; r++)
{
Board2[row + r][col] = 'S';
} // end for (int r = 0; r < maxGuess - 1; r++)
p2LocShip[ships][0] = row;
p2LocShip[ships][1] = col;
p2LocShip[ships][2] = row + shipLengths[ships] - 1;
p2LocShip[ships][3] = col;
}
}
}
bool
ShipSunk (int shipLocs[5][4], bool isSunk[5], string
board[11][11],
int turn, string GuessP1[11][11])
{
// determine if the ship is sunk during player 1's turn
bool shipSunk = true;
for (int ship = 0; ship < 5; ship++)
{
if (isSunk[ship])
{
shipSunk = true;
for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2];
r++)
{
for (int c = shipLocs[ship][1]; c <=
shipLocs[ship][3]; c++)
{
if (board[r][c] == "S")
{
shipSunk = false;
break;
}
}
if (!shipSunk)
{
break;
} // end if (!shipSunk)
} // end for (int r = shipLocs[ship][0]; r <=
shipLocs[ship][2]; r++)
if (shipSunk)
{
isSunk[ship] = false;
string shipNames[5] = { "A", "B", "C", "S", "D" };
for (int r = shipLocs[ship][0]; r <=
shipLocs[ship][2]; r++)
{
for (int c = shipLocs[ship][1]; c <=
shipLocs[ship][3]; c++)
{
GuessP1[r][c] = shipNames[ship];
}
}
if (turn == 1)
{
cout << " You sunk the computer's ";
} // end if (turn == 1)
else
{
cout << " The CPU sank your ";
} // end else: if (turn == 1)
switch (ship)
{
case 0:
cout << "Aircraft Carrier!n";
break;
case 1:
cout << "Battleship!n";
break;
case 2:
cout << "Cruiser!n";
break;
case 3:
cout << "Submarine!n";
break;
case 4:
cout << "Destroyer!n";
break;
} // end switch (ship)
return true;
} // end if (shipSunk)
} // end if (isSunk[ship])
} // end for (int ship = 0; ship < 5; ship++)
return false;
} // end bool ShipSunk(int shipLocs[5][4], bool
isSunk[5], string board[11][11], int turn, string
GuessP1[11][11])
bool
ShipSunk (int shipLocs[5][4], bool isSunk[5], string
board[11][11],
int turn, int GuessP2[11][11])
{
// determine if CPU's last guess sunk a ship.
bool shipSunk = true;
for (int ship = 0; ship < 5; ship++)
{
if (isSunk[ship])
{
shipSunk = true;
for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2];
r++)
{
for (int c = shipLocs[ship][1]; c <=
shipLocs[ship][3]; c++)
{
if (board[r][c] == "S")
{
shipSunk = false;
break;
} // end if board
} // end for (int c = shipLocs[ship][1]; c <=
shipLocs[ship][3]; c++)
if (!shipSunk)
{
break;
} // end if (!shipSunk)
} // end for (int r = shipLocs[ship][0]; r <=
shipLocs[ship][2]; r++)
if (shipSunk)
{
// if shipsunk is true, the previous guess sunk the
ship
// update GuessP2 to indicate the sunk ship
for (int r = shipLocs[ship][0]; r <=
shipLocs[ship][2]; r++)
{
for (int c = shipLocs[ship][1]; c <=
shipLocs[ship][3]; c++)
{
GuessP2[r][c] = 3;
} // end for (int c = shipLocs[ship][1]; c <=
shipLocs[ship][3]; c++)
} // end for (int r = shipLocs[ship][0]; r <=
shipLocs[ship][2]; r++)
// update the ship's status
isSunk[ship] = false;
if (turn == 1)
{
cout << " You sunk the computer's ";
} // end if (turn == 1)
else
{
cout << " The CPU sank your ";
} // end else: if (turn == 1)
switch (ship)
{
case 0:
cout << "Aircraft Carrier!n";
break;
case 1:
cout << "Battleship!n";
break;
case 2:
cout << "Cruiser!n";
break;
case 3:
cout << "Submarine!n";
break;
case 4:
cout << "Destroyer!n";
break;
}
return true;
} // end switch (ship)
} // end if (isSunk[ship]){
} // end for (int ship = 0; ship < 5; ship++)
return false;
} // end bool ShipSunk(int shipLocs[5][4], bool
isSunk[5], string board[11][11], int turn, int GuessP2[11][11])
bool
isGameOver (bool isSunk[5])
{
// check each ships status.
// if a ship is alive, return false -- else return true;
for (int i = 0; i < 5; i++)
{
if (isSunk[i])
return false;
}
return true;
} // end bool isGameOver(bool isSunk[5])
bool
chooseTile (string Board1[11][11], string Board2[11][11],
string GuessP1[11][11], int p2LocShip[5][4],
bool p2isSunk[5], string Display1[11][11],
int GuessP2[11][11])
{
// handle user's turn.
// when the user sinks a ship, check to see if the ship was the
last ship.
// if the last ship was sunk, return true to alert main that the
game is over.
vector < char >userGuess; // vector to hold user input
string userInput; // string for user guess
int row; // user's row guess
int col; // user's col guess
bool tryAgain; // if their input is invalid -- true
// print the game board
printBoard (GuessP1, Board1, Display1, GuessP2);
do
{
cout << " Where are we aiming our cannons: ";
cin >> userInput;
// this wouldn't have to be a char vector,
// but the input for placing the user's ships does
// so string interpreter was written to handle char vectors
// ergo, char vector.
for (int i = 0; i < userInput.size (); i++)
{
userGuess.push_back (userInput[i]);
} // end for (int i = 0; i < userInput.size(); i++)
tryAgain = stringInterpreter (userGuess, row, col);
if (tryAgain)
{
userGuess.clear ();
} // end if (tryAgain)
}
while (tryAgain);
if (Board2[row][col] == "S")
{
cout << " You hit the CPU's ship!n";
GuessP1[row][col] = "X";
Board2[row][col] = "X";
if (ShipSunk (p2LocShip, p2isSunk, Board2, 1, GuessP1))
{
if (isGameOver (p2isSunk))
{
return true;
}
}
}
else if (GuessP1[row][col] == "X" || GuessP1[row][col] ==
"O"
|| GuessP1[row][col] == "A" || GuessP1[row][col] ==
"B"
|| GuessP1[row][col] == "C" || GuessP1[row][col] ==
"S"
|| GuessP1[row][col] == "D")
{
cout << " You've already guessed this location. Try
Again.n";
if (chooseTile
(Board1, Board2, GuessP1, p2LocShip, p2isSunk,
Display1, GuessP2))
{
return true;
}
}
else
{
cout << " you missed :( n";
GuessP1[row][col] = "O";
} // end else
return false;
}
void
getP1ShipLocs (string Board1[11][11], int shipLengths[],
int p1LocShip[5][4], string Display1[11][11])
{
for (int ships = 0; ships < 5; ships++)
{
cout <<
"n-----------------------------------------------------------------
------------------------------------------------------n";
cout << "WELCOME TO BATTLESHIP n";
cout <<
"-------------------------------------------------------------------
----------------------------------------------------nn";
printBoardInput (Board1, Display1);
setLocShips (Board1, ships, shipLengths, p1LocShip,
Display1);
system ("cls");
}
}
void
BombingMostProbable (int GuessP2[11][11], int row, int col,
int directions[4])
{
int dir[4] = { 1, 1, 1, 1 };
// check North
while ((GuessP2[row - dir[0]][col] == 0
|| GuessP2[row - dir[0]][col] == 2) && row - dir[0] >=
1)
{
dir[0]++;
} // end while ((GuessP2[row - dir[0]][col] == 0 ||
GuessP2[row - dir[0]][col] == 2) && row - dir[0] >= 1)
// check South
while ((GuessP2[row + dir[1]][col] == 0
|| GuessP2[row + dir[1]][col] == 2) && row + dir[1] <=
10)
{
dir[1]++;
} // end while ((GuessP2[row - dir[1]][col] == 0 ||
GuessP2[row - dir[1]][col] == 2) && row - dir[1] >= 1)
// check East
while ((GuessP2[row][col + dir[2]] == 0
|| GuessP2[row][col + dir[2]] == 2) && col + dir[2] <=
10)
{
dir[2]++;
} // end while ((GuessP2[row][col + dir[2]] == 0 ||
GuessP2[row][col + dir[2]] == 2) && col + dir[2] <= 10)
// check West
while ((GuessP2[row][col + dir[3]] == 0
|| GuessP2[row][col + dir[3]] == 2) && col + dir[3] >=
1)
{
dir[3]++;
} // end while ((GuessP2[row][col + dir[3]] == 0 ||
GuessP2[row][col + dir[3]] == 2) && col + dir[3] <= 10)
int whichWay = 0;
int maxValue = 0;
int temp = 0;
for (int j = 0; j < 4; j++)
{
maxValue = 0;
for (int i = j; i < 4; i++)
{
if (dir[i] > maxValue)
{
maxValue = dir[i];
whichWay = i;
}
}
temp = directions[j];
directions[j] = directions[whichWay];
directions[whichWay] = temp;
temp = dir[j];
dir[j] = dir[whichWay];
dir[whichWay] = temp;
}
}
// For
void
smartComp (int GuessP2[11][11], bool p1isSunk[5],
int shipLengths[5], int &row, int &col)
{
int probabilityField[11][11] = { 0 };
bool possible;
for (int ship = 0; ship < 5; ship++)
{
if (p1isSunk[ship])
{
for (int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10 - (shipLengths[ship] - 1); j++)
{
possible = true;
for (int idx = 0; idx < shipLengths[ship]; idx++)
{
if (GuessP2[i][j + idx] == 1
|| GuessP2[i][j + idx] == 3)
{
possible = false;
break;
}
}
if (possible)
{
for (int idx = 0; idx < shipLengths[ship] / 2;
idx++)
{
probabilityField[i][j + idx] += idx + 1;
probabilityField[i][j + shipLengths[ship] - 1
-
idx] += idx + 1;
}
if (shipLengths[ship] % 2 == 1)
{
probabilityField[i][j + shipLengths[ship] / 2]
+=
shipLengths[ship] / 2 + 1;
}
}
}
}
}
}
// loop through each ship.
for (int ship = 0; ship < 5; ship++)
{
if (p1isSunk[ship])
{
// loop through each row.
for (int i = 1; i <= 10 - (shipLengths[ship] - 1); i++)
{
for (int j = 1; j <= 10; j++)
{
possible = true;
for (int idx = 0; idx < shipLengths[ship]; idx++)
{
if (GuessP2[i + idx][j] == 1
|| GuessP2[i + idx][j] == 3)
{
possible = false;
break;
} // end if (GuessP2[i + idx][j] == 1 ||
GuessP2[i + idx][j] == 3)
} // end for (int idx = 0; idx <
shipLengths[ship]; idx++)
if (possible)
{
// give the center of the possible ship location
priority
for (int idx = 0; idx < shipLengths[ship] / 2;
idx++)
{
probabilityField[i + idx][j] += idx + 1;
probabilityField[i + shipLengths[ship] - 1 -
idx][j] += idx + 1;
} // end for (int idx = 0; idx <
shipLengths[ship]; idx++)
if (shipLengths[ship] % 2 == 1)
{
probabilityField[i + shipLengths[ship] / 2][j]
+=
shipLengths[ship] / 2 + 1;
} // end if (shipLengths[ship] % 2 == 1)
} // end if(possible)
} // end for (int c = 1; c <= 10 -
(shipLengths[ship] - 1); c++)
} // end for (int r = 1; r <= 10; r++)
// break; // uncomment to only worry about the largest
possible ship
} // end if (p1isSunk[ship])
} // end for (int ship = 0; ship < 5; ship++)
// find the max value and randomly select one if there are
more than one.
vector < int >i_locs;
vector < int >j_locs;
// find the highest value
int maxValue = 0;
for (int i = 1; i < 11; i++)
{
for (int j = 1; j < 11; j++)
{
if (probabilityField[i][j] > maxValue && GuessP2[i][j]
!= 1
&& GuessP2[i][j] != 2 && GuessP2[i][j] != 3)
{
maxValue = probabilityField[i][j];
} // end if (probabilityField[i][j] > maxValue
&& GuessP2[i][j] != 1 && GuessP2[i][j] != 2 && GuessP2[i][j]
!= 3)
} // end for (int j = 1; j < 11; j++)
} // end for (int i = 1; i < 11; i++)
// find all the spots that have the highest value
for (int i = 1; i < 11; i++)
{
for (int j = 1; j < 11; j++)
{
if (probabilityField[i][j] == maxValue &&
GuessP2[i][j] == 0)
{
i_locs.push_back (i);
j_locs.push_back (j);
} // end if (probabilityField[i][j] == maxValue
&& GuessP2[i][j] == 0)
} // end for (int j = 1; j < 11; j++)
} // end for (int i = 1; i < 11; i++)
// randomly select one
int randNum = rand () % i_locs.size ();
row = i_locs.at (randNum);
col = j_locs.at (randNum);
} // end void smartComp(int GuessP2[11][11], bool
p1isSunk[5], int shipLengths[5], int &row, int &col)
void
displayCPUGuess (int row, int col)
{
// interpret the guess into something the user will understand
char letters[] = { ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
cout <<
"----------------------------------------------------------------------
-------------------------------------------------n";
cout << " The CPU guessed: " << letters[row] << col <<
"n";
} // end void displayCPUGuess(int row, int col)
bool
BSAI (string Board1[11][11], int GuessP2[11][11], bool
p1isSunk[5],
int shipLengths[5], int p1LocShip[5][4])
{
static bool Bombing = true; // state flag for remembering if
the cpu is Bombing for a ship.
static bool directionFound = false; // state flag for
remembering if the cpu has found the orientation of the ship
static bool bothDirections = false; // state flag for
remembering if the cpu has found the orientation of the ship and
checked both sides.
static int directions[4] = { 1, 2, 3, 4 }; // for guessing the
direction once a ship has been found.
static int row = 0, col = 0; // for remembering the last cpu
guess
static int idx = 0; // for remembering how far away from
the origin the cpu is now guessing.
static bool findMostProbable = true; // for determining if
you should calculate the most probable neighborhood shot
static int whichWay = 0; // for keeping track of which
neighborhoods have been shot at it.
static int dRow = 0, dCol = 0; // for guessing at ship
locations while no longer in hunt mode. *conserves original hit.
static int pursuingDirection = 0; // for keeping track of the
direction being pursued
static int checkingDirection = 0; // for keeping track of the
direction being checked.
/* when the orientation is found, pursuing will equal
checking */
if (Bombing)
{
for (int r = 0; r < 11; r++)
{
for (int c = 0; c < 11; c++)
{
if (GuessP2[r][c] == 2)
{
Bombing = false;
directionFound = false;
bothDirections = false;
findMostProbable = true;
for (int i = 0; i < 4; i++)
{
directions[i] = i + 1;
} // end for (int i = 0; i < 4; i++)
row = r;
col = c;
idx = 1;
whichWay = 0;
cout << " The CPU is moving on to the next
found ship.n";
if (BSAI
(Board1, GuessP2, p1isSunk, shipLengths,
p1LocShip))
{
return true;
} // end if (BSAI( Board1, GuessP2,
p1isSunk, shipLengths, p1LocShip))
else
{
return false;
} // end else: if (BSAI( Board1, GuessP2,
p1isSunk, shipLengths, p1LocShip))
} // end if (GuessP2[r][c] == 2)
} // end for (int c = 0; c < 11; c++)
} // end for (int r = 0; r < 11; r++)
// calculate the probability fields and choose a location to
guess -- updating row and col by
// pass by reference
smartComp (GuessP2, p1isSunk, shipLengths, row, col);
cout <<
"-------------------------------------------------------------------
----------------------------------------------------n";
cout << " The CPU is Bombing.n";
displayCPUGuess (row, col); // display the cpu's guess
if (Board1[row][col] == "S")
{
// the cpu hit a player's ship.
cout << " The CPU hit your ship!n";
Board1[row][col] = "X"; // update player 1's board
GuessP2[row][col] = 2; // update the cpu's guessing
matrix
Bombing = false; // the cpu is no longer Bombing!
idx = 1; // begin looking 1 away from the origin
// the cpu hit a ship, so check if that ship got sunk.
if (ShipSunk (p1LocShip, p1isSunk, Board1, 2,
GuessP2))
{
if (isGameOver (p1isSunk))
{
return true; // the game is over.
} // end if (isGameOver(p1isSunk))
// a ship was sunk, so reset the flags and begin
Bombing
Bombing = true;
directionFound = false;
bothDirections = false;
findMostProbable = true;
for (int i = 0; i < 4; i++)
{
directions[i] = i + 1;
} // end for (int i = 0; i < 4; i++)
} // end if (ShipSunk(p1LocShip, p1isSunk,
Board1, 2))
} // end if ( Board1[row][col] == "S")
else
{
// the cpu missed a player's ship
cout << " The CPU missed your ship!n";
Board1[row][col] = "O"; // update player 1's board
GuessP2[row][col] = 1; // update the cpu's guessing
matrix
} // end else: if ( Board1[row][col] == "S")
} // end if (Bombing)
else
{
if (directionFound)
{
// keep guessing until you find a new
// spot to guess.
do
{
// North
if (pursuingDirection == 1)
{
dRow = row - idx;
dCol = col;
} // end if (pursuingDirection == 1)
// South
else if (pursuingDirection == 2)
{
dRow = row + idx;
dCol = col;
} // end else if (pursuingDirection == 2)
// East
else if (pursuingDirection == 3)
{
dRow = row;
dCol = col + idx;
} // end else if (pursuingDirection == 3)
// West
else if (pursuingDirection == 4)
{
dRow = row;
dCol = col - idx;
} // end // end else if (pursuingDirection == 4)
// skip over previous guesses that
// hit a ship and the ship never sunk
if (GuessP2[dRow][dCol] == 2)
{
idx++;
} // end if (GuessP2[dRow][dCol] == 2)
// if the direction is a dead end swap directions
if (GuessP2[dRow][dCol] == 1 ||
GuessP2[dRow][dCol] == 3)
{
if (bothDirections)
{
cout <<
"-------------------------------------------------------
----------------------------------------------------------------n";
cout << " The CPU found multiple touching
ships.n";
directionFound = false;
bothDirections = false;
whichWay++;
idx = 1;
for (int i = 0; i < 4; i++)
{
directions[i] = i + 1;
} // end for (int i = 0; i < 4; i++)
if (BSAI
(Board1, GuessP2, p1isSunk, shipLengths,
p1LocShip))
{
return true;
} // end if (BSAI(
Board1,GuessP2,p1isSunk,shipLengths,p1LocShip))
else
{
return false;
} // end else: if (BSAI(
Board1,GuessP2,p1isSunk,shipLengths,p1LocShip))
} // end if (bothDirections)
else
{
bothDirections = true;
if (pursuingDirection % 2 == 1)
{
pursuingDirection++;
idx = 1;
} // end if (pursuingDirection % 2 == 1)
else
{
pursuingDirection--;
idx = 1;
} // end else: if (pursuingDirection % 2 == 1)
} // end else: if (bothDirections)
} // end if (GuessP2[dRow][dCol] == 1 ||
GuessP2[dRow][dCol] == 3)
}
while (GuessP2[dRow][dCol] != 0);
cout <<
"----------------------------------------------------------------
-------------------------------------------------------n";
if (pursuingDirection == 1)
{
cout << " The CPU is pursuing North.n";
} // end if (pursuingDirection == 1)
else if (pursuingDirection == 2)
{
cout << " The CPU is pursuing South.n";
} // end else if (pursuingDirection == 2)
else if (pursuingDirection == 3)
{
cout << " The CPU is pursuing East.n";
} // end else if (pursuingDirection == 3)
else if (pursuingDirection == 4)
{
cout << " The CPU is pursuing West.n";
} // end else if (pursuingDirection == 4)
displayCPUGuess (dRow, dCol); // display the cpu's
guess
if (Board1[dRow][dCol] == "S")
{
// the cpu hit a player's ship.
cout << " The CPU hit your ship!n";
Board1[dRow][dCol] = "X"; // update player 1's
board
GuessP2[dRow][dCol] = 2; // update the cpu's
guessing matrix
idx++; // begin looking 1 away from the origin
directionFound = true; // the cpu has discovered
the orientation
// the cpu hit a ship, so check if that ship got sunk.
if (ShipSunk
(p1LocShip, p1isSunk, Board1, 2, GuessP2))
{
if (isGameOver (p1isSunk))
{
return true; // the game is over.
} // end if (isGameOver(p1isSunk))
// a ship was sunk, so reset the flags and begin
Bombing
Bombing = true;
directionFound = false;
bothDirections = false;
findMostProbable = true;
for (int i = 0; i < 4; i++)
{
directions[i] = i + 1;
} // end for (int i = 0; i < 4; i++)
} // end if (ShipSunk(p1LocShip, p1isSunk,
Board1, 2))
} // end if ( Board1[dRow][dCol] == "S")
else if (Board1[dRow][dCol] == " ")
{
// the cpu missed a player's ship
cout << " The CPU missed your ship!n";
Board1[dRow][dCol] = "O"; // update player 1's
board
GuessP2[dRow][dCol] = 1; // update the cpu's
guessing matrix
} // end else: if ( Board1[dRow][dCol] == "S")
} // end if (directionFound)
else
{
if (findMostProbable)
{
BombingMostProbable (GuessP2, row, col,
directions);
findMostProbable = false;
whichWay = 0;
} // end if (findMostProbable)
do
{
checkingDirection = directions[whichWay];
// North
if (checkingDirection == 1)
{
dRow = row - idx;
dCol = col;
} // end if (checkingDirection == 1)
// South
else if (checkingDirection == 2)
{
dRow = row + idx;
dCol = col;
}
else if (checkingDirection == 3)
{
dRow = row;
dCol = col + idx;
}
else if (checkingDirection == 4)
{
dRow = row;
dCol = col - idx;
}
if (dRow >= 1 && dRow <= 10 && dCol >= 1 &&
dCol <= 10)
{
if (GuessP2[dRow][dCol] != 0)
{
whichWay++;
}
}
else
{
whichWay++;
}
}
while (GuessP2[dRow][dCol] != 0);
cout <<
"----------------------------------------------------------------
-------------------------------------------------------n";
if (checkingDirection == 1)
{
cout << " The CPU is checking North.n";
}
else if (checkingDirection == 2)
{
cout << " The CPU is checking South.n";
} // end else if (checkingDirection == 2)
else if (checkingDirection == 3)
{
cout << " The CPU is checking East.n";
} // end else if (checkingDirection == 3)
else if (checkingDirection == 4)
{
cout << " The CPU is checking West.n";
} // end else if (checkingDirection == 4)
displayCPUGuess (dRow, dCol); // display the cpu's
guess
if (Board1[dRow][dCol] == "S")
{
cout << " The CPU hit your ship!n";
cout << " The CPU has entered Destroyer Mode.n";
Board1[dRow][dCol] = "X";
GuessP2[dRow][dCol] = 2;
idx++;
directionFound = true;
pursuingDirection = checkingDirection;
if (ShipSunk
(p1LocShip, p1isSunk, Board1, 2, GuessP2))
{
if (isGameOver (p1isSunk))
{
return true;
}
Bombing = true;
directionFound = false;
bothDirections = false;
findMostProbable = true;
for (int i = 0; i < 4; i++)
{
directions[i] = i + 1;
}
}
}
else if (Board1[dRow][dCol] == " ")
{
cout << " The CPU missed your ship!n";
Board1[dRow][dCol] = "O";
GuessP2[dRow][dCol] = 1;
}
}
}
return false;
}
void endPrintBoard (string Board1[11][11], string
Display1[11][11],
string Board2[11][11], string Display2[11][11],
string GuessP1[11][11])
{
cout <<
"----------------------------------------------------------------------
-------------------------------------------------n";
cout << "|" <<
" CPU Game Board
Your Game Board "
<< "|n";
cout <<
"----------------------------------------------------------------------
-------------------------------------------------n";
cout <<
"|
|n";
for (int r = 0; r < 11; r++)
{
cout << "|t";
for (int c = 0; c < 11; c++)
{
if (r == 0)
{
cout << Board2[r][c] << " ";
}
else
{
if (Board2[r][c] == "S")
{
cout << Display2[r][c] << " | ";
} // end if ( Board2[r][c] == "S"
else if (Board2[r][c] == "X")
{
cout << Display2[r][c] << " | ";
} // end else if ( Board2[r][c] == "X")
else if (GuessP1[r][c] == "O")
{
cout << GuessP1[r][c] << " | ";
}
else if (Board2[r][c] == " ")
{
cout << Board2[r][c] << " | ";
}
else
{
cout << Board2[r][c] << " | ";
} // end else
}
}
cout << "tt";
for (int c = 0; c < 11; c++)
{
if (r == 0)
{
cout << Board1[r][c] << " ";
}
else
{
if (Board1[r][c] == "S")
{
cout << Display1[r][c] << " | ";
}
else if (Board1[r][c] == "X")
{
cout << Display1[r][c] << " | ";
}
else if (Board1[r][c] == "O")
{
cout << Board1[r][c] << " | ";
}
else if (Board1[r][c] == " ")
{
cout << Board1[r][c] << " | ";
}
else
{
cout << Board1[r][c] << " | ";
}
}
}
if (r == 0)
{
cout << " |";
}
else
{
cout << " |";
}
cout <<
"n| t ----------------------------------------- tt -------------
---------------------------- |n";
} // end for (int r = 0; r < 11; r++)
cout <<
"|
|";
cout <<
"n--------------------------------------------------------------------
---------------------------------------------------n";
}
void
setDisplayBoard (string board[11][11], int locs[5][4])
{
string shipNames[5] = { "A", "B", "C", "S", "D" };
for (int s = 0; s < 5; s++)
{
for (int r = locs[s][0]; r <= locs[s][2]; r++)
{
for (int c = locs[s][1]; c <= locs[s][3]; c++)
{
board[r][c] = shipNames[s];
}
}
}
}
__MACOSX/._main.cpp
Running Head: METHODOLOGY OUTLINE INSTRUCTION
1
METHODOLOGY OUTLINE INSTRUCTION 5
Methodology Outline Instructions
Carrington Sherman
HCS/542 - HEALTH CARE RESEARCH
Instructor: HARRIET BAGGETT
March 2,2018
A quantitative methodology outline
1. Identified target population
· The target population of this research is the men and women
with obesity in the Southern Cone of America.
· The targeted towns include Marcos Paz and Bariloche in
Argentina, the Uruguays Pando-Barros Blancos and Temuco city
in Chile.
2. Your specific sample of participants:
· What/who will comprise your sample(s)?
i. The sampled population will be people with records of obese.
ii. The sample size comprises 7,524 obese people (3165 men
and 4359 women) within the age bracket of between 35 and 74
years old.
· Where will you find them?
i. The sample population will be sampled from the towns of
Southern Cone of America.
ii. These includes the Marcos Paz and Bariloche in Argentina,
the Uruguays Pando-Barros Blancos and Temuco city in Chile.
· How large will your sample(s) be?
i. The sample size will be 10,254 randomly selected individuals.
· What is your rationale for these decisions?
i. The larger the sample the better to increase the degree of
confidence and reduce errors due to the respondents behavior.
ii. The number will cater for those who will refuse to take part,
those who will not complete the survey, and those who will not
complete clinical examinations (Ormston et al., 2014).
3. Method for getting the data from the sample:
· How will you recruit the subjects?
i. Subjects will be recruited randomly in the towns identified
after seeking the participants consent (Meadows, 2003).
ii. Random sampling will not observe gender stratification
(Meadows, 2003).
· What general process will you use to collect the data? (e.g.,
where will you collect it? Who will collect it? Etc. What is
the process you and the participant will go through so you can
get the data, in other words?)
i. Data will be collected using a multiple of data collection
tools.
ii. There shall be home visits entailing surveys to collect
demographic characteristics of the participant, healthcare
access, (Cardiovascular diseases) CVD and risk factors personal
history, their physical activity and Dietary History.
iii. There shall also be clinical visits to collect Anthropometric
measurements like blood pressure, body weight, waist
circumference and height (Meadows, 2003).
· What specific independent and dependent variables will you
be studying, and how specifically will you measure those
variables?
i. The independent variables in this study will include the race
(black American and the whites) and CVD risk factors.
ii. The dependent variables will include the overweight, obesity
and central obesity in the Southern Cone of Latin America.
iii. Dependent variables will be measured clinically using set of
anthropometric protocols and techniques. For instance, BP
measured using a standard mercury or aneroid
sphygmomanometer, Body weight using standing scales and
body height without shoes using a wall-mounted stadiometer
and waist circumference measured in centimeters above the
navel during minimal respiration (Meadows, 2003).
· What comparison groups will you have, if any?
i. Will compare the cardiovascular diseases of the whites and
the black Americans, and other races like the Hispanic.
ii. Male and female obese, overweight and central obesity
comparison will be done
· What instruments or measurements will you use to get the
data?
i. The questionnaires will be used to obtain participants
demographic and personal characteristics (Ormston et al.,
2014).
ii. Anthropometric measurements will be done using clinically
approved protocols and techniques.
iii. The overnight fasting blood creatinine, lipids and glucose
levels will be measured
iv. Again, the total and HDL-cholesterol and triglycerides will
be measured too.
· How did you decide on these particular groups, instruments or
measurements?
i. The decision to use these groups was derived from the theory
of prevalence of obesity among whites than the blacks and
minorities in America.
ii. The use of protocols and set techniques for Anthropometric
measurements were chosen for clinical procedures (Meadows,
2003).
iii. Structured questionnaires were used to collect demographic
characteristics because of the nature of data (qualitative)
inclusivity of data collected and validity of the data collected
(Ormston et al., 2014).
4. Ethical Considerations and Steps for your proposed study,
based on our prior weeks' materials
· The participants are required to first agree on a written
consent for participation.
· Participants’ personal information will be confidential and
private from third parties.
· Participants anonymity for the sake of research findings
· Information obtained shall be distributed freely (Ormston et
al., 2014).
References
Meadows, K. A. (2003). So you want to do research? 2:
developing the research question. British journal of community
nursing, 8(9), 397-403.
Ormston, R., Spencer, L., Barnard, M., & Snape, D. (2014). The
foundations of qualitative research. Qualitative research
practice: A guide for social science students and researchers, 1-
26.
1
2
Week 2 Assignment ResearchStudy Proposal–Part I: Problem
Statement
Carrington Sherman
HCS 542 Health Care Research
March 12, 2018
University of Phoenix
Study Proposal–Part I: Problem Statement
Why are southern who live in the southern states like Texas,
Louisiana, Mississippi, Alabama, and Georgia have higher
obesity rates compared to other state in different region. Is it
because of lack of education for health diets or, does it has to
deal with the culture and in environment they reside in?
Majority of the population who are overweight live in urban
areas where there are predominantly lower income families
homes (Obesity Epidemic).
What is obesity, it is defined as when a person body fat total is
30 percent are higher (Adolescent obesity) . Which causes stress
on the joints, back, and feet some people may even have trouble
berthing. The two main populations that this disease affects the
most are white and black in lower income family homes that
live in the urban areas. Most of the time if people don’t know
any better so they will continue to do the same thing because
that is all they know. Due to everyone been a creatures of habit
it is very difficult to change someone who no intention to
change.
In 2014 “For the second year in a row, Mississippi had the
highest obesity rate, with 35.2% of residents classified as obese
according to residents' self-reported height and weight”(Obesity
Rates).It also indicated that number was still on the up raise and
will continue to increase. Due to them understand that the way
they grew up is all that they know. You always hear about how
the food is just so flavorful and delicious in the southern state.
You may also see the result of what good food can do to you
and your health as well as your body. Just because the food
tastes great and it makes you want to eat more doesn’t necessary
mean that it’s good for you. Most people would like to think
that but that is not the case.
Health education can change life style and the way people eat
.For explain if you told someone if they continue to eat
unhealthy and not exercise they would they would die everyone
gym membership would be sky high just because of the fear the
someone has left on the mind. Also, your live environment plays
a major role in what type of health you will have. If you live in
a descent home you will probably have descent health as well if
you live in a rough a poor neighborhood you are most like to
receive help form the government. Sometime you make not
quality for government assistance even though they’re still
poor.
References:
Conway, B. N., Han, X., Munro, H. M., Gross, A. L., Xiao-Ou,
S., Hargreaves, M. K., . . . Blot, W. J. (2018). The obesity
epidemic and rising diabetes incidence in a low-income racially
diverse southern US cohort. PLoS
One, 13(1)http://dx.doi.org.contentproxy.phoenix.edu/10.1371/j
ournal.pone.0190993 Retrieved from https://search-proquest-
com.contentproxy.phoenix.edu/docview/1986672403?accountid
=134061
McCarthy, Justin, and Diana Liu. "Obesity Rate Lowest in
Hawaii, Highest in Mississippi." Gallup Poll News Service, 26
May 2015. Opposing Viewpoints in Context,
http://link.galegroup.com.contentproxy.phoenix.edu/apps/doc/A
416344500/OVIC?u=uphoenix_uopx&xid=cbfbf7ce. Accessed
12 Mar. 2018.
Koehly, L. M., & Loscalzo, A. (2009). Adolescent Obesity and
Social Networks. Preventing Chronic Disease, 6(3), A99.
Running Head: OBESITY EPIDEMIC IN SOUTH U. S STATES
1
OBESITY EPIDEMIC IN SOUTH U. S STATES
2
Obesity Epidemic Southern U. S States
Carrington Sherman
Name of Institution
Why are southern who live in the southern states like Texas,
Louisiana, Mississippi, Alabama, and Georgia have higher
obesity rates compared to other state in different region. Is it
because of lack of education for health diets or, does it has to
deal with the culture and in environment they reside in?
Majority of the population who are overweight live in urban
areas where there are predominantly lower income families
homes (Obesity Epidemic).
In-text citation
Study design
Sample size and description
Independent and dependent variables
Key findings
Study method strengths
Study method weakness
Further research needs
· Conway et al., 2018).
· The study design in this research is the Cohort Study
· The sample size was 24,000 black Americans and 14,064 white
adults sampled
· The individuals’ were of age between 40–79 years
· The samples were from underserved populations in the 12-
state span that included Alabama, Florida, Arkansas, Georgia,
Louisiana, Kentucky, Mississippi, South Carolina, North
Carolina, Tennessee, West Virginia and Virginia.
· The dependent variables included the racial difference in the
population in U. S including the blacks Americans and the
whites.
· The gaps in diabetes, cardiovascular, cancer and other chronic
diseases were also dependent factor on the race, economic
status and the age of the participants in the population.
· The independent variables included the races that are the
African Americans and whites. Change in time was also
independent because it did not rely on any factor in the
population to vary but determined the extend of variation of the
prevalence of the obesity, physical inactivity and diabetes
· Risk of obesity and diabetes monotonically increased with
increasing BMI and varied between blacks and whites.
· Diabetes incidences doubled in black populations than among
the whites who had normal BMI.
· Racial difference became weak as the BMI increased among
the populations
· The increase in the BMI remained a predominant risk factor
among blacks and whites.
· One, cohort study presents a clear temporal Sequence of
outcomes against exposures over time
· Two, it allows Calculation of the incidence in terms of
absolute and relative risks.
· Three, it facilitates study of rare exposures and multiple
effects of an exposure. The study design will be able to single
out the effect of every exposure to a factor and also combine the
several effects due to every exposure on the factor that causes
variation in the variables.
· Time consuming because it involving following up a
phenomenon for a long time observing and recording incidences
· It is also very expensive due to the length of time involved
and the amount of data collection done.
· It is affected by many unforeseen factors in the field. As the
field dynamics changes, the factors affecting the study may
change and so will require new techniques or modification of
the existing techniques.
· It needs studies of variables that have long latency which will
enable recording of the observations consistently without
termination
· The role of treatment of obesity in checking diabetes
incidence.
· Study need to be done to include individuals with multiple
chronic diseases in the population.
· Sequential collection of data using uniform standardized
methods and personnel its needed too to enhance data collection
I cohort studies like this.
· Research question: Does the high incidences of obesity reflect
on the high rate of incidence of diabetic incidence in the
population of southern states of U. S?
· Lanas et al., 2016).
· The study design in this research is the CESCAS I study
design - is an observational and prospective cohort study
· The sample size was of 7,524 women and men aged between
35 and 74 years old. They were sampled from all the 4 cities of
Southern Cone of Latin
America which included Bariloche and Marcos Paz in
Argentina, Temuco city in Chile, and Pando-Barros Blancos in
Uruguay. Marcos Paz and Pando-Barros Blancos had population
size of 54,000 and 58,000 respectively, Bariloche and Temuco
had 134,000 and 245,000 respectively. the study sites had been
selected based on the characteristics of the population reflecting
the country averages.
· Dependent variables height, weight, sex, education, household
income, occupation and healthcare access.
· Independent variables included age groups and gender. The
age group varied from 35 years to 74 in the interval of five
years per group.
· Women prevalence of obesity and central obesity were higher
compared to men.
· Education level increased the prevalence of obesity, physical
inactivity and diabetes further.
· It is very concrete in digging out information.
· It is comprehensive and inclusive in data collection and
analysis that results to conclusion drawing and reliability of the
results for generalization on the entire population
· It needs capacity building before carrying out data collection
· It is expensive design and time consuming due to the longer
time involved in data collection and tools and protocols used to
collect and analyze data
· The role of education on the increased prevalence of obesity
should be studied. This will dig out the fundamental aspects of
education that influence risks of obesity and how it can be used
to check prevalence of obesity.
· Research question: what is the impact of increased educational
level among the individuals on the incidence of obesity rates in
southern states of U. S?
· Geiss et al., 2017).
· The study design in this research is the Bayesian multilevel
telephone survey modeling techniques and census
· The sample size was 400,000 adults in 50 U. S states
involving the 3143 counties.
· Time was the independent variable (2004 to 2012.
· The dependent variables were prevalence of diagnosed
diabetes, obesity, and individuals’ physical inactivity. These are
the variables that depended on the time and the regions in the
southern U. S.
· Low median average annual percentage point changes (APPCs)
of obesity, diabetes, and physical inactivity in 2008–2012
compared to 2004-2008.
· APPCs varied among counties in U. S and regions.
· APPC differences between two periods also varied in both the
blacks and the whites.
· Bayesian method can accommodate all unobserved variables
and also is a powerful tool for incorporating previous
information and controlling confounding.
· Census surveys increasing the confidence interval of the data
collected due to large participants, it also provides a chance for
identifying and attending to negative feedback.
· Bayesian method requires in-depth understanding of the design
and implementation. It is best for large computational studies.
· Census surveys limits other studies on the same population
and also takes a longer time to collect information
· There is need to be a study to estimate the effect of geographic
patterns, and physical inactivity on obesity and diabetes.
· Continuous data collection systems should be set to ensure
continuous standardizes data collection and storage
· Research question: does geographic variability, nutritional
awareness and income status reduces the incidence of obesity
significantly in southern States of U. S?
References
Conway, B. N., Han, X., Munro, H. M., Gross, A. L., Shu, X.
O., Hargreaves, M. K., ... & Blot, W. J. (2018). The obesity
epidemic and rising diabetes incidence in a low-income racially
diverse southern US cohort. PloS one, 13(1), e0190993.
Geiss, L. S., Kirtland, K., Lin, J., Shrestha, S., Thompson, T.,
Albright, A., & Gregg, E. W. (2017). Changes in diagnosed
diabetes, obesity, and physical inactivity prevalence in US
counties, 2004-2012. PloS one, 12(3), e0173428.
Lanas, F., Bazzano, L., Rubinstein, A., Calandrelli, M., Chen,
C. S., Elorriaga, N., ... & Poggio, R. (2016). Prevalence,
Distributions and Determinants of Obesity and Central Obesity
in the Southern Cone of America. PloS one, 11(10), e0163727.
Retrieved from:
http://journals.plos.org/plosone/article?id=10.1371/journal.pone
.0163727

Grid.h#ifndef grid_h#define grid_h#includeGame.hvoid.docx

  • 1.
    Grid.h #ifndef grid_h #define grid_h #include"Game.h" voidprintBoardInput (string gameBoard[11][11], string Display1[11][11]); void printBoard (string GuessP1[11][11], string Board1[11][11],string Display1[11][11], int GuessP2[11][11]); string Board1[11][11] = { {" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, {"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "} }; // will display a "O" for guesses that didn't hit a ship. // will display a "X" for guesses that did. string GuessP1[11][11] = { {" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, {"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "},
  • 2.
    {"E", " "," ", " ", " ", " ", " ", " ", " ", " ", " "}, {"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "} }; string Display1[11][11] = { {" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, {"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "} }; string Board2[11][11] = { {" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, {"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
  • 3.
    }; string Display2[11][11] ={ {" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, {"A", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"C", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"D", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"E", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"F", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"G", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"H", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"I", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}, {"J", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "} }; #endif /* grid_h */ __MACOSX/._Grid.h Game.h #ifndef Game_h #define Game_h #include<iostream> #include<vector> using namespace std; void endPrintBoard (string Board1[11][11], string Display1[11][11],string Board2[11][11], string Display2[11][11],string GuessP1[11][11]); bool stringInterpreter (vector < char >LocShips, int &row1, int &Column1); void setLocShips (string Board1[11][11], int ships, int
  • 4.
    shipLengths[5],int p1LocShipss[5][4], stringDisplay1[11][11]); void setP2ShipLocs (string Board2[11][11], int p2LocShipss[5][4],int shipLengths[5]); bool ShipSunk (int shipLocs[5][4], bool isSunk[5], string board[11][11],int turn); bool ShipSunk (int shipLocs[5][4], bool isSunk[5], string board[11][11],int turn, int GuessP2[11][11]); bool chooseTile (string Board1[11][11], string Board2[11][11],string GuessP1[11][11], int p2LocShipss[5][4],bool p2isSunk[5], string Display1[11][11],int GuessP2[11][11]); void getP1ShipLocs (string Board1[11][11], int shipLengths[],int p1LocShipss[5][4], string Display1[11][11]); void BombingMostProbable (int GuessP2[11][11], int row, int col,int directions[4]); void smartComp (int GuessP2[11][11], bool p1isSunk[5],int shipLengths[5], int &row, int &col); void displayCPUGuess (int row, int col); bool BSAI (string Board1[11][11], int GuessP2[11][11],bool p1isSunk[5], int shipLengths[5],int p1LocShipss[5][4]); void setDisplayBoard (string board[11][11], int locs[5][4]); #endif /* Game_h */ __MACOSX/._Game.h
  • 5.
    main.cpp #include <iostream> #include <string> #include<time.h> #include <vector> #include <stdlib.h> #include "Game.h" #include "Grid.h" using namespace std; int main () { srand (unsigned (time (NULL))); int GuessP2[11][11] = { 0 }; int p1LocShip[5][4]; // array with player 1 ship locations [ r1 c1 r2 c2 ] int p2LocShip[5][4]; // array with player 2 ship locations [ r1 c1 r2 c2 ] int shipLengths[5] = { 5, 4, 3, 3, 2 }; // remember the length of each ship. // if true, the ship is still alive. bool p1isSunk[5] = { true, true, true, true, true }; bool p2isSunk[5] = { true, true, true, true, true }; // A B C S D // get the user's ship locations getP1ShipLocs (Board1, shipLengths, p1LocShip, Display1); // set the CPU's ship locations setP2ShipLocs (Board2, p2LocShip, shipLengths);
  • 6.
    // set theCPU display board based on the ship locations setDisplayBoard (Display2, p2LocShip); // begin play int turn = 1; // keep track of whose turn it is while (true) { if (turn == 1) { if (chooseTile (Board1, Board2, GuessP1, p2LocShip, p2isSunk, Display1, GuessP2)) { cout << "n----------------------------------------------------------- ------------------------------------------------------------n"; cout << "| You Win! |"; endPrintBoard (Board1, Display1, Board2, Display2, GuessP1); return 0; } // end if (chooseTile(GuessP1, Board2, userGuess)) turn = 2; // CPU's turn } // end if (turn == 1) else { if (BSAI (Board1, GuessP2, p1isSunk, shipLengths, p1LocShip))
  • 7.
    { cout << "n----------------------------------------------------------- ------------------------------------------------------------n"; cout << "|You Lose! |"; endPrintBoard (Board1, Display1, Board2, Display2, GuessP1); return 0; } turn = 1; } } } void printBoardInput (string gameBoard[11][11], string Display1[11][11]) { for (int r = 0; r < 11; r++) { for (int c = 0; c < 11; c++) { if (r == 0) { cout << gameBoard[r][c] << " "; } else { if (gameBoard[r][c] == "S") {
  • 8.
    cout << Display1[r][c]<< " | "; } else if (gameBoard[r][c] == " ") { cout << gameBoard[r][c] << " | "; } else { cout << gameBoard[r][c] << " | "; } } } cout << "n -----------------------------------------n"; } } void printBoard (string GuessP1[11][11], string Board1[11][11], string Display1[11][11], int GuessP2[11][11]) { cout << "---------------------------------------------------------------------- -------------------------------------------------n"; cout << "|" << " YOUR GUESSES YOUR SHIPS/CPU GUESSES " << "|n"; cout << "---------------------------------------------------------------------- -------------------------------------------------n"; cout << "| |n"; for (int r = 0; r < 11; r++) {
  • 9.
    cout << "|t"; for(int c = 0; c < 11; c++) { if (r == 0) { cout << GuessP1[r][c] << " "; } // end if (r == 0) else { if ((GuessP1[r][c] == "X" || GuessP1[r][c] == "A" || GuessP1[r][c] == "B" || GuessP1[r][c] == "C" || GuessP1[r][c] == "S" || GuessP1[r][c] == "D") && c > 0) { cout << GuessP1[r][c] << " | "; } else if (GuessP1[r][c] == "O") { cout << GuessP1[r][c] << " | "; } // end else if (GuessP1[r][c] == "O") else if (GuessP1[r][c] == " ") { cout << GuessP1[r][c] << " | "; } else { cout << GuessP1[r][c] << " | "; } } } cout << "tt"; for (int c = 0; c < 11; c++) { if (r == 0) { cout << Board1[r][c] << " ";
  • 10.
    } else { if (Board1[r][c] =="S") { cout << Display1[r][c] << " | "; } else if (Board1[r][c] == "X") { if (GuessP2[r][c] == 2 || GuessP2[r][c] == 3) { cout << Display1[r][c] << " | "; } else { cout << Display1[r][c] << " | "; } } else if (Board1[r][c] == "O") { cout << Board1[r][c] << " | "; } else if (Board1[r][c] == " ") { cout << Board1[r][c] << " | "; } else { cout << Board1[r][c] << " | "; } } } if (r == 0) { cout << " |"; } // end if (r == 0)
  • 11.
    else { cout << "|"; } // end else: if (r == 0) cout << "n| t ----------------------------------------- tt ------------- ---------------------------- |n"; } // end for (int r = 0; r < 11; r++) cout << "| |"; cout << "n-------------------------------------------------------------------- ---------------------------------------------------n"; } bool stringInterpreter (vector < char >LocShips, int &row1, int &Column1) { if (LocShips.size () < 2) { cout << " Mistakes were made. Try Again.n Inputs must be a Letter(A - J) followed by a Number(1 - 10).nn"; return true; } if (LocShips[0] == 'A' || LocShips[0] == 'a') { row1 = 1; } else if (LocShips[0] == 'B' || LocShips[0] == 'b') {
  • 12.
    row1 = 2; } elseif (LocShips[0] == 'C' || LocShips[0] == 'c') { row1 = 3; } else if (LocShips[0] == 'D' || LocShips[0] == 'd') { row1 = 4; } else if (LocShips[0] == 'E' || LocShips[0] == 'e') { row1 = 5; } else if (LocShips[0] == 'F' || LocShips[0] == 'f') { row1 = 6; } else if (LocShips[0] == 'G' || LocShips[0] == 'g') { row1 = 7; } else if (LocShips[0] == 'H' || LocShips[0] == 'h') { row1 = 8; } else if (LocShips[0] == 'I' || LocShips[0] == 'i') { row1 = 9; } else if (LocShips[0] == 'J' || LocShips[0] == 'j') { row1 = 10; } else {
  • 13.
    cout << " Mistakeswere made. Try Again.n Inputs must be a Letter(A-J) followed by a Number(1-10).nn"; return true; } if (LocShips.size () < 3) { if (LocShips[1] == '1') { Column1 = 1; } else if (LocShips[1] == '2') { Column1 = 2; } else if (LocShips[1] == '3') { Column1 = 3; } else if (LocShips[1] == '4') { Column1 = 4; } else if (LocShips[1] == '5') { Column1 = 5; } else if (LocShips[1] == '6') { Column1 = 6; } else if (LocShips[1] == '7') { Column1 = 7;
  • 14.
    } else if (LocShips[1]== '8') { Column1 = 8; } else if (LocShips[1] == '9') { Column1 = 9; } else { cout << " Mistakes were made.Try Again.n Inputs must be a Letter(A - J) followed by a Number(1 - 10).nn"; return true; } } else if (LocShips.size () == 3) { if (LocShips[1] == '1' && LocShips[2] == '0') { Column1 = 10; } else { cout << " Mistakes were made.Try Again.n Inputs must be a Letter(A - J) followed by a Number(1 - 10).nn"; return true; } } else { cout << " Mistakes were made.Try Again.n Inputs must be a Letter(A - J) followed by a Number(1 - 10).nn";
  • 15.
    return true; } return false; } void setLocShips(string Board1[11][11], int ships, int shipLengths[5], int p1LocShip[5][4], string Display1[11][11]) { string LocShips; int row1, Column1; int row2, Column2; int temp; vector < char >location1; vector < char >location2; bool secondString; bool shipsIntersected; static int p1Ships = 0; while (true) { LocShips = " "; cout << "Please place your " << shipLengths[ships] << "- tile ship: "; cin >> LocShips; secondString = false; for (int idx = 0; idx < LocShips.size (); idx++) { if (!secondString) {
  • 16.
    if (LocShips[idx] =='-') { secondString = true; } else { location1.push_back (LocShips[idx]); } } else { location2.push_back (LocShips[idx]); } } if (!secondString) { cout << " Input must be LetterNumber- LetterNumber.n"; location1.clear (); location2.clear (); continue; } if (stringInterpreter (location1, row1, Column1)) { location1.clear (); location2.clear (); continue; } if (stringInterpreter (location2, row2, Column2)) { location1.clear (); location2.clear (); continue; }
  • 17.
    if (row1 !=row2 && Column1 != Column2) { cout << " The ships are one dimensional. Try again.n"; location1.clear (); location2.clear (); continue; } if (row1 == row2) { if (Column2 < Column1) { temp = Column1; Column1 = Column2; Column2 = temp; } // end if (Column2 < Column1) if ((Column2 - Column1 + 1) != shipLengths[ships]) { cout << " Your input was not the correct size. Try again.n"; location1.clear (); // if it isn't, clear the vectors location2.clear (); continue; } } else { if (row2 < row1) { temp = row1; row1 = row2; row2 = temp;
  • 18.
    } if ((row2 -row1 + 1) != shipLengths[ships]) { cout << " Your input was not the correct size. Try again.n"; location1.clear (); location2.clear (); continue; } } shipsIntersected = false; for (int r = row1; r <= row2; r++) { for (int c = Column1; c <= Column2; c++) { if (Board1[r][c] == "S") { shipsIntersected = true; cout << " Ships may not intersect. Try Again.n"; location1.clear (); location2.clear (); break; } } if (shipsIntersected) { break; } } if (shipsIntersected) { continue; } break; }
  • 19.
    for (int r= row1; r <= row2; r++) { for (int c = Column1; c <= Column2; c++) { Board1[r][c] = "S"; } } string shipNames[5] = { "A", "B", "C", "S", "D" }; for (int r = row1; r <= row2; r++) { for (int c = Column1; c <= Column2; c++) { Display1[r][c] = shipNames[p1Ships]; } } int shipLocs[4] = { row1, Column1, row2, Column2 }; if (p1Ships < 5) { for (int i = 0; i < 4; i++) { p1LocShip[p1Ships][i] = shipLocs[i]; } // for (int i = 0; i < 4; i++) p1Ships++; } // if (p1Ships < 5) } void setP2ShipLocs (string Board2[11][11], int p2LocShip[5][4], int shipLengths[5]) { int max[] = { 6, 5, 4, 4, 3 };
  • 20.
    bool isPlaced =false; int row = 0; int col = 0; enum direction { horizontal, vertical }; direction whichWay; for (int ships = 0; ships < 5; ships++) { while (!isPlaced) { isPlaced = true; whichWay = (rand () % 2 == 0) ? horizontal : vertical; if (whichWay == horizontal) { col = 1 + rand () % max[ships]; row = 1 + rand () % 10; for (int c = col; c < col + (11 - max[ships]); c++) { if (Board2[row][c] == "S") { isPlaced = false; break; } } } else { row = 1 + rand () % max[ships]; col = 1 + rand () % 10; for (int r = row; r < row + (11 - max[ships]); r++)
  • 21.
    { if (Board2[r][col] =="S") { isPlaced = false; break; } } } } isPlaced = false; if (whichWay == horizontal) { for (int c = 0; c < max[ships] - 1; c++) { Board2[row][col + c] = 'S'; } // end for (int c = 0; c < maxGuess - 1; c++) p2LocShip[ships][0] = row; p2LocShip[ships][1] = col; p2LocShip[ships][2] = row; p2LocShip[ships][3] = col + shipLengths[ships] - 1; } // end if (whichWay == horizontal) else { for (int r = 0; r < max[ships] - 1; r++) { Board2[row + r][col] = 'S'; } // end for (int r = 0; r < maxGuess - 1; r++) p2LocShip[ships][0] = row; p2LocShip[ships][1] = col; p2LocShip[ships][2] = row + shipLengths[ships] - 1; p2LocShip[ships][3] = col; } } } bool
  • 22.
    ShipSunk (int shipLocs[5][4],bool isSunk[5], string board[11][11], int turn, string GuessP1[11][11]) { // determine if the ship is sunk during player 1's turn bool shipSunk = true; for (int ship = 0; ship < 5; ship++) { if (isSunk[ship]) { shipSunk = true; for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) { for (int c = shipLocs[ship][1]; c <= shipLocs[ship][3]; c++) { if (board[r][c] == "S") { shipSunk = false; break; } } if (!shipSunk) { break; } // end if (!shipSunk) } // end for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) if (shipSunk) { isSunk[ship] = false; string shipNames[5] = { "A", "B", "C", "S", "D" };
  • 23.
    for (int r= shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) { for (int c = shipLocs[ship][1]; c <= shipLocs[ship][3]; c++) { GuessP1[r][c] = shipNames[ship]; } } if (turn == 1) { cout << " You sunk the computer's "; } // end if (turn == 1) else { cout << " The CPU sank your "; } // end else: if (turn == 1) switch (ship) { case 0: cout << "Aircraft Carrier!n"; break; case 1: cout << "Battleship!n"; break; case 2: cout << "Cruiser!n"; break; case 3: cout << "Submarine!n"; break; case 4: cout << "Destroyer!n"; break; } // end switch (ship) return true;
  • 24.
    } // endif (shipSunk) } // end if (isSunk[ship]) } // end for (int ship = 0; ship < 5; ship++) return false; } // end bool ShipSunk(int shipLocs[5][4], bool isSunk[5], string board[11][11], int turn, string GuessP1[11][11]) bool ShipSunk (int shipLocs[5][4], bool isSunk[5], string board[11][11], int turn, int GuessP2[11][11]) { // determine if CPU's last guess sunk a ship. bool shipSunk = true; for (int ship = 0; ship < 5; ship++) { if (isSunk[ship]) { shipSunk = true; for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) { for (int c = shipLocs[ship][1]; c <= shipLocs[ship][3]; c++) { if (board[r][c] == "S") { shipSunk = false; break; } // end if board } // end for (int c = shipLocs[ship][1]; c <= shipLocs[ship][3]; c++) if (!shipSunk) { break;
  • 25.
    } // endif (!shipSunk) } // end for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) if (shipSunk) { // if shipsunk is true, the previous guess sunk the ship // update GuessP2 to indicate the sunk ship for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) { for (int c = shipLocs[ship][1]; c <= shipLocs[ship][3]; c++) { GuessP2[r][c] = 3; } // end for (int c = shipLocs[ship][1]; c <= shipLocs[ship][3]; c++) } // end for (int r = shipLocs[ship][0]; r <= shipLocs[ship][2]; r++) // update the ship's status isSunk[ship] = false; if (turn == 1) { cout << " You sunk the computer's "; } // end if (turn == 1) else { cout << " The CPU sank your "; } // end else: if (turn == 1) switch (ship) { case 0: cout << "Aircraft Carrier!n"; break; case 1:
  • 26.
    cout << "Battleship!n"; break; case2: cout << "Cruiser!n"; break; case 3: cout << "Submarine!n"; break; case 4: cout << "Destroyer!n"; break; } return true; } // end switch (ship) } // end if (isSunk[ship]){ } // end for (int ship = 0; ship < 5; ship++) return false; } // end bool ShipSunk(int shipLocs[5][4], bool isSunk[5], string board[11][11], int turn, int GuessP2[11][11]) bool isGameOver (bool isSunk[5]) { // check each ships status. // if a ship is alive, return false -- else return true; for (int i = 0; i < 5; i++) { if (isSunk[i]) return false; } return true; } // end bool isGameOver(bool isSunk[5]) bool chooseTile (string Board1[11][11], string Board2[11][11],
  • 27.
    string GuessP1[11][11], intp2LocShip[5][4], bool p2isSunk[5], string Display1[11][11], int GuessP2[11][11]) { // handle user's turn. // when the user sinks a ship, check to see if the ship was the last ship. // if the last ship was sunk, return true to alert main that the game is over. vector < char >userGuess; // vector to hold user input string userInput; // string for user guess int row; // user's row guess int col; // user's col guess bool tryAgain; // if their input is invalid -- true // print the game board printBoard (GuessP1, Board1, Display1, GuessP2); do { cout << " Where are we aiming our cannons: "; cin >> userInput; // this wouldn't have to be a char vector, // but the input for placing the user's ships does // so string interpreter was written to handle char vectors // ergo, char vector. for (int i = 0; i < userInput.size (); i++) { userGuess.push_back (userInput[i]); } // end for (int i = 0; i < userInput.size(); i++) tryAgain = stringInterpreter (userGuess, row, col); if (tryAgain) { userGuess.clear (); } // end if (tryAgain)
  • 28.
    } while (tryAgain); if (Board2[row][col]== "S") { cout << " You hit the CPU's ship!n"; GuessP1[row][col] = "X"; Board2[row][col] = "X"; if (ShipSunk (p2LocShip, p2isSunk, Board2, 1, GuessP1)) { if (isGameOver (p2isSunk)) { return true; } } } else if (GuessP1[row][col] == "X" || GuessP1[row][col] == "O" || GuessP1[row][col] == "A" || GuessP1[row][col] == "B" || GuessP1[row][col] == "C" || GuessP1[row][col] == "S" || GuessP1[row][col] == "D") { cout << " You've already guessed this location. Try Again.n"; if (chooseTile (Board1, Board2, GuessP1, p2LocShip, p2isSunk, Display1, GuessP2)) { return true; } } else
  • 29.
    { cout << "you missed :( n"; GuessP1[row][col] = "O"; } // end else return false; } void getP1ShipLocs (string Board1[11][11], int shipLengths[], int p1LocShip[5][4], string Display1[11][11]) { for (int ships = 0; ships < 5; ships++) { cout << "n----------------------------------------------------------------- ------------------------------------------------------n"; cout << "WELCOME TO BATTLESHIP n"; cout << "------------------------------------------------------------------- ----------------------------------------------------nn"; printBoardInput (Board1, Display1); setLocShips (Board1, ships, shipLengths, p1LocShip, Display1); system ("cls"); } } void BombingMostProbable (int GuessP2[11][11], int row, int col, int directions[4]) { int dir[4] = { 1, 1, 1, 1 };
  • 30.
    // check North while((GuessP2[row - dir[0]][col] == 0 || GuessP2[row - dir[0]][col] == 2) && row - dir[0] >= 1) { dir[0]++; } // end while ((GuessP2[row - dir[0]][col] == 0 || GuessP2[row - dir[0]][col] == 2) && row - dir[0] >= 1) // check South while ((GuessP2[row + dir[1]][col] == 0 || GuessP2[row + dir[1]][col] == 2) && row + dir[1] <= 10) { dir[1]++; } // end while ((GuessP2[row - dir[1]][col] == 0 || GuessP2[row - dir[1]][col] == 2) && row - dir[1] >= 1) // check East while ((GuessP2[row][col + dir[2]] == 0 || GuessP2[row][col + dir[2]] == 2) && col + dir[2] <= 10) { dir[2]++; } // end while ((GuessP2[row][col + dir[2]] == 0 || GuessP2[row][col + dir[2]] == 2) && col + dir[2] <= 10) // check West while ((GuessP2[row][col + dir[3]] == 0 || GuessP2[row][col + dir[3]] == 2) && col + dir[3] >= 1) { dir[3]++; } // end while ((GuessP2[row][col + dir[3]] == 0 || GuessP2[row][col + dir[3]] == 2) && col + dir[3] <= 10)
  • 31.
    int whichWay =0; int maxValue = 0; int temp = 0; for (int j = 0; j < 4; j++) { maxValue = 0; for (int i = j; i < 4; i++) { if (dir[i] > maxValue) { maxValue = dir[i]; whichWay = i; } } temp = directions[j]; directions[j] = directions[whichWay]; directions[whichWay] = temp; temp = dir[j]; dir[j] = dir[whichWay]; dir[whichWay] = temp; } } // For void smartComp (int GuessP2[11][11], bool p1isSunk[5], int shipLengths[5], int &row, int &col) { int probabilityField[11][11] = { 0 }; bool possible;
  • 32.
    for (int ship= 0; ship < 5; ship++) { if (p1isSunk[ship]) { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10 - (shipLengths[ship] - 1); j++) { possible = true; for (int idx = 0; idx < shipLengths[ship]; idx++) { if (GuessP2[i][j + idx] == 1 || GuessP2[i][j + idx] == 3) { possible = false; break; } } if (possible) { for (int idx = 0; idx < shipLengths[ship] / 2; idx++) { probabilityField[i][j + idx] += idx + 1; probabilityField[i][j + shipLengths[ship] - 1 - idx] += idx + 1; } if (shipLengths[ship] % 2 == 1) { probabilityField[i][j + shipLengths[ship] / 2] += shipLengths[ship] / 2 + 1; }
  • 33.
    } } } } } // loop througheach ship. for (int ship = 0; ship < 5; ship++) { if (p1isSunk[ship]) { // loop through each row. for (int i = 1; i <= 10 - (shipLengths[ship] - 1); i++) { for (int j = 1; j <= 10; j++) { possible = true; for (int idx = 0; idx < shipLengths[ship]; idx++) { if (GuessP2[i + idx][j] == 1 || GuessP2[i + idx][j] == 3) { possible = false; break; } // end if (GuessP2[i + idx][j] == 1 || GuessP2[i + idx][j] == 3) } // end for (int idx = 0; idx < shipLengths[ship]; idx++) if (possible) { // give the center of the possible ship location priority for (int idx = 0; idx < shipLengths[ship] / 2; idx++)
  • 34.
    { probabilityField[i + idx][j]+= idx + 1; probabilityField[i + shipLengths[ship] - 1 - idx][j] += idx + 1; } // end for (int idx = 0; idx < shipLengths[ship]; idx++) if (shipLengths[ship] % 2 == 1) { probabilityField[i + shipLengths[ship] / 2][j] += shipLengths[ship] / 2 + 1; } // end if (shipLengths[ship] % 2 == 1) } // end if(possible) } // end for (int c = 1; c <= 10 - (shipLengths[ship] - 1); c++) } // end for (int r = 1; r <= 10; r++) // break; // uncomment to only worry about the largest possible ship } // end if (p1isSunk[ship]) } // end for (int ship = 0; ship < 5; ship++) // find the max value and randomly select one if there are more than one. vector < int >i_locs; vector < int >j_locs; // find the highest value int maxValue = 0; for (int i = 1; i < 11; i++) { for (int j = 1; j < 11; j++) { if (probabilityField[i][j] > maxValue && GuessP2[i][j] != 1 && GuessP2[i][j] != 2 && GuessP2[i][j] != 3) {
  • 35.
    maxValue = probabilityField[i][j]; }// end if (probabilityField[i][j] > maxValue && GuessP2[i][j] != 1 && GuessP2[i][j] != 2 && GuessP2[i][j] != 3) } // end for (int j = 1; j < 11; j++) } // end for (int i = 1; i < 11; i++) // find all the spots that have the highest value for (int i = 1; i < 11; i++) { for (int j = 1; j < 11; j++) { if (probabilityField[i][j] == maxValue && GuessP2[i][j] == 0) { i_locs.push_back (i); j_locs.push_back (j); } // end if (probabilityField[i][j] == maxValue && GuessP2[i][j] == 0) } // end for (int j = 1; j < 11; j++) } // end for (int i = 1; i < 11; i++) // randomly select one int randNum = rand () % i_locs.size (); row = i_locs.at (randNum); col = j_locs.at (randNum); } // end void smartComp(int GuessP2[11][11], bool p1isSunk[5], int shipLengths[5], int &row, int &col) void displayCPUGuess (int row, int col) { // interpret the guess into something the user will understand char letters[] = { ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' }; cout << "----------------------------------------------------------------------
  • 36.
    -------------------------------------------------n"; cout << "The CPU guessed: " << letters[row] << col << "n"; } // end void displayCPUGuess(int row, int col) bool BSAI (string Board1[11][11], int GuessP2[11][11], bool p1isSunk[5], int shipLengths[5], int p1LocShip[5][4]) { static bool Bombing = true; // state flag for remembering if the cpu is Bombing for a ship. static bool directionFound = false; // state flag for remembering if the cpu has found the orientation of the ship static bool bothDirections = false; // state flag for remembering if the cpu has found the orientation of the ship and checked both sides. static int directions[4] = { 1, 2, 3, 4 }; // for guessing the direction once a ship has been found. static int row = 0, col = 0; // for remembering the last cpu guess static int idx = 0; // for remembering how far away from the origin the cpu is now guessing. static bool findMostProbable = true; // for determining if you should calculate the most probable neighborhood shot static int whichWay = 0; // for keeping track of which neighborhoods have been shot at it. static int dRow = 0, dCol = 0; // for guessing at ship locations while no longer in hunt mode. *conserves original hit. static int pursuingDirection = 0; // for keeping track of the direction being pursued static int checkingDirection = 0; // for keeping track of the
  • 37.
    direction being checked. /*when the orientation is found, pursuing will equal checking */ if (Bombing) { for (int r = 0; r < 11; r++) { for (int c = 0; c < 11; c++) { if (GuessP2[r][c] == 2) { Bombing = false; directionFound = false; bothDirections = false; findMostProbable = true; for (int i = 0; i < 4; i++) { directions[i] = i + 1; } // end for (int i = 0; i < 4; i++) row = r; col = c; idx = 1; whichWay = 0; cout << " The CPU is moving on to the next found ship.n"; if (BSAI (Board1, GuessP2, p1isSunk, shipLengths, p1LocShip)) { return true; } // end if (BSAI( Board1, GuessP2, p1isSunk, shipLengths, p1LocShip)) else {
  • 38.
    return false; } //end else: if (BSAI( Board1, GuessP2, p1isSunk, shipLengths, p1LocShip)) } // end if (GuessP2[r][c] == 2) } // end for (int c = 0; c < 11; c++) } // end for (int r = 0; r < 11; r++) // calculate the probability fields and choose a location to guess -- updating row and col by // pass by reference smartComp (GuessP2, p1isSunk, shipLengths, row, col); cout << "------------------------------------------------------------------- ----------------------------------------------------n"; cout << " The CPU is Bombing.n"; displayCPUGuess (row, col); // display the cpu's guess if (Board1[row][col] == "S") { // the cpu hit a player's ship. cout << " The CPU hit your ship!n"; Board1[row][col] = "X"; // update player 1's board GuessP2[row][col] = 2; // update the cpu's guessing matrix Bombing = false; // the cpu is no longer Bombing! idx = 1; // begin looking 1 away from the origin // the cpu hit a ship, so check if that ship got sunk. if (ShipSunk (p1LocShip, p1isSunk, Board1, 2, GuessP2)) { if (isGameOver (p1isSunk)) { return true; // the game is over.
  • 39.
    } // endif (isGameOver(p1isSunk)) // a ship was sunk, so reset the flags and begin Bombing Bombing = true; directionFound = false; bothDirections = false; findMostProbable = true; for (int i = 0; i < 4; i++) { directions[i] = i + 1; } // end for (int i = 0; i < 4; i++) } // end if (ShipSunk(p1LocShip, p1isSunk, Board1, 2)) } // end if ( Board1[row][col] == "S") else { // the cpu missed a player's ship cout << " The CPU missed your ship!n"; Board1[row][col] = "O"; // update player 1's board GuessP2[row][col] = 1; // update the cpu's guessing matrix } // end else: if ( Board1[row][col] == "S") } // end if (Bombing) else { if (directionFound) { // keep guessing until you find a new // spot to guess. do { // North if (pursuingDirection == 1) { dRow = row - idx;
  • 40.
    dCol = col; }// end if (pursuingDirection == 1) // South else if (pursuingDirection == 2) { dRow = row + idx; dCol = col; } // end else if (pursuingDirection == 2) // East else if (pursuingDirection == 3) { dRow = row; dCol = col + idx; } // end else if (pursuingDirection == 3) // West else if (pursuingDirection == 4) { dRow = row; dCol = col - idx; } // end // end else if (pursuingDirection == 4) // skip over previous guesses that // hit a ship and the ship never sunk if (GuessP2[dRow][dCol] == 2) { idx++; } // end if (GuessP2[dRow][dCol] == 2) // if the direction is a dead end swap directions if (GuessP2[dRow][dCol] == 1 || GuessP2[dRow][dCol] == 3) { if (bothDirections) { cout << "-------------------------------------------------------
  • 41.
    ----------------------------------------------------------------n"; cout << "The CPU found multiple touching ships.n"; directionFound = false; bothDirections = false; whichWay++; idx = 1; for (int i = 0; i < 4; i++) { directions[i] = i + 1; } // end for (int i = 0; i < 4; i++) if (BSAI (Board1, GuessP2, p1isSunk, shipLengths, p1LocShip)) { return true; } // end if (BSAI( Board1,GuessP2,p1isSunk,shipLengths,p1LocShip)) else { return false; } // end else: if (BSAI( Board1,GuessP2,p1isSunk,shipLengths,p1LocShip)) } // end if (bothDirections) else { bothDirections = true; if (pursuingDirection % 2 == 1) { pursuingDirection++; idx = 1; } // end if (pursuingDirection % 2 == 1) else { pursuingDirection--; idx = 1;
  • 42.
    } // endelse: if (pursuingDirection % 2 == 1) } // end else: if (bothDirections) } // end if (GuessP2[dRow][dCol] == 1 || GuessP2[dRow][dCol] == 3) } while (GuessP2[dRow][dCol] != 0); cout << "---------------------------------------------------------------- -------------------------------------------------------n"; if (pursuingDirection == 1) { cout << " The CPU is pursuing North.n"; } // end if (pursuingDirection == 1) else if (pursuingDirection == 2) { cout << " The CPU is pursuing South.n"; } // end else if (pursuingDirection == 2) else if (pursuingDirection == 3) { cout << " The CPU is pursuing East.n"; } // end else if (pursuingDirection == 3) else if (pursuingDirection == 4) { cout << " The CPU is pursuing West.n"; } // end else if (pursuingDirection == 4) displayCPUGuess (dRow, dCol); // display the cpu's guess if (Board1[dRow][dCol] == "S") { // the cpu hit a player's ship. cout << " The CPU hit your ship!n"; Board1[dRow][dCol] = "X"; // update player 1's board
  • 43.
    GuessP2[dRow][dCol] = 2;// update the cpu's guessing matrix idx++; // begin looking 1 away from the origin directionFound = true; // the cpu has discovered the orientation // the cpu hit a ship, so check if that ship got sunk. if (ShipSunk (p1LocShip, p1isSunk, Board1, 2, GuessP2)) { if (isGameOver (p1isSunk)) { return true; // the game is over. } // end if (isGameOver(p1isSunk)) // a ship was sunk, so reset the flags and begin Bombing Bombing = true; directionFound = false; bothDirections = false; findMostProbable = true; for (int i = 0; i < 4; i++) { directions[i] = i + 1; } // end for (int i = 0; i < 4; i++) } // end if (ShipSunk(p1LocShip, p1isSunk, Board1, 2)) } // end if ( Board1[dRow][dCol] == "S") else if (Board1[dRow][dCol] == " ") { // the cpu missed a player's ship cout << " The CPU missed your ship!n"; Board1[dRow][dCol] = "O"; // update player 1's board GuessP2[dRow][dCol] = 1; // update the cpu's guessing matrix } // end else: if ( Board1[dRow][dCol] == "S")
  • 44.
    } // endif (directionFound) else { if (findMostProbable) { BombingMostProbable (GuessP2, row, col, directions); findMostProbable = false; whichWay = 0; } // end if (findMostProbable) do { checkingDirection = directions[whichWay]; // North if (checkingDirection == 1) { dRow = row - idx; dCol = col; } // end if (checkingDirection == 1) // South else if (checkingDirection == 2) { dRow = row + idx; dCol = col; } else if (checkingDirection == 3) { dRow = row; dCol = col + idx; } else if (checkingDirection == 4) {
  • 45.
    dRow = row; dCol= col - idx; } if (dRow >= 1 && dRow <= 10 && dCol >= 1 && dCol <= 10) { if (GuessP2[dRow][dCol] != 0) { whichWay++; } } else { whichWay++; } } while (GuessP2[dRow][dCol] != 0); cout << "---------------------------------------------------------------- -------------------------------------------------------n"; if (checkingDirection == 1) { cout << " The CPU is checking North.n"; } else if (checkingDirection == 2) { cout << " The CPU is checking South.n"; } // end else if (checkingDirection == 2) else if (checkingDirection == 3) { cout << " The CPU is checking East.n"; } // end else if (checkingDirection == 3) else if (checkingDirection == 4) { cout << " The CPU is checking West.n";
  • 46.
    } // endelse if (checkingDirection == 4) displayCPUGuess (dRow, dCol); // display the cpu's guess if (Board1[dRow][dCol] == "S") { cout << " The CPU hit your ship!n"; cout << " The CPU has entered Destroyer Mode.n"; Board1[dRow][dCol] = "X"; GuessP2[dRow][dCol] = 2; idx++; directionFound = true; pursuingDirection = checkingDirection; if (ShipSunk (p1LocShip, p1isSunk, Board1, 2, GuessP2)) { if (isGameOver (p1isSunk)) { return true; } Bombing = true; directionFound = false; bothDirections = false; findMostProbable = true; for (int i = 0; i < 4; i++) { directions[i] = i + 1; } } } else if (Board1[dRow][dCol] == " ")
  • 47.
    { cout << "The CPU missed your ship!n"; Board1[dRow][dCol] = "O"; GuessP2[dRow][dCol] = 1; } } } return false; } void endPrintBoard (string Board1[11][11], string Display1[11][11], string Board2[11][11], string Display2[11][11], string GuessP1[11][11]) { cout << "---------------------------------------------------------------------- -------------------------------------------------n"; cout << "|" << " CPU Game Board Your Game Board " << "|n"; cout << "---------------------------------------------------------------------- -------------------------------------------------n"; cout << "| |n"; for (int r = 0; r < 11; r++) { cout << "|t"; for (int c = 0; c < 11; c++) { if (r == 0) {
  • 48.
    cout << Board2[r][c]<< " "; } else { if (Board2[r][c] == "S") { cout << Display2[r][c] << " | "; } // end if ( Board2[r][c] == "S" else if (Board2[r][c] == "X") { cout << Display2[r][c] << " | "; } // end else if ( Board2[r][c] == "X") else if (GuessP1[r][c] == "O") { cout << GuessP1[r][c] << " | "; } else if (Board2[r][c] == " ") { cout << Board2[r][c] << " | "; } else { cout << Board2[r][c] << " | "; } // end else } } cout << "tt"; for (int c = 0; c < 11; c++) { if (r == 0) { cout << Board1[r][c] << " "; } else { if (Board1[r][c] == "S")
  • 49.
    { cout << Display1[r][c]<< " | "; } else if (Board1[r][c] == "X") { cout << Display1[r][c] << " | "; } else if (Board1[r][c] == "O") { cout << Board1[r][c] << " | "; } else if (Board1[r][c] == " ") { cout << Board1[r][c] << " | "; } else { cout << Board1[r][c] << " | "; } } } if (r == 0) { cout << " |"; } else { cout << " |"; } cout << "n| t ----------------------------------------- tt ------------- ---------------------------- |n"; } // end for (int r = 0; r < 11; r++) cout << "| |";
  • 50.
    cout << "n-------------------------------------------------------------------- ---------------------------------------------------n"; } void setDisplayBoard (stringboard[11][11], int locs[5][4]) { string shipNames[5] = { "A", "B", "C", "S", "D" }; for (int s = 0; s < 5; s++) { for (int r = locs[s][0]; r <= locs[s][2]; r++) { for (int c = locs[s][1]; c <= locs[s][3]; c++) { board[r][c] = shipNames[s]; } } } } __MACOSX/._main.cpp Running Head: METHODOLOGY OUTLINE INSTRUCTION 1 METHODOLOGY OUTLINE INSTRUCTION 5 Methodology Outline Instructions
  • 51.
    Carrington Sherman HCS/542 -HEALTH CARE RESEARCH Instructor: HARRIET BAGGETT March 2,2018 A quantitative methodology outline 1. Identified target population · The target population of this research is the men and women with obesity in the Southern Cone of America. · The targeted towns include Marcos Paz and Bariloche in Argentina, the Uruguays Pando-Barros Blancos and Temuco city in Chile. 2. Your specific sample of participants: · What/who will comprise your sample(s)? i. The sampled population will be people with records of obese. ii. The sample size comprises 7,524 obese people (3165 men and 4359 women) within the age bracket of between 35 and 74 years old. · Where will you find them? i. The sample population will be sampled from the towns of Southern Cone of America. ii. These includes the Marcos Paz and Bariloche in Argentina, the Uruguays Pando-Barros Blancos and Temuco city in Chile. · How large will your sample(s) be? i. The sample size will be 10,254 randomly selected individuals.
  • 52.
    · What isyour rationale for these decisions? i. The larger the sample the better to increase the degree of confidence and reduce errors due to the respondents behavior. ii. The number will cater for those who will refuse to take part, those who will not complete the survey, and those who will not complete clinical examinations (Ormston et al., 2014). 3. Method for getting the data from the sample: · How will you recruit the subjects? i. Subjects will be recruited randomly in the towns identified after seeking the participants consent (Meadows, 2003). ii. Random sampling will not observe gender stratification (Meadows, 2003). · What general process will you use to collect the data? (e.g., where will you collect it? Who will collect it? Etc. What is the process you and the participant will go through so you can get the data, in other words?) i. Data will be collected using a multiple of data collection tools. ii. There shall be home visits entailing surveys to collect demographic characteristics of the participant, healthcare access, (Cardiovascular diseases) CVD and risk factors personal history, their physical activity and Dietary History. iii. There shall also be clinical visits to collect Anthropometric measurements like blood pressure, body weight, waist circumference and height (Meadows, 2003). · What specific independent and dependent variables will you be studying, and how specifically will you measure those variables? i. The independent variables in this study will include the race (black American and the whites) and CVD risk factors. ii. The dependent variables will include the overweight, obesity and central obesity in the Southern Cone of Latin America. iii. Dependent variables will be measured clinically using set of anthropometric protocols and techniques. For instance, BP measured using a standard mercury or aneroid sphygmomanometer, Body weight using standing scales and
  • 53.
    body height withoutshoes using a wall-mounted stadiometer and waist circumference measured in centimeters above the navel during minimal respiration (Meadows, 2003). · What comparison groups will you have, if any? i. Will compare the cardiovascular diseases of the whites and the black Americans, and other races like the Hispanic. ii. Male and female obese, overweight and central obesity comparison will be done · What instruments or measurements will you use to get the data? i. The questionnaires will be used to obtain participants demographic and personal characteristics (Ormston et al., 2014). ii. Anthropometric measurements will be done using clinically approved protocols and techniques. iii. The overnight fasting blood creatinine, lipids and glucose levels will be measured iv. Again, the total and HDL-cholesterol and triglycerides will be measured too. · How did you decide on these particular groups, instruments or measurements? i. The decision to use these groups was derived from the theory of prevalence of obesity among whites than the blacks and minorities in America. ii. The use of protocols and set techniques for Anthropometric measurements were chosen for clinical procedures (Meadows, 2003). iii. Structured questionnaires were used to collect demographic characteristics because of the nature of data (qualitative) inclusivity of data collected and validity of the data collected (Ormston et al., 2014). 4. Ethical Considerations and Steps for your proposed study, based on our prior weeks' materials · The participants are required to first agree on a written consent for participation. · Participants’ personal information will be confidential and
  • 54.
    private from thirdparties. · Participants anonymity for the sake of research findings · Information obtained shall be distributed freely (Ormston et al., 2014). References Meadows, K. A. (2003). So you want to do research? 2: developing the research question. British journal of community nursing, 8(9), 397-403. Ormston, R., Spencer, L., Barnard, M., & Snape, D. (2014). The foundations of qualitative research. Qualitative research practice: A guide for social science students and researchers, 1- 26. 1 2 Week 2 Assignment ResearchStudy Proposal–Part I: Problem Statement Carrington Sherman HCS 542 Health Care Research March 12, 2018 University of Phoenix
  • 55.
    Study Proposal–Part I:Problem Statement Why are southern who live in the southern states like Texas, Louisiana, Mississippi, Alabama, and Georgia have higher obesity rates compared to other state in different region. Is it because of lack of education for health diets or, does it has to deal with the culture and in environment they reside in? Majority of the population who are overweight live in urban areas where there are predominantly lower income families homes (Obesity Epidemic). What is obesity, it is defined as when a person body fat total is 30 percent are higher (Adolescent obesity) . Which causes stress on the joints, back, and feet some people may even have trouble berthing. The two main populations that this disease affects the most are white and black in lower income family homes that live in the urban areas. Most of the time if people don’t know any better so they will continue to do the same thing because that is all they know. Due to everyone been a creatures of habit it is very difficult to change someone who no intention to change. In 2014 “For the second year in a row, Mississippi had the highest obesity rate, with 35.2% of residents classified as obese according to residents' self-reported height and weight”(Obesity Rates).It also indicated that number was still on the up raise and will continue to increase. Due to them understand that the way they grew up is all that they know. You always hear about how the food is just so flavorful and delicious in the southern state. You may also see the result of what good food can do to you and your health as well as your body. Just because the food
  • 56.
    tastes great andit makes you want to eat more doesn’t necessary mean that it’s good for you. Most people would like to think that but that is not the case. Health education can change life style and the way people eat .For explain if you told someone if they continue to eat unhealthy and not exercise they would they would die everyone gym membership would be sky high just because of the fear the someone has left on the mind. Also, your live environment plays a major role in what type of health you will have. If you live in a descent home you will probably have descent health as well if you live in a rough a poor neighborhood you are most like to receive help form the government. Sometime you make not quality for government assistance even though they’re still poor. References: Conway, B. N., Han, X., Munro, H. M., Gross, A. L., Xiao-Ou, S., Hargreaves, M. K., . . . Blot, W. J. (2018). The obesity epidemic and rising diabetes incidence in a low-income racially diverse southern US cohort. PLoS One, 13(1)http://dx.doi.org.contentproxy.phoenix.edu/10.1371/j ournal.pone.0190993 Retrieved from https://search-proquest- com.contentproxy.phoenix.edu/docview/1986672403?accountid =134061 McCarthy, Justin, and Diana Liu. "Obesity Rate Lowest in Hawaii, Highest in Mississippi." Gallup Poll News Service, 26 May 2015. Opposing Viewpoints in Context,
  • 57.
    http://link.galegroup.com.contentproxy.phoenix.edu/apps/doc/A 416344500/OVIC?u=uphoenix_uopx&xid=cbfbf7ce. Accessed 12 Mar.2018. Koehly, L. M., & Loscalzo, A. (2009). Adolescent Obesity and Social Networks. Preventing Chronic Disease, 6(3), A99. Running Head: OBESITY EPIDEMIC IN SOUTH U. S STATES 1 OBESITY EPIDEMIC IN SOUTH U. S STATES 2 Obesity Epidemic Southern U. S States Carrington Sherman Name of Institution Why are southern who live in the southern states like Texas, Louisiana, Mississippi, Alabama, and Georgia have higher obesity rates compared to other state in different region. Is it because of lack of education for health diets or, does it has to deal with the culture and in environment they reside in? Majority of the population who are overweight live in urban
  • 58.
    areas where thereare predominantly lower income families homes (Obesity Epidemic). In-text citation Study design Sample size and description Independent and dependent variables Key findings Study method strengths Study method weakness Further research needs · Conway et al., 2018). · The study design in this research is the Cohort Study · The sample size was 24,000 black Americans and 14,064 white adults sampled · The individuals’ were of age between 40–79 years · The samples were from underserved populations in the 12- state span that included Alabama, Florida, Arkansas, Georgia, Louisiana, Kentucky, Mississippi, South Carolina, North Carolina, Tennessee, West Virginia and Virginia. · The dependent variables included the racial difference in the population in U. S including the blacks Americans and the whites. · The gaps in diabetes, cardiovascular, cancer and other chronic diseases were also dependent factor on the race, economic status and the age of the participants in the population. · The independent variables included the races that are the African Americans and whites. Change in time was also independent because it did not rely on any factor in the population to vary but determined the extend of variation of the prevalence of the obesity, physical inactivity and diabetes · Risk of obesity and diabetes monotonically increased with increasing BMI and varied between blacks and whites. · Diabetes incidences doubled in black populations than among the whites who had normal BMI. · Racial difference became weak as the BMI increased among the populations
  • 59.
    · The increasein the BMI remained a predominant risk factor among blacks and whites. · One, cohort study presents a clear temporal Sequence of outcomes against exposures over time · Two, it allows Calculation of the incidence in terms of absolute and relative risks. · Three, it facilitates study of rare exposures and multiple effects of an exposure. The study design will be able to single out the effect of every exposure to a factor and also combine the several effects due to every exposure on the factor that causes variation in the variables. · Time consuming because it involving following up a phenomenon for a long time observing and recording incidences · It is also very expensive due to the length of time involved and the amount of data collection done. · It is affected by many unforeseen factors in the field. As the field dynamics changes, the factors affecting the study may change and so will require new techniques or modification of the existing techniques. · It needs studies of variables that have long latency which will enable recording of the observations consistently without termination · The role of treatment of obesity in checking diabetes incidence. · Study need to be done to include individuals with multiple chronic diseases in the population. · Sequential collection of data using uniform standardized methods and personnel its needed too to enhance data collection I cohort studies like this. · Research question: Does the high incidences of obesity reflect on the high rate of incidence of diabetic incidence in the population of southern states of U. S? · Lanas et al., 2016). · The study design in this research is the CESCAS I study design - is an observational and prospective cohort study · The sample size was of 7,524 women and men aged between
  • 60.
    35 and 74years old. They were sampled from all the 4 cities of Southern Cone of Latin America which included Bariloche and Marcos Paz in Argentina, Temuco city in Chile, and Pando-Barros Blancos in Uruguay. Marcos Paz and Pando-Barros Blancos had population size of 54,000 and 58,000 respectively, Bariloche and Temuco had 134,000 and 245,000 respectively. the study sites had been selected based on the characteristics of the population reflecting the country averages. · Dependent variables height, weight, sex, education, household income, occupation and healthcare access. · Independent variables included age groups and gender. The age group varied from 35 years to 74 in the interval of five years per group. · Women prevalence of obesity and central obesity were higher compared to men. · Education level increased the prevalence of obesity, physical inactivity and diabetes further. · It is very concrete in digging out information. · It is comprehensive and inclusive in data collection and analysis that results to conclusion drawing and reliability of the results for generalization on the entire population · It needs capacity building before carrying out data collection · It is expensive design and time consuming due to the longer time involved in data collection and tools and protocols used to collect and analyze data · The role of education on the increased prevalence of obesity should be studied. This will dig out the fundamental aspects of education that influence risks of obesity and how it can be used to check prevalence of obesity. · Research question: what is the impact of increased educational level among the individuals on the incidence of obesity rates in southern states of U. S? · Geiss et al., 2017). · The study design in this research is the Bayesian multilevel
  • 61.
    telephone survey modelingtechniques and census · The sample size was 400,000 adults in 50 U. S states involving the 3143 counties. · Time was the independent variable (2004 to 2012. · The dependent variables were prevalence of diagnosed diabetes, obesity, and individuals’ physical inactivity. These are the variables that depended on the time and the regions in the southern U. S. · Low median average annual percentage point changes (APPCs) of obesity, diabetes, and physical inactivity in 2008–2012 compared to 2004-2008. · APPCs varied among counties in U. S and regions. · APPC differences between two periods also varied in both the blacks and the whites. · Bayesian method can accommodate all unobserved variables and also is a powerful tool for incorporating previous information and controlling confounding. · Census surveys increasing the confidence interval of the data collected due to large participants, it also provides a chance for identifying and attending to negative feedback. · Bayesian method requires in-depth understanding of the design and implementation. It is best for large computational studies. · Census surveys limits other studies on the same population and also takes a longer time to collect information · There is need to be a study to estimate the effect of geographic patterns, and physical inactivity on obesity and diabetes. · Continuous data collection systems should be set to ensure continuous standardizes data collection and storage · Research question: does geographic variability, nutritional awareness and income status reduces the incidence of obesity significantly in southern States of U. S?
  • 62.
    References Conway, B. N.,Han, X., Munro, H. M., Gross, A. L., Shu, X. O., Hargreaves, M. K., ... & Blot, W. J. (2018). The obesity epidemic and rising diabetes incidence in a low-income racially diverse southern US cohort. PloS one, 13(1), e0190993. Geiss, L. S., Kirtland, K., Lin, J., Shrestha, S., Thompson, T., Albright, A., & Gregg, E. W. (2017). Changes in diagnosed diabetes, obesity, and physical inactivity prevalence in US counties, 2004-2012. PloS one, 12(3), e0173428. Lanas, F., Bazzano, L., Rubinstein, A., Calandrelli, M., Chen, C. S., Elorriaga, N., ... & Poggio, R. (2016). Prevalence, Distributions and Determinants of Obesity and Central Obesity in the Southern Cone of America. PloS one, 11(10), e0163727. Retrieved from: http://journals.plos.org/plosone/article?id=10.1371/journal.pone .0163727