6 Replies - 808 Views - Last Post: 17 August 2012 - 11:16 PM Rate Topic: -----

#1 EarlyWorm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 08:55 PM

I am having a problem with my TTT ai. I need an ai that would check for blank space and randomly put the piece in.
Can any1 give any suggestion?
Part of my code is as below.

void getMove(bool player)
{
	int GetAIMove()
	{ //here's the part i need help with
}

	int choice;
	if (player)
	{
		cout << "Enter Your Move; "; << endl;
		cin >> choice;
	}
	else
	{
		choice = GetAIMove();
		cout >> "Computer's Move: " >> choice >> endl;
	}
	
	while(choice > 9)
	{
		cout << "Invaild Move!" << endl;
		cout << "Enter number between 1 to 9 ONLY!" << endl;
		cout << "Enter your move again!" << endl;

		cin >> choice;
	}


	if(correctDrop(choice))
	{
		if(player == true)
			board[choice-1] = 'X';
		else
			board[choice-1] = 'O';
	}
	else
		getMove(player);
	display();
}


Is This A Good Question/Topic? 0
  • +

Replies To: Help Needed with AI IN Tic Tac Toe

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,125
  • Joined: 05-May 12

Re: Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 09:08 PM

Wow! That code looks amazingly like my post here. It even includes the misspelling from post #1 on that thread. Are you sure that is your code or every1play's code?

What have you tried so far? Can you show us your code?

This post has been edited by Skydiver: 17 August 2012 - 09:11 PM

Was This Post Helpful? 0
  • +
  • -

#3 every1play  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 06-July 12

Re: Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 09:12 PM

Hey dude!
Did u just copy my code? Anyways thanks to skydiver i solved that problem.
U would need to check for blank space using counter. Then put in the code.
Was This Post Helpful? 1
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,125
  • Joined: 05-May 12

Re: Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 09:17 PM

If we, for a moment, assume that it was just some weird fluke that your code here happened to parallel the code in the other thread, then there is not enough information. What is the significance of the choice values 1-9? How will GetAIMove() access the board data? Is the board data global or something that should be passed in? If it is global, what is the name of the global variable? Is the AI allowed the leave the board with values of it trial moves or does it need to cleanup after itself?

On the other hand, if you tell us that your code also looks like the code on the other thread, there maybe enough information to start figuring out how to make an AI.

This post has been edited by Skydiver: 17 August 2012 - 09:18 PM

Was This Post Helpful? 0
  • +
  • -

#5 EarlyWorm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

Re: Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 09:20 PM

I admit that that's not my code.....
I just wanted to know how to make an ai for my own reference i just browse through the web and saw that thread but i still dun understand what Skydiver said.
Sorry for all these inconvenience caused.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,125
  • Joined: 05-May 12

Re: Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 09:46 PM

View Postevery1play, on 17 August 2012 - 09:12 PM, said:

Hey dude!
Did u just copy my code? Anyways thanks to skydiver i solved that problem.
U would need to check for blank space using counter. Then put in the code.


Actually it was Salem_c who helped you the most by suggesting the method for finding a good move for the computer. I was just the sarcastic a**hole trying to get you to code it up. I'm glad that you got your assignment done because you had some pretty good code shaping up in that thread, and all you really needed was just to get the AI implemented.

This post has been edited by Skydiver: 17 August 2012 - 09:46 PM

Was This Post Helpful? 0
  • +
  • -

#7 TwoOfDiamonds  Icon User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 272
  • Joined: 27-July 12

Re: Help Needed with AI IN Tic Tac Toe

Posted 17 August 2012 - 11:16 PM

Hmm. I think it would be better if your the computer would firstly try to get the middle cell , then the ones in the corners then the rest :)
Of course , in that case that he couldn't win with the next move nor he couldn't lose in the next turn .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1