<?php
$message = "";
$grid = [0,1,0,1,0,2,2,0,0];


//
// TODO
//
//

function isWinner($grid, $player)
{
	$winStates = array
		(
			array(0, 1, 2), array(3, 4, 5), array(6, 7, 8),     // Horizontal
			array(0, 3, 6), array(1, 4, 7), array(2, 5, 8),     // Vertical
			array(0, 4, 8), array(2, 4, 6)                      // Diagonal
		);

	foreach ($winStates as $winState)
	{
		if ($grid[$winState[0]] == $player &&
			$grid[$winState[1]] == $player &&
			$grid[$winState[2]] == $player)
		{
			return true;
		}
	}
	return false;
}

function noWinner($grid)
{
	for($i = 0; $i < 9; $i++)
		if ($grid[$i] == 0) 
			return false;

	return true;
}

function displayGrid($grid)
{
	echo '<table class="morpion">';
	for ($i = 0; $i < 3; $i ++){
		echo "<tr>";
		for ($j = 0; $j < 3; $j ++){

			echo "<td>";

			$pos = 3*$i + $j;
			if ($grid[$pos] == 0)
				echo "<a href='?pos=$pos'></a>";
			if ($grid[$pos] == 1)
				echo '<i class="fa fa-times" aria-hidden="true"></i>';
			if ($grid[$pos] == 2)
				echo '<i class="fa fa-circle-o" aria-hidden="true"></i>';

			echo "</td>";

		}

		echo "</tr>";
	}

	echo "</table>";
}
