quine-ish tic-tac-toe
Perl, 933 characters

$m=&lt;&lt;'';$_='         ';
sub h{/^(?:...)*(\d)\1\1/|/^.?.?(\d)..\1..\1/|/(\d)...\1...\1/|/^..(\d).\1.\1/&amp;&amp;$1}
sub r{substr($_,$p-1,1)=pop}sub p{my$w=pop;my@b=(0,h==$w||h&amp;&amp;-1);if(!$b[1]&amp;&amp;/ /){$b[1]=-9;
while(/ /g){local($_,$p)=($_,pos);r$w;$r=-(p($w^1))[1];@b=($p,$r)if$r&gt;$b[1]}}@b}
if(($w=h||!/ /)||!@ARGV){$w--&amp;&amp;print+(nobody,X,O)[$w]," wins\n";s/(...)/$1\n/g;
tr/ 23/.XO/;print}else{$w=3;$w^=1for/\d/g;($p=pop)?r($w^1)&amp;&amp;!h&amp;&amp;(($p)=p$w)&amp;&amp;r$w:s/ /2/;
print"\$m=&lt;&lt;'';\$_='$_';\n$m\n$m"}

sub h{/^(?:...)*(\d)\1\1/|/^.?.?(\d)..\1..\1/|/(\d)...\1...\1/|/^..(\d).\1.\1/&amp;&amp;$1}
sub r{substr($_,$p-1,1)=pop}sub p{my$w=pop;my@b=(0,h==$w||h&amp;&amp;-1);if(!$b[1]&amp;&amp;/ /){$b[1]=-9;
while(/ /g){local($_,$p)=($_,pos);r$w;$r=-(p($w^1))[1];@b=($p,$r)if$r&gt;$b[1]}}@b}
if(($w=h||!/ /)||!@ARGV){$w--&amp;&amp;print+(nobody,X,O)[$w]," wins\n";s/(...)/$1\n/g;
tr/ 23/.XO/;print}else{$w=3;$w^=1for/\d/g;($p=pop)?r($w^1)&amp;&amp;!h&amp;&amp;(($p)=p$w)&amp;&amp;r$w:s/ /2/;
print"\$m=&lt;&lt;'';\$_='$_';\n$m\n$m"}


Please note that the blank line in the middle of the script is actually required to be there. (The line breaks at the end of the long lines are not required, other than for legibility, and are not included in the character count.) 

Usage: When the program is run without arguments, it displays the current game state. Since at the start the board is empty, the output will be:

...
...
...


Run the program with an argument between 1 and 9 to claim that square as your move. The program will make its own move and then output a replacement script with the new state. Thus, for example:

$ perl ./qttt 5 &gt; ./qttt-2
$ perl ./qttt-2
O..
.X.
...


On the very first turn only, you may give a move of 0 to indicate that the computer should take the first move. Note that the first player will always be X.

When the game is over, the display output will include a note to that effect:

$ perl ./qttt-4 6 &gt; ./qttt-5
$ perl ./qttt-5
O wins
OXX
OOX
X.O


The program works by doing a standard minimax search of the game tree. (Tic-tac-toe is a small enough game that a full game tree can be generated on every run.) The exception to this is when the computer moves first -- in this case the initial move to the upper left corner is hard-coded.

Note that this program works in the fashion of a proper quine -- at no point does the script access its own source file in order to produce its output.