Ejemplo n.º 1
0
function begin($startX, $startY)
{
    if ($startY > 0 && $startY == $startX) {
        begin($startY - 1, $startY - 1, $board);
    }
    if ($startX > 0) {
        begin($startX - 1, $startY, $board);
    }
    $board = newBoard();
    $board[$startY][$startX] = 1;
    //the first move location will be "1"
    echo "Starting at: (" . $startY . "," . $startX . ")\n";
    $solution = solve($board, $startY, $startX, 2);
}
Ejemplo n.º 2
0
// colours
while ($p1 != 'R' && $p1 != 'Y') {
    $p1 = strtoupper(readline("player 1, please choose a colour (R/Y): "));
}
if ($p1 == 'R') {
    $p2 = 'Y';
} else {
    $p2 = 'R';
}
// number of players
$players = 0;
while ($players != 1 && $players != 2) {
    $players = readline("number of players (1/2): ");
}
// game
$board = newBoard();
$colours = [$p1, $p2];
while (!$win) {
    foreach ($colours as $idx => $colour) {
        if ($idx == 1 && $players == 1) {
            $cpu = 1;
        } else {
            $cpu = 0;
        }
        $board = go($board, $colour, $cpu);
        if ($board == 1) {
            $win = true;
            break;
        }
    }
}