(If other header or cpp files are necessary, I will provide them accordingly)
here is the compiler error I'm receiving:
Undefined symbols for architecture x86_64:
"TicTacToe::rungame()", referenced from:
_main in main-672692.o
"TicTacToe::TicTacToe()", referenced from:
_main in main-672692.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
private:
static const int ROW = 3;
static const int COL = 3;
int currentplayer;
static const int DEFAULT_NUM_PLAYERS = 2;
Player p[DEFAULT_NUM_PLAYERS];
Cell board[ROW][COL];
Date d;
int numGamesPlayed, turn;
};
#endif /* defined(____tictactoe__) */
cpp file:
#include "tictactoe.h"
#include "cell.h"
#include "date.h"
#include <iostream>
using namespace std;
int ROW = 3;
int COL = 3;
//Tic Tac Toe default constructor
TicTacToe::TicTacToe()
{
cout << "Welcome to my TicTacToe Program!" << endl;
turn=0;
currentplayer=0;
numGamesPlayed = 0;
d.input();
}
//Function to input player information and assign a marker to each player
void TicTacToe::setplayer()
{
cout << "Player 1 please input your information:\n";
p[0].input();
cout << endl;
cout << "Player 2 please input your information:\n";
p[1].input();
cout << p[currentplayer].gethandle() <<", what marker would you like to use? " << endl;
cout << "\t1. X" << endl << "\t2. O\n";
int choice;
cin >> choice;
switch (choice) {
case 1:
p[0].setmarker('X');
p[1].setmarker('O');
break;
case 2:
p[0].setmarker('O');
p[1].setmarker('X');
break;
default:
p[0].setmarker('X');
p[1].setmarker('O');
break;
}
}
//Function that chooses which player's turn it is
void TicTacToe::chooseplayer()
{
if(turn%2==0)
{
currentplayer = 0;
}
else
currentplayer = 1;
}
//Display board function
void TicTacToe::Displayboard(){
int i = 0;
int r = 0;
for ( i = 0; i < COL; i++)
{
for (r = 0; r < ROW; r++)
{
if (r < ROW-1)
{
cout << board[i][r].getmarker() << " | ";
}
else
{
cout << board [i][r].getmarker() << endl;
if(i !=COL-1){
cout << "---------------";
cout << endl;
}
else
cout << endl;
}
}
}
}
//Function to allow player to make move
//Function validates if the choice is within the bounds and if it has chosen already
void TicTacToe::makeMove(){
int x,y;
do{
cout << p[currentplayer].gethandle() << ", please enter the space of the coordinates (ROW,COL)" << endl;
cin >> x >> y;
}while(!(validatebounds(x, y)&&validatechoice(x, y)));
board[x-1][y-1].setmarkers(p[currentplayer].getmarker());
}
//Validation functions
bool TicTacToe::validatebounds(int x, int y)
{
bool validate = true;
if(x<0||x>COL)
{
validate = false;
cout << "Your entry was invalid" << endl;
}
if(y<0||y>ROW)
{
validate = false;
cout << "Your entry was invalid" << endl;
}
return validate;
}
bool TicTacToe::validatechoice(int x, int y)
{
bool validate = true;
if(board[x-1][y-1].getmarker() == 'O' || board[x-1][y-1].getmarker()== 'X')
{
validate = false;
cout << "Please choose another space, this one has been taken" << endl;
}
return validate;
}
//Function to check for wins
bool TicTacToe::checkWin()
{
bool winner(false);
int x;
//Checks for wins on diagonals
if (board[0][0].getmarker() != ' ' && board[0][0].getmarker() == board[1][1].getmarker() && board[0][0].getmarker() == board[2][2].getmarker())
return winner = true;