Lesson 12 assignment

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Psychoman
Posts: 36
Joined: June 13th, 2013, 2:12 pm

Lesson 12 assignment

Post by Psychoman » June 26th, 2013, 8:26 am

Hello dear friends,I'm here with a problem ( again ).Something bad happens and I don't know what to do.It's the 1 thing about logic of a smarter AI.I did it ,like to see through rows and columns and if 2 symbols (X or O) are equal (in row or column , haven't done diagonally yet) we put AI symbol on a free spot.The first move is random.But this cool thing doesn't work :( and I need your help.

Code: Select all

//AI move
void Game::SmartAIMove()
{
	do
	{
	    if( firstTurn == true )
		{
			AIMoveX = rand() % 3;
			AIMoveY = rand() % 3;
			firstTurn = false;
		}
		else
		{
                                  //All Variants
			IFforSmartAI(0,1,2,0,0,true);
			IFforSmartAI(3,4,5,1,0,true);
			IFforSmartAI(5,6,7,2,0,true);
			IFforSmartAI(0,3,6,0,0,false);
			IFforSmartAI(1,4,7,0,1,false);
			IFforSmartAI(2,5,8,0,2,false);
	//		IFforSmartAI(0,4,8);
	//		IFforSmartAI(2,4,6);
		}
	} while( GetSquareState( AIMoveX,AIMoveY )!= EMPTY );

}
void Game::IFforSmartAI( int index0,int index1,int index2,int row,int column,bool incCol )
{
	if( ( GetSquareState(index0) == GetSquareState(index1) )!= EMPTY && GetSquareState(index2) == EMPTY )
			{
				//Last element
				AIMoveX = column;
				AIMoveY = row;
				//Move horizontally
				if(incCol == true)
				{
					AIMoveX = 2;
				}
				//Vertical
				else
				{
					AIMoveY = 2;
				}
			}
	else if( ( GetSquareState(index1) == GetSquareState(index2) )!= EMPTY && GetSquareState(index0) == EMPTY )
			{
				//First element
				AIMoveX = column;
				AIMoveY = row;
			}
	else if( ( GetSquareState(index0) == GetSquareState(index2) )!= EMPTY && GetSquareState(index1) == EMPTY )
			{
				AIMoveX = column;
				AIMoveY = row;
				//2 element
				if(incCol == true)
				{
					AIMoveX = 1;
				}
				else
				{
					AIMoveY = 1;
				}
			}

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Lesson 12 assignment

Post by LuisR14 » June 26th, 2013, 9:20 am

Psychoman wrote: if( ( GetSquareState(index0) == GetSquareState(index1) )!= EMPTY && GetSquareState(index2) == EMPTY )
...
else if( ( GetSquareState(index1) == GetSquareState(index2) )!= EMPTY && GetSquareState(index0) == EMPTY )
...
else if( ( GetSquareState(index0) == GetSquareState(index2) )!= EMPTY && GetSquareState(index1) == EMPTY )
...
how would that even work? o.o
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Psychoman
Posts: 36
Joined: June 13th, 2013, 2:12 pm

Re: Lesson 12 assignment

Post by Psychoman » June 26th, 2013, 10:44 am

Well at first it checks if there are 2 similar characters X or O, thats why there's a "!= Empty",then it checks if the 3 character is not occupied and if not it puts character.3 if statements because 3 different combinations can be , I mean like -XX,X-X,XX-.

Psychoman
Posts: 36
Joined: June 13th, 2013, 2:12 pm

Re: Lesson 12 assignment

Post by Psychoman » June 26th, 2013, 3:00 pm

I just don't get why it wouldn't work

brotallica
Posts: 2
Joined: June 30th, 2013, 1:47 am

Re: Lesson 12 assignment

Post by brotallica » June 30th, 2013, 1:49 am

where did you get column and row from and how do they make the AI move?
[EDIT] Nvm, I looked it over and figured it out, still trying to make my own =S

brotallica
Posts: 2
Joined: June 30th, 2013, 1:47 am

Re: Lesson 12 assignment

Post by brotallica » June 30th, 2013, 3:40 am

btw idk if this is in your actual code but the one you posted is missing a final "}"

Psychoman
Posts: 36
Joined: June 13th, 2013, 2:12 pm

Re: Lesson 12 assignment

Post by Psychoman » July 4th, 2013, 4:28 pm

I've already done that ,just divided this if structure to obvious parts and it worked and I think I just missed a '}' typing the post.

Post Reply