Lesson 12 homework

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
simplicity
Posts: 18
Joined: July 10th, 2012, 6:55 pm

Lesson 12 homework

Post by simplicity » July 11th, 2012, 12:31 am

I just want to say that these are the best tutorials on programming I've watched. Would like to thank chili if he reads this.

I was wondering how you guys did the homework. I've nearly finished making an algorithm that plays perfectly(code is below).

I originally had it checking for conditions like

Code: Select all

if(s1==X && s2==X && s0=EMPTY){ 
AIMoveX=0;
AIMoveY=0;
}
However, if the computer goes first, then you have a sure way of either winning and drawing.

I hope he covers more advance AI techniques later on.

But, was wondering how you do the next part I.e. make it move the cursor towards it. Wouldn't you have to create a new function that changes the position of the cursor. Can someone give me a hint on how they did it?

Code: Select all

void Game::AIGetMoveRand()
{
	if(nTurns== 0)
	{
		AIMoveX = 0;
		AIMoveY = 0;
	}

	if(nTurns==2)
	{
		if(s4==O)
		{
			AIMoveX=2;
			AIMoveY=2;
		} else if (s1==EMPTY&& s2==EMPTY)
		{
			AIMoveX=2;
			AIMoveY=0;
		} else {
			AIMoveX=0;
			AIMoveY=2;
		}
	}

	if(nTurns == 4)
	{
		if(s8==X){
			AIMoveX=2;
			AIMoveY=0;
		} else if(s2==X && s1==EMPTY){
			AIMoveX=1;
			AIMoveY=0;
		} else if(s2==X && s1==O)
		{
			AIMoveX=1;
			AIMoveY=1;
		} else if(s3==EMPTY&& s6==X)
		{
			AIMoveX=0;
			AIMoveY=1;
		} else {
			AIMoveX=1;
			AIMoveY=1;
		}
	}
	
	

}
Is there a way to stay within a certain possibility and still get out the information I.e. the AIMove.

For example if I knew he played on the centre, is there a way to stay in the loop that is player 2 played O in the centre on turn 1 and not have to check every possibility again?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson 12 homework

Post by chili » July 11th, 2012, 11:12 am

We will likely be covering AI search someday. If you search the forum you can find the solution that I created. It works by first searching for lines to play to win, then lines for blocking an opponent's win, then lines where there are 2 empty and 1 with the AI mark, and then it plays empty squares, preferring center over corner, corner over side.
Chili

Post Reply