7 || $col<0 || $col>7) // out of bounds return false; if (($currentpiece = $board[($row*8)+$col]) == $otherpiece) $othercount++; else return (($othercount > 0) && ($currentpiece == $piece)); // sandwiched opponent } return false; } function update_board($board, $newboard) { // Find the move just taken. Trust the bot not to cheat. for ($i=0, $position=-1; $i0) foreach (get_directions() as $direction) if (has_line($newboard, $piece, $position, $direction[0], $direction[1])) $newboard = flip_pieces($newboard, $piece, $position, $direction[0], $direction[1]); return $newboard; } function flip_pieces($board, $piece, $position, $rowchange, $colchange) { $otherpiece = $piece == 'X' ? 'O' : 'X'; $othercount = 0; $row = (int) ($position / 8); $col = $position % 8; for ($i=0; $i<9; $i++) { $row += $rowchange; $col += $colchange; if ($row<0 || $row>7 || $col<0 || $col>7) // out of bounds return; if ($board[($row*8)+$col] == $otherpiece) $board[($row*8)+$col] = $piece; else return $board; } return $board; } ?>