Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <array>
  4. #include <ctime>
  5. #include <vector>
  6. #include <algorithm>
  7. using namespace std;
  8. //Created by William Freire
  9. //Foward Declaration
  10. 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];
  11. //Declaring Varible
  12. int row = 0,col = 0,car = 5,bs = 4,cru = 3,sub = 3,des = 2,RandomIndexRow,RandomIndexCol;
  13. char Hit = 'H',CarShip = 'C',BsShip = 'B',CruShip = 'R',SubShip = 'S',DesShip = 'D',Miss = 'M',Empty = 'E',target;
  14. vector<int> ROW; vector<int> COL;
  15.  
  16. //Checking if Virtualboard[row][col] = '_'; which is empty
  17. int EmptyChecker(){
  18. for (int row=0; row<10 ; row++){
  19. if(Exist_in(Virtualboard,Empty) == true){
  20. ROW.push_back(row);
  21. }
  22. }
  23. for (int col; col<10; col++){
  24. if(Exist_in(Virtualboard,Empty) == true){
  25. COL.push_back(col);
  26. }
  27. }
  28. if(Exist_in(Virtualboard,Empty) == true){
  29. AI(AIboard);
  30. }
  31. }
  32. //Works with EmptyChecker and other functions to see if some thing is in an array
  33. bool Exist_in(char arr[10][10], char target){
  34. for (int row=0; row<10 ; row++){
  35. for(int col=0; col<10; col++){
  36. if(arr[row][col] == target)
  37. return true;
  38. }
  39. }
  40. return false;
  41. }
  42. //Starts all the functions
  43. void Start(){
  44. ResetBoard();
  45. PrintBoard();
  46. EmptyChecker();
  47. }
  48. //makes a debug log for the Virtualboard
  49. void Debug(){
  50. cout<<"\n";
  51. for(unsigned int i = 0; i < ROW.size(); i++){
  52. for(unsigned int i = 0; i < COL.size(); i++){
  53. cout<<"Cords that is empty: "<<ROW[i]<<","<<COL[i]<<endl;
  54. }
  55. }
  56. }
  57. //Self explainatory. It prints out the bottomboard
  58. void PrintBoard(){
  59. for (row=0; row<10; row++){
  60. for (col=0;col<10;col++){
  61. cout <<topboard[row][col] << " ";
  62. }
  63. cout << "\n";
  64. }
  65. cout<<endl<<"----------------------------"<<endl;
  66. for (row=0; row<10; row++){
  67. for (col=0;col<10;col++){
  68. cout <<bottomboard[row][col] << " ";
  69. }
  70. cout << "\n";
  71. }
  72. }
  73. //Resets array bottomboard to a 10 by 10 2d array of '_'
  74. void ResetBoard(){
  75. cout<<"Battle Ship"<<endl;
  76. for (row=0; row<10; row++){
  77. for (col=0;col<10;col++){
  78. char item = '_';
  79. bottomboard[row][col] = item;
  80. Virtualboard[row][col] = Empty;
  81. topboard[row][col] = item;
  82. AIboard[row][col] = item;
  83. }
  84. }
  85. }
  86. //The algorythm/ai that plays the player that first places the ships and then hunts and targets ships.
  87. int AI(char AIboard[10][10]){
  88. RandomIndexRow = rand() % ROW.size();
  89. RandomIndexCol = rand() % COL.size();
  90. cout<<"Debug Row: "<<RandomIndexRow<<endl;
  91. cout<<"Debug Col: "<<RandomIndexCol<<endl;
  92. //ships car = 5,bs = 4,cru = 3,sub = 3,des = 2;
  93. for(car; car<0; car--){
  94.  
  95. }
  96. for(bs; bs<0; bs--){
  97.  
  98. }
  99. for(cru; cru<0; cru--){
  100.  
  101. }
  102. for(sub; sub<0; sub--){
  103.  
  104. }
  105. for(des; des<0; des--){
  106.  
  107. }
  108. }
  109. //Main function which starts the whole program
  110. int main() {
  111. srand(time(0));
  112. Start();
  113. //Debug();
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement