Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I've been obsessing with Tic Tac Toe recently, with my post of a bot that plays best-defense against a human player. Along the way I bumped into this thread from 4 years ago, which shows a somewhat golfed and obfuscated script that plays two humans.

I posted my own entry, but wasn't satisfied with it. After some more tinkering and an epiphany or two, I came up with this, measuring in at 159 characters:

$_="123 456 789 147,258,369,159,357";$p=X;sub d{/.{12}/s;print$&.$p;die$_ for@_} n:d;$m=<>until$m=~/\d/&&s/$&/$p/g;/$p{3}/?d$p:!/\d/?d"Tie":$p=~y/XO/OX +/;goto n
The challenge: Create a script that follows the rules below, in as few characters as possible.

Rules:

  • Standard Tic Tac Toe rules must be followed (e.g., the board is 3x3, each square can be played only once, X and O alternate turns.)
  • A representation of the current game state (the board) must be displayed after each turn. This can take any form that is understandable. (Mine is the squares being numbered 1 through 9 and displayed on a 3x3 console grid)
  • An indicator of who's (X or O) turn it is must be displayed before each turn.
  • A mechanism to accept and validate input must be provided (e.g., it's X's turn until he picks a legal square).
  • A winning move must exit the game and display who won.
  • A "cat" game (tie) must exit and display "Tie" or "Cat" after the last square has been played.

    In reply to (Golf) Tic Tac Toe by delirium

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (13)
    As of 2014-07-29 19:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (226 votes), past polls