Jump to content



Photo

PHP, JQUERY Tic Tac Toe

tic tac toe php jquery

  • Please log in to reply
23 replies to this topic

#1 xScence

xScence

    Neowinian

  • Joined: 01-January 13

Posted 24 July 2013 - 19:50

Hi all. Im trying to figure out how can i make tic tac toe with php and jquery and AI. If anyone can give me some examples,logic i'll be happy. Thanks to all.




#2 threetonesun

threetonesun

    Neowinian Senior

  • Tech Issues Solved: 1
  • Joined: 26-February 02

Posted 24 July 2013 - 19:59

Er, you wouldn't need php or jquery for that, you could write it all in javascript, unless you had some desire to log win/loss results. Hell, you could even do that for one player locally.

 

Figure out how to store the data (hint: arrays), then figure out the test cases. It's not hard, since there's no such thing as winning in tic-tac-toe, only not losing.



#3 OP xScence

xScence

    Neowinian

  • Joined: 01-January 13

Posted 24 July 2013 - 20:20

It must be on php and ajax / jquery i know i can only wtite it on js but it need to be php + ajax / jquery



#4 jren207

jren207

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 06-February 04
  • Location: Lincolnshire, UK
  • OS: Windows 7
  • Phone: Samsung Galaxy Nexus

Posted 24 July 2013 - 22:03

So is this a game of Tic Tac Toe played over the Internet between two computers?

I guess you'd need to POST the moves of Player 1 using AJAX to a PHP script (adding this to a DB), then Player 2's browser would be polling the server using another PHP script (querying the DB) and an AJAX GET request to update the game on their end, and vice-versa?

#5 +Nik L

Nik L

    Where's my pants?

  • Tech Issues Solved: 2
  • Joined: 14-January 03

Posted 24 July 2013 - 22:37

Seeing as it MUST be PHP/JQuery, can I ask, honestly - are you asking for homework help?



#6 Original Poster

Original Poster

    C++ n00b

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7, backtrack 5, OSx 10.6

Posted 25 July 2013 - 04:22

sounds like some work i got set a long time ago ;) haha :p you need to be more specific... what do you want the game to do.



#7 OP xScence

xScence

    Neowinian

  • Joined: 01-January 13

Posted 25 July 2013 - 05:46

Well when i click somewhere AI to click too after my move. Me click -> AI click -> Me Click -> AI click and so on till some one wins or its ties. I just need some logic and examples thats all.



#8 Original Poster

Original Poster

    C++ n00b

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7, backtrack 5, OSx 10.6

Posted 25 July 2013 - 13:38

Well when i click somewhere AI to click too after my move. Me click -> AI click -> Me Click -> AI click and so on till some one wins or its ties. I just need some logic and examples thats all.

ok well personally I would store all the moves in a PHP array ..but as for the "AI" ...its a loose term its actually simulated AI ....it gives the impression of intelligence and while you may or may have not known that is irrelevant what you have to remember is not matter what... you are going to have to program all its moves.. whether you right a mathmatical algorithm or if you simply write a database full of possible outcomes 

 

I would have to sit down and think about it but personal I would go with a lengthy algo ...you can write a list of functions but the main thing you need to do is make it play one move ahead then return the previous step. its hard to explain but not hard to program lol



#9 OP xScence

xScence

    Neowinian

  • Joined: 01-January 13

Posted 25 July 2013 - 14:21

i don't know how i can make the clicks. Which is better to have 9 divs and when to click them to send some ajax or buttons ?



#10 Original Poster

Original Poster

    C++ n00b

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7, backtrack 5, OSx 10.6

Posted 25 July 2013 - 14:23

i don't know how i can make the clicks. Which is better to have 9 divs and when to click them to send some ajax or buttons ?

its what ever you are more comfortable with coding ? with this there is no standard and with code there normally is not just one way... do the way you think you can or atleast prefer the sounds of.... or ...do both ? either way you are going to have to link to ajax for real time :L 



#11 JonnyLH

JonnyLH

    I say things.

  • Joined: 15-February 13
  • Location: UK
  • OS: W8, W7, WP8, iOS, Ubuntu
  • Phone: Nokia Lumia 920

Posted 25 July 2013 - 14:25

Sounds quite a fun piece of homework haha.

 

How about doing a simple 3x3 table, with numerical id's. Use JQuery to add an event listener to look out for a click of a TD, grab the ID of the table and change the background image of that to one of the symbols. Once that's done, call an AI function which looks out for which images are in the grid, and where it could make a line using the numerical ID's?

 

If you need that logic doing in PHP, store the results in a DB once called to make a move and do the logic that way. Or, if you want something simple. just fire off the state of the full table every move so you can work out the AI's move without needed a DB.



#12 OP xScence

xScence

    Neowinian

  • Joined: 01-January 13

Posted 25 July 2013 - 14:27

Yep i understand this Jonny but im soo poor in ajax programming can i have some examples, thanks.



#13 +Nik L

Nik L

    Where's my pants?

  • Tech Issues Solved: 2
  • Joined: 14-January 03

Posted 25 July 2013 - 14:31

Yup, someone asking people to do their homework.  If you are poor at ajax, you won't learn by people doing it for you.



#14 JonnyLH

JonnyLH

    I say things.

  • Joined: 15-February 13
  • Location: UK
  • OS: W8, W7, WP8, iOS, Ubuntu
  • Phone: Nokia Lumia 920

Posted 25 July 2013 - 14:35

<table>
	<tr>
		<td id='1-1'></td>
		<td id='1-2'></td>
		<td id='1-3'></td>
	</tr>
	<tr>
		<td id='2-1'></td>
		<td id='2-2'></td>
		<td id='2-3'></td>
	</tr>
	<tr>
		<td id='3-1'></td>
		<td id='3-2'></td>
		<td id='3-3'></td>
	</tr>
</table>
$('td').click(function(e) {
	makeMove(e.target.id);
});

function makeMove(square) {
	$.ajax("?square="+square function(data){
		//Set table background
		aiMove();
	});
}

function aiMove() {
	//AI Calculations
	//AJAX or 
}

That's very simple, but does that help? Just don't want to do your homework for you ;)



#15 Bag

Bag

    I press buttons to make the pattern of light correct.

  • Joined: 03-January 05
  • Location: Earth

Posted 25 July 2013 - 14:39

Seems kinda pointless involving PHP to be honest, makes much more sense for it all to be done in the browser (unless you want to add multi-player (node would be better here) or just save scores server side).

 

Only reason i can see to involve php would be if its some badly spec'ed out homework "/





Click here to login or here to register to remove this ad, it's free!