Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <array>
- #include <ctime>
- #include <vector>
- #include <algorithm>
- using namespace std;
- //Created by William Freire
- //Foward Declaration
- char bottomboard[10][10];char AIboard[10][10];char Virtualboard[10][10];int AI(char AIboard[10][10]);void ResetBoard(); void PrintBoard();void Debug(); int EmptyChecker();bool Exist_in(char arr[10][10], char target);char topboard[10][10];
- //Declaring Varible
- int row = 0,col = 0,car = 5,bs = 4,cru = 3,sub = 3,des = 2,RandomIndexRow,RandomIndexCol;
- char Hit = 'H',CarShip = 'C',BsShip = 'B',CruShip = 'R',SubShip = 'S',DesShip = 'D',Miss = 'M',Empty = 'E',target;
- vector<int> ROW; vector<int> COL;
- //Checking if Virtualboard[row][col] = '_'; which is empty
- int EmptyChecker(){
- for (int row=0; row<10 ; row++){
- if(Exist_in(Virtualboard,Empty) == true){
- ROW.push_back(row);
- }
- }
- for (int col; col<10; col++){
- if(Exist_in(Virtualboard,Empty) == true){
- COL.push_back(col);
- }
- }
- if(Exist_in(Virtualboard,Empty) == true){
- AI(AIboard);
- }
- }
- //Works with EmptyChecker and other functions to see if some thing is in an array
- bool Exist_in(char arr[10][10], char target){
- for (int row=0; row<10 ; row++){
- for(int col=0; col<10; col++){
- if(arr[row][col] == target)
- return true;
- }
- }
- return false;
- }
- //Starts all the functions
- void Start(){
- ResetBoard();
- PrintBoard();
- EmptyChecker();
- }
- //makes a debug log for the Virtualboard
- void Debug(){
- cout<<"\n";
- for(unsigned int i = 0; i < ROW.size(); i++){
- for(unsigned int i = 0; i < COL.size(); i++){
- cout<<"Cords that is empty: "<<ROW[i]<<","<<COL[i]<<endl;
- }
- }
- }
- //Self explainatory. It prints out the bottomboard
- void PrintBoard(){
- for (row=0; row<10; row++){
- for (col=0;col<10;col++){
- cout <<topboard[row][col] << " ";
- }
- cout << "\n";
- }
- cout<<endl<<"----------------------------"<<endl;
- for (row=0; row<10; row++){
- for (col=0;col<10;col++){
- cout <<bottomboard[row][col] << " ";
- }
- cout << "\n";
- }
- }
- //Resets array bottomboard to a 10 by 10 2d array of '_'
- void ResetBoard(){
- cout<<"Battle Ship"<<endl;
- for (row=0; row<10; row++){
- for (col=0;col<10;col++){
- char item = '_';
- bottomboard[row][col] = item;
- Virtualboard[row][col] = Empty;
- topboard[row][col] = item;
- AIboard[row][col] = item;
- }
- }
- }
- //The algorythm/ai that plays the player that first places the ships and then hunts and targets ships.
- int AI(char AIboard[10][10]){
- RandomIndexRow = rand() % ROW.size();
- RandomIndexCol = rand() % COL.size();
- cout<<"Debug Row: "<<RandomIndexRow<<endl;
- cout<<"Debug Col: "<<RandomIndexCol<<endl;
- //ships car = 5,bs = 4,cru = 3,sub = 3,des = 2;
- for(car; car<0; car--){
- }
- for(bs; bs<0; bs--){
- }
- for(cru; cru<0; cru--){
- }
- for(sub; sub<0; sub--){
- }
- for(des; des<0; des--){
- }
- }
- //Main function which starts the whole program
- int main() {
- srand(time(0));
- Start();
- //Debug();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement