source.obj : error LNK2001: unresolved external symbol "bool __cdecl safe(int)" (?safe@@YA_NH@Z)
Would anyone know why I get this message when ever i try to run my program.
There is my code..................I believe that the error is comeing form my use of the safe function (safe(Game[count]));Code:#include <iostream> using namespace std; int num_of_suc; int nth_next_move(int n, int GameState[9]); void nth_next_game(int n, int GameState[9], int NextGame[9]); int number_of_moves(int GameState[9]); void not_in_state(int GameState[], int Return[]); bool member(int e, int GameState[9]); bool safe(int); bool game=false; void drawboard(); char board[9]={0,1,2,3,4,5,6,7,8}; void moves(int); void turn(int, int); void nth_next_game(int n, int GameState[9], int NextGame[9]) { for(int i=0;i<9;i++) { if(i<number_of_moves(GameState)) NextGame[i]=GameState[i]; else if (i == number_of_moves(GameState)) NextGame[i]=nth_next_move(n,GameState); else NextGame[i]=-1; } } int number_of_moves(int GameState[9]) { int i=0; while(GameState[i] != -1) i++; return i; } int nth_next_move(int n, int GameState[9]) { int NotIn[9]; not_in_state(GameState,NotIn); return NotIn[n-1]; } void not_in_state(int GameState[], int ret[]) { int Counter=0; for(int i=1;i<=9;i++) if(!member(i,GameState)) { ret[Counter]=i; Counter++; } for(i=Counter;i<9;i++) ret[i] = -1; } bool member(int e, int GameState[9]) { bool flag=false; for(int i=0;i<9;i++) if(GameState[i]==e) flag =true; return flag; } bool safe (int gamestate[9]) { //o's move only!!!!!! bool safeflag=false; num_of_suc=9-number_of_moves(gamestate); int nextgame[9]; if (number_of_moves(gamestate)%2==1) { for (int i=1; i<=num_of_suc; i++) { nth_next_game(i, gamestate, nextgame); if (safe(nextgame)) safeflag=true; } } else // x's move only!!!!!! { bool safeflag=true; if (number_of_moves(gamestate)%2==1) { for (int i=1; i<=num_of_suc; i++) { nth_next_game(i, gamestate, nextgame); if (!safe(nextgame)) safeflag=false; } } } return 0; } void moves(int m) { cin >> m; switch(m) { case 1: if ((m==1)&&(board[0]!='x')&&(board[0]!='o')) board[0]='x'; break; case 2: if ((m==2)&&(board[1]!='x')&&(board[1]!='o')) board[1]='x'; break; case 3: if ((m==3)&&(board[2]!='x')&&(board[2]!='o')) board[2]='x'; break; case 4: if ((m==4)&&(board[3]!='x')&&(board[3]!='o')) board[3]='x'; break; case 5: if ((m==5)&&(board[4]!='x')&&(board[4]!='o')) board[4]='x'; break; case 6: if ((m==6)&&(board[5]!='x')&&(board[5]!='o')) board[5]='x'; break; case 7: if ((m==7)&&(board[6]!='x')&&(board[6]!='o')) board[6]='x'; break; case 8: if ((m==8)&&(board[7]!='x')&&(board[7]!='o')) board[7]='x'; break; case 9: if ((m==9)&&(board[8]!='x')&&(board[8]!='o')) board[8]='x'; default: cout << "Cannot move there!" << endl; } } //////////////////////////////////////////////////// ////////// Main Funciton ///////////////////////// //////////////////////////////////////////////////// void main() { board[0]=' '; board[1]=' '; board[2]=' '; board[3]=' '; board[4]=' '; board[5]=' '; board[6]=' '; board[7]=' '; board[8]=' '; int Game[9]={3,5,7,8,1,-1,-1,-1,-1}; int Next[9]; char x; cout << "Would you like to play a game of Tic Tac Toe (Y/N)?" << endl; cin >> x; if (x=='y') game=false; else if (x=='n') game=true; while (!game) { for (int count=0; count<9; count++) { cout << "Choose a number between 1 and 9 to move" << endl; drawboard(); if ((count==0)||(count==2)||(count==4)||(count==6)||(count==8)) { moves(Game[count]); }else { if (safe(Game[count])) { cout << "Game is Safe!" << endl; } } } if (count==9) { game=true; } } } void drawboard() { cout << board[0] << "|" << board[1] << "|" << board[2] << endl; cout << board[3] << "|" << board[4] << "|" << board[5] << endl; cout << board[6] << "|" << board[7] << "|" << board[8] << endl; }



LinkBack URL
About LinkBacks


