I've been doing a simple Tic-Tac-Toe with PHP, generating only HTML code.A few notes:I didn't bother yet to give an AI to the opponents (the Os), and it is intentional. There is no CSS style to it, I intend to append it with a css file.  tictactoe.php is naturally the name of the script itself, so each links are refering to the page itself.Now I don't know if I did everything correctly, here are my concern:If I want to expand the functionalities of the game in the future (adding javascript, opponent AIs, new game features), I fear that the structure of the code is not adapted for it. Should I change my code so it is Object Oriented? EDIT I have in mind to add new feature to the game, like powers who would change the state of the board, like rewind to a previous state and; some css and javascript in a non-intrusive way and add some way to check if options are disabled (like javascript/flash), or check for the version of the browser for html5/css3 features.As for now, it is easy to cheat and directly introduce the wished board state. I would like to prevent that, and if possible without using javascript, as I want the game to be playable also without it.<table><?php//Determine if a player as aligned three of its symbols and return the id of the player (1//for X Player, -1 for O Player(Computer)). Otherwise return 0;function isWinState($board){    $winning_sequences = '012345678036147258048642';    for($i=0;$i<=21;$i+=3){        $player = $board[$winning_sequences[$i]];        if($player == $board[$winning_sequences[$i+1]]){            if($player == $board[$winning_sequences[$i+2]]){                if($player!=0){                    return $player;                }            }         }       }    return 0;}//Player O plays its turn at randomfunction OsTurn($board){    if(in_array(0,$board)){        $i = mt_rand(0,8);        while($board[$i]!=0){            $i = mt_rand(0,8);        }        $board[$i]=-1;    }    return $board;}$winstate = 0;$values = array();if(empty($_GET['values'])){    //initializing the board    $values = array_fill(0,9,0);    //determine who begins at random    if(mt_rand(0,1)){        $values = OsTurn($values);    }}else{    //get the board    $values = explode(',',$_GET['values']);    //Check if a player X won, if not, player 0 plays its turn.    $winstate = isWinState($values);    if($winstate==0){        $values = OsTurn($values);    }    //Check if a player 0 won    $winstate = isWinState($values);    }//Display the board as a tablefor($i=0;$i<9;$i++){    //begin of a row    if(fmod($i,3)==0){echo '<tr>';}    echo '<td>';    //representation of the player token, depending on the ID    if($values[$i]==1){        echo 'X';    }else if($values[$i]==-1){        echo 'O';    }else{        //If noone put a token on this, and if noone won, make a link to allow player X to        //put its token here. Otherwise, empty space.        if($winstate==0){            $values_link = $values;            $values_link[$i]=1;            echo '<a href=tictactoe.php?values='.implode(',',$values_link).'>&nbsp;</a>';        }else{            echo '&nbsp;';        }    }    echo '</td>';    //end of a row    if(fmod($i,3)==2){echo '</tr>';}}?></table><?php//If someone won, display the messageif($winstate!=0){    echo '<p><b>Player '.(($winstate==1)?'X':'O').' won!</b></p>';}?>
Simple Tic-Tac-Toe PHP/Pure HTML
php;game
There isn't really a reason to make this more object-oriented if you don't need to. To add more AI constructs, for example, you can do:switch ($aiLevel) {   case 1: $values = $OsTurn($values);   case 2: $values = $betterAi($values);   case 3: $values = $unbeatableAi($values);}Adding more features could be done in a similiar manner. I'm not sure exacly wht you have in mind, so I can only make some general comments. Break down everything into functions, and make sure that it's easy to see the flow of the program. The way you've structured your code is good. It should not be difficult to add more features if you use similiar style.CSS won't affect your script; it just changes how the page looks. You'll just need to be sure you use the right elements when outputting html. Javascript may be trickier, but there are many ways of doing that including form elements (possibly hidden) and page submits. There may be other ways that I'm not aware of as I'm not primarily a web programmer.I believe when you are talking about cheating, you're saying that you can send a winning board value set to the script by typing the URL yourself. To prevent this you need a way to preserve state. A cookie would be an easy way to start; store the current state of the board in it after every page call, and check that the only change was the placing of another piece. A more robust, but somewhat more involved, solution would be to use session variables to store the state. This would avoid the cookys are bad problem and the possibility that someone might fake the cooky!