#include <iostream>
#include <sstream>
#include <string>

#define print( x ) std::cout << x;
#define printl( x ) std::cout << x << std::endl;

std::string points[8][8];

void setPoints() {
	for (int x = 0; x < 8; x++) {
		for (int y = 0; y < 8; y++) {
			points[x][y] = "-";
		}
	}
}

void drawGrid() {
	print("   ");
	for (int x = 0; x < 8; x++) {
		print(x << "  ");
		if (x >= 7) printl("");
	}
	for (int x = 0; x < 8; x++) {
		print(x << "  ");

		for (int y = 0; y < 8; y++) {
			print(points[x][y] << "  ");
		}
		printl("");
	}
}

int main() {
	setPoints();
	drawGrid();
	printl("Player 1, please place your treasures now: ");
	bool treasurePoints[8][8];
	bool guessPoints[8][8];
	for (int i = 0; i < 3; i++) {
		std::string x, y;
		print("X: ");
		std::getline(std::cin, x);
		print("Y: ");
		std::getline(std::cin, y);
		treasurePoints[std::stoi(x)][std::stoi(y)] = true;
		printl("Treasure " << i + 1 << " placed!");
	}
	system("cls");
	drawGrid();
	int lives = 3;
	for (int i = 0; i < 3; i++) {
		printl("Player 2, Guess now: ");
		std::string x, y;
		print("X: ");
		std::getline(std::cin, x);
		print("Y: ");
		std::getline(std::cin, y);
		guessPoints[std::stoi(x)][std::stoi(y)] = true;
		system("cls");
		if (guessPoints[std::stoi(x)][std::stoi(y)] == treasurePoints[std::stoi(x)][std::stoi(y)]) {
			treasurePoints[std::stoi(x)][std::stoi(y)] = false;
			points[std::stoi(x)][std::stoi(y)] = "x";
			printl("You found treasure " << i + 1 << " of 3");
			drawGrid();
		}
		else {
			points[std::stoi(x)][std::stoi(y)] = "N";
			if (lives != 0) {
				lives--;
				printl("Miss! Try again. Lives left: " << lives);
				drawGrid();
			}
		}
	}
	if (lives != 0) {
		printl("Player 2 Wins!");
	}
	else {
		printl("Player 1 Wins!");
	}
	system("PAUSE");
	return 0;
}