-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleBoardGame.cpp
65 lines (51 loc) · 1.77 KB
/
SampleBoardGame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SampleBoardGame.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include "Board.h"
#include <iostream>
#include <vector>
static void printBoardDetails(Board & boardToPrint ) {
std::cout << "====================================================================================== \n";
std::cout << " The Given board looks like \n";
boardToPrint.print();
std::cout << " \n";
std::string boardValidText;
if (boardToPrint.isValidBoard()) {
boardValidText = "Valid";
}
else {
boardValidText = "invalid";
}
std::cout << "Checking if the board is valid : " << boardValidText.c_str() << " \n";
std::cout << "Number of ships in the board is : " << boardToPrint.getShipCountOnBoard() << "\n";
std::cout << "====================================================================================== \n";
}
int main()
{
char DOT = '.';
char PART = 'X';
int TEST_SIZE = 4;
char board[4][4] = { { DOT,PART, DOT, PART},{ DOT,PART, DOT, DOT}, { DOT,DOT, DOT, PART} };
std::vector<std::vector<char>> boardData;
for (int r = 0; r < TEST_SIZE; r++) {
std::vector<char> rowData;
for (int co = 0; co < TEST_SIZE; co++) {
rowData.push_back(board[r][co]);
}
boardData.push_back(rowData);
}
Board testBoard(boardData);
printBoardDetails(testBoard);
//Let us check for invalid board.
char invalid_board[4][4] = { { DOT,PART, PART, PART},{ DOT,PART, DOT, DOT}, { DOT,DOT, DOT, PART} };
std::vector<std::vector<char>> invalid_boardData;
for (int r = 0; r < TEST_SIZE; r++) {
std::vector<char> rowData;
for (int co = 0; co < TEST_SIZE; co++) {
rowData.push_back(invalid_board[r][co]);
}
invalid_boardData.push_back(rowData);
}
Board invalid_testBoard(invalid_boardData);
printBoardDetails(invalid_testBoard);
}