Пример #1
0
<?php

try {
    echo '<pre>';
    // global config
    require_once realpath(dirname(__FILE__)) . '/../../htdocs/config.inc';
    // bot config
    require_once TOOLS . 'npc/config.specific.php';
    // needed libs
    require_once LIB . 'Default/SmrMySqlDatabase.class.inc';
    require_once LIB . 'Default/Globals.class.inc';
    $db = new SmrMySqlDatabase();
    debug('Script started');
    define('SCRIPT_ID', $db->getInsertID());
    $db->query('UPDATE npc_logs SET script_id=' . SCRIPT_ID . ' WHERE log_id=' . SCRIPT_ID);
    define('NPCScript', true);
    $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
    $engine = proc_open(UCI_CHESS_ENGINE, $descriptorSpec, $pipes);
    $toEngine =& $pipes[0];
    $fromEngine =& $pipes[1];
    function readFromEngine($block = true)
    {
        global $fromEngine;
        stream_set_blocking($fromEngine, $block == true ? 1 : 0);
        while (($s = fgets($fromEngine)) !== false) {
            debug('<-- ' . trim($s));
            stream_set_blocking($fromEngine, 0);
        }
    }
    function writeToEngine($s, $block = true, $read = true)
    {