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

7

1

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

Wally

Posted 2014-02-10T19:32:20.407

Reputation: 483

7code-golf and popularity-contest should never be together in the same question. One excludes the other. – Fez Vrasta – 2014-02-10T19:40:46.230

2

If you are unsure about the scoring for a problem, use the sandbox before posting.

– Justin – 2014-02-10T21:13:24.253

1Quincunx: 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 – 2014-02-10T22:03:03.690

2Someone added a close-vote as off-topic. I can't see how this is off-topic. – Victor Stafusa – 2014-02-11T00:59:39.120

Answers

3

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

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

screenshot

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

Doorknob

Posted 2014-02-10T19:32:20.407

Reputation: 68 138

+1 for exceeding the 2 player criteria and allowing INF players at once! – Wally – 2014-02-12T13:09:32.823

Accepted this as the answer since it nearly meet the spec and had no competitors. Good job. – Wally – 2014-03-01T04:57:10.267

@Wally Lol, sorry, I never finished it :-P I might tomorrow morning. – Doorknob – 2014-03-01T04:57:56.950

Update: Due to a site reorganization, the misc has been removed and it's now just http://keyboardfire.com/tictactoegolf/t.php. – Doorknob – 2014-11-23T17:03:03.793