Thread: error

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    73

    error

    When i use
    Code:
    nth_next_game(x, gamestate[9]);
    I get this error;
    Code:
    C:\Program Files\Microsoft Visual Studio\MyProjects\Tic Tac Toe\MichaelNeill.cpp(131) : error C2664: 'nth_next_game' : cannot convert parameter 2 from 'int' to 'int []'
    Any know whats wrong with it. Here is my code.

    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 gamestate[9]);
    bool game=false;
    void drawboard(int[]);
    int select_computer_move(int []);
    void playermove(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;
    	}
    
    
    
    	int select_computer_move(int n, int game[9], int gamestate[9])
    	{
    		for (n=0; n<=9; n++)
    		{
    			if (safe(game))
    			{
    				nth_next_game(n, game[n], gamestate[n]);
    			}
    		}
    
    
    		return 0;
    	}
    
    	void playermove(int m, int gamestate[9])
    	{
    		if ((m==1)&&(gamestate[0]!=0)&&(gamestate[0]!=1))
    			gamestate[0]=0;
    		else
    
    		if ((m==2)&&(gamestate[1]!=0)&&(gamestate[1]!=1))
    			gamestate[1]=0;
    		else
    
    		if ((m==3)&&(gamestate[2]!=0)&&(gamestate[2]!=1))
    			gamestate[2]=0;
    		else
    
    		if ((m==4)&&(gamestate[3]!=0)&&(gamestate[3]!=1))
    			gamestate[3]=0;
    		else
    
    		if ((m==5)&&(gamestate[4]!=0)&&(gamestate[4]!=1))
    			gamestate[4]=0;
    		else
    
    		if ((m==6)&&(gamestate[5]!=0)&&(gamestate[5]!=1))
    			gamestate[5]=0;
    		else
    
    		if ((m==7)&&(gamestate[6]!=0)&&(gamestate[6]!=1))
    			gamestate[6]=0;
    		else
    
    		if ((m==8)&&(gamestate[7]!=0)&&(gamestate[7]!=1))
    			gamestate[7]=0;
    		else
    
    		if ((m==9)&&(gamestate[8]!=0)&&(gamestate[8]!=1))
    			gamestate[8]=0;
    	}
    
    	////////////////////////////////////////////////////
    	//////////  Main Funciton  /////////////////////////
    	////////////////////////////////////////////////////
    
    	int main()
    	{
    		int gamestate[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1};
    
    		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 i=0; i<=9; i++)
    			{
    				if ((i%2)==0)
    				{
    					int x;
    
    					cin >> x;
    
    					playermove(x, gamestate[9]);
    				}else
    
    				if ((i%2)!=0)
    				{
    					selct_computer_move(gamestate[9]);
    				}
    			}
    		}
    
    		return 0;
    
    	}

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    o this is a tic tac toe game

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    93
    too lazy to trace through ur code but it appears u are passing the array in wrong..

    nth_next_game(x, gamestate[9]);

    gamestate[9] is a value in gamestate at index 9

    if u want to pass the whole array try

    nth_next_game(x, gamestate);
    when u are inside the function then u can access the individual values in the array..

    hope this helps alittle..

    edit: ah i was beatin' to the punch

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Yeah i remembered that my teacher did that, so i fixed it. Um now when i compile i get this error message.

    Code:
    MichaelNeill.obj : error LNK2001: unresolved external symbol "int __cdecl select_computer_move(int * const)" (?select_computer_move@@YAHQAH@Z)
    Any suggestions?

  5. #5
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Unresolved external symbol usually means that your declaration and definition of a function or variable don't match. In this case, you declare select_computer_move as (int []) but define it as (int, int [], int [])

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    how can that be so when i declared it as select_computer_move(int []) and defined it as select_computer_move(gamestate); and gamestate is an array?

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    and it tells me i have one unresolved exturnal.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM