# Graphical, networked, two-(human)-player Tic-Tac-Toe

Create a Tic-Tac-Toe game that allows two human players to play against each other using two networked devices.

Requirements:

1. Network play.
2. Program must let both players know whose turn it is.
3. Program must show who won and how (like drawing a line through the three in a row).
4. Graphical game board displayed for both players.
5. Player moves inputted "graphically" (point and click, etc...).
6. Enforce all Tic-Tac-Toe rules.

Preferred:

1. Any libraries are allowed but smaller libraries are better.
2. Support as many different platforms/devices as possible.
3. Make it "pretty".

I would love to invent scoring that would take into account the "Preferred" points, but that appears impossible. So vote for the code that does the best on the "Preferred" points.

Scoring:

• byte count / vote count
• lowest score wins
• code-golf and popularity-contest should never be together in the same question. One excludes the other. – Fez Vrasta Feb 10 '14 at 19:40
• If you are unsure about the scoring for a problem, use the sandbox before posting. – Justin Feb 10 '14 at 21:13
• Quincunx: I wasn't unsure of scoring. I just knew my preferred scoring was impossible. Fez Vrasta: I had hoped that byte count/vote count was a clever way to combine code-golf and popularity-contest! – Wally Feb 10 '14 at 22:03
• Someone added a close-vote as off-topic. I can't see how this is off-topic. – Victor Stafusa Feb 11 '14 at 0:59

# PHP, work in progress (474 chars / 2 upvotes = 237 score)

It's fully functional except it doesn't have win detection yet.

What I really like about this solution is that I only learned PHP about 3 days ago, so the code is probably terrible. :D

### t.php, 474 chars (newlines can be removed and are there only for readability):

<style>#d>*{display:block;border:1px solid #000;width:50px;height:50px;float:left;text-align:center}#d{width:160px}</style><div id=d><?php
$f=file("a");$p=$_GET["p"];if($p!="x"&&$p!="o")die(); if(isset($_GET["m"])){$s=$f[0];$s[intval($_GET["m"])]=$p;fwrite(fopen('a','w'),$s.($f[1]=='x'?'o':'x'));echo"<a href='t.php?p=$p'>back</a>";}
else{$i=0;while($i<9){$s=($p==$f[1]&&$f[0][$i]=='.')?'a':'div';echo"<$s href='t.php?p=$p&m=$i'>".$f[0][$i++]."</$s>";}echo$f[1]."'s turn";}
?>


### reset.php, 57 chars

<?php fwrite(fopen('a','w'),"..........\nx");?>Reset done


It's live on my website. Player X should go to this URL:

http://keyboardfire.com/misc/tictactoegolf/t.php?p=x


And Player O should go here:

http://keyboardfire.com/misc/tictactoegolf/t.php?p=o


(don't worry, I added a check that only lets player "o" or "x" in so that you can't do any fancy XSS stuff :P)

To reset, go here:

http://keyboardfire.com/misc/tictactoegolf/reset.php


Obviously, it's really easy to cheat (moving for the other player, randomly resetting the board, etc.), but it's code golf so it doesn't matter :P

• +1 for exceeding the 2 player criteria and allowing INF players at once! – Wally Feb 12 '14 at 13:09
• Accepted this as the answer since it nearly meet the spec and had no competitors. Good job. – Wally Mar 1 '14 at 4:57
• @Wally Lol, sorry, I never finished it :-P I might tomorrow morning. – Doorknob Mar 1 '14 at 4:57
• Update: Due to a site reorganization, the misc has been removed and it's now just http://keyboardfire.com/tictactoegolf/t.php. – Doorknob Nov 23 '14 at 17:03