<?php error_reporting(E_ALL); ini_set('display_error', 1); /* Autoloaders are soooo nice :) */ require_once 'GetterSetter.php'; require_once 'Localization.php'; require_once 'Sensors.php'; require_once 'Robot.php'; require_once 'Movement.php'; $config = ['pHit' => 0.6, 'pMiss' => 0.2, 'world' => ['green', 'red', 'red', 'green', 'green'], 'probabilityMatrix' => [0, 1, 0, 0, 0], 'biasMatrix' => ['over' => 0.1, 'under' => 0.1, 'exact' => 0.8]]; $moveProgram = [1, 1]; // Let's build us a robot :) $robot = new Robot($config); $robot->setSensor(new Sensors([]))->setLocalization(new Localization([]))->setMovement(new Movement($config['biasMatrix'])); foreach ($robot->getSensor() as $i => $sensorData) { $robot->sense($sensorData); $robot->move($moveProgram[$i]); } $robot->showWorld();
public function testresetName() { $name1 = $this->robot->getName(); $this->robot->reset(); $name2 = $this->robot->getName(); $this->assertNotSame($name1, $name2); $this->assertRegExp('/\\w{2}\\d{3}/', $name2); }
function __construct($args) { parent::__construct($args); $this->username = '******'; $this->password = '******'; if ($this->username == "YOUR VINE USERNAME" or $this->password == "YOUR VINE PASSWORD") { die("[Error] You need to set your Vine's account user/password at /robots/Vine/Vine.php" . PHP_EOL); } }
function __construct($args) { parent::__construct($args); $this->toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); if (!is_object($this->toa)) { die('TwitterOAuth failed to initialize. Check your Twitter credentials at /robots/Twitter/Twitter.php' . PHP_EOL); } $this->toa->get('account/verify_credentials'); if ($this->toa->http_code != 200) { die('Unable to authenticate with Twitter' . PHP_EOL); } // get all friends $friends = $this->toa->get('friends/ids', array('cursor' => -1)); $this->friendIds = array(); foreach ($friends->ids as $id) { $this->friendIds[] = $id; } // get all favorites to prevent re-favorite $favorites = $this->toa->get('favorites', array()); $this->favoritesIds = array(); foreach ($favorites as $fav) { $this->favoritesIds[] = $fav->id; } }
/** * Measurement Update Function * * That's where we are scanning the world trying to find the place where are at. * Updates the internal probability matrix * * @param $input * @param Robot $robot * @return $this */ public function sense($input, Robot $robot) { $retVal = []; // Update measurement foreach ($robot->getProbabilityMatrix() as $index => $p) { if ($input == $robot->getWorld()[$index]) { $retVal[] = $robot->getPHit() * $p; } else { $retVal[] = $robot->getPMiss() * $p; } } // Normalize data $normalisationFactor = array_sum($retVal); foreach ($retVal as $index => $value) { $retVal[$index] = $retVal[$index] * (1 / $normalisationFactor); } $robot->setProbabilityMatrix($retVal); return $this; }
function __construct($args) { parent::__construct($args); echo '[i] If nothing is returned, check if account is private or not exists' . PHP_EOL; echo '[Scraping ...]' . PHP_EOL; }
if ($state['state'] == '0') { $reply = chooseFunctionNum($keyword, $yixin); } elseif ($state['state'] == '1') { $mryw = new Mryw($keyword); $rst = $mryw->get(); $reply = $yixin->makeNews($rst); } elseif ($state['state'] == '2') { $joke = new Joke($keyword); $rst = $joke->getJoke(); $reply = $yixin->makeNews($rst); } elseif ($state['state'] == '3') { $beautiful = new Beautiful($keyword); $rst = $beautiful->getBeautifulPic(); $reply = $yixin->makeNews($rst); } elseif ($state['state'] == '4') { $robot = new Robot($keyword); $rst = $robot->getReply(); if (is_array($rst)) { $reply = $yixin->makeNews($rst); } else { $reply = $yixin->makeText($rst); } } elseif ($state['state'] == '5') { $weather = new Weather($keyword); $reply = $yixin->makeText($weather->getWeatherDetail()); } elseif ($state['state'] == '6') { $youdao = new YouDaoTrans($keyword); $reply = $yixin->makeText($youdao->getTransContent()); } elseif ($state['state'] == '7') { $mobile = new Mobile($keyword); $reply = $yixin->makeText($mobile->getMobileLocation());
public function proceduretest($param1, $param2) { $robot = Robot::towersp($param1, $param2); return $robot; }
/** * Creates a new dance */ function dance_put() { /* User ID ------------------------------------------------- */ $uuid = $this->put("uuid"); $guid = $this->put("guid"); $robot_id = $this->put("robot_id"); $sound_id = $this->put("sound_id"); $robot_name = $this->put("robot_name"); $robot_still = $this->put("robot_still"); $is_entered_into_comp = $this->put("is_entered_into_comp") == 1 ? 1 : 0; /* Save the main data into a json encoded array ------------------------------------------------- */ $move = array("masterTempo" => $this->put("masterTempo"), "neck_tempoMultiplier" => $this->put("neck_tempoMultiplier"), "neck_upDown" => $this->put("neck_upDown"), "neck_leftRight" => $this->put("neck_leftRight"), "rightForearm_reverse" => $this->put("rightForearm_reverse"), "rightForearm_tempoMultiplier" => $this->put("rightForearm_tempoMultiplier"), "rightForearm_amount" => $this->put("rightForearm_amount"), "rightForearm_angle" => $this->put("rightForearm_angle"), "rightUpperArm_reverse" => $this->put("rightUpperArm_reverse"), "rightUpperArm_tempoMultiplier" => $this->put("rightUpperArm_tempoMultiplier"), "rightUpperArm_amount" => $this->put("rightUpperArm_amount"), "rightUpperArm_angle" => $this->put("rightUpperArm_angle"), "leftForearm_reverse" => $this->put("leftForearm_reverse"), "leftForearm_tempoMultiplier" => $this->put("leftForearm_tempoMultiplier"), "leftForearm_amount" => $this->put("leftForearm_amount"), "leftForearm_angle" => $this->put("leftForearm_angle"), "leftUpperArm_reverse" => $this->put("leftUpperArm_reverse"), "leftUpperArm_tempoMultiplier" => $this->put("leftUpperArm_tempoMultiplier"), "leftUpperArm_amount" => $this->put("leftUpperArm_amount"), "leftUpperArm_angle" => $this->put("leftUpperArm_angle"), "hips_tempoMultiplier" => $this->put("hips_tempoMultiplier"), "hips_upDown" => $this->put("hips_upDown"), "hips_leftRight" => $this->put("hips_leftRight")); $encoded_move = json_encode($move); /* Save it ------------------------------------------------- */ $dance = new Dance(); $dance->get_by_guid($guid); if ($dance->exists()) { $dance->move = $encoded_move; $dance->date_updated = mktime(); $dance->robot_name = $robot_name; $dance->robot_still = $robot_still; $dance->is_entered_into_comp = $is_entered_into_comp; // Save the soundtrack to the dance $soundtrack = new Soundtrack(); $soundtrack->get_by_id($sound_id); $dance->save($soundtrack); $output = $dance->save() ? $dance->guid : 'Error'; } else { /* New dance ------------------------------------------------- */ $user = new User(); $user->get_by_uuid($uuid); if ($user->exists()) { // Dance doesn't exist, create it $new_dance = new Dance(); $new_dance->guid = uniqid(); $new_dance->move = $encoded_move; $new_dance->date_created = mktime(); $new_dance->date_updated = mktime(); $new_dance->robot_name = $robot_name; $new_dance->robot_still = $robot_still; $new_dance->is_entered_into_comp = $is_entered_into_comp; // Save the dance on the user if ($new_dance->save($user)) { // Save the robot to the dance $robot = new Robot(); $robot->get_by_id($robot_id); $new_dance->save($robot); // Save the soundtrack to the dance $soundtrack = new Soundtrack(); $soundtrack->get_by_id($sound_id); $new_dance->save($soundtrack); $output = $new_dance->guid; } } else { $output = "Error"; // $output = "unable to find user with UUID ". $uuid; } } /* Return the data ------------------------------------------------- */ $this->response($output); }
$this->reverseCoins(); } } public function reverseCoins() { if (count($this->coinContainer) < 0) { return; } foreach ($this->coinContainer as $coin) { if ($coin->isPositive()) { $coin->randomSurface(); } else { $coin->setSurface(true); } $this->statisticsCount(); } } public function statisticsCount() { $count = 0; foreach ($this->coinContainer as $coin) { if ($coin->isPositive()) { $count++; } } var_dump(" 正面占用比例为:" . $count / count($this->coinContainer)); } } $robot = new Robot(); $robot->newCoins(); $robot->reverseCoinsForever();
{ return $this->currentState; } public function powerUp() { $this->currentState->powerUp(); } public function powerDown() { $this->currentState->powerDown(); } public function turnIntoVehicle() { $this->currentState->turnIntoVehicle(); } public function turnIntoRobot() { $this->currentState->turnIntoRobot(); } } $robot = new Robot(); echo "\n"; $robot->powerUp(); echo "\n"; $robot->turnIntoRobot(); echo "\n"; $robot->turnIntoRobot(); /* This one will just give me a message */ echo "\n"; $robot->turnIntoVehicle(); echo "\n";
function _shout(); } class Human implements Man { function move() { echo "Defect user's movement"; } function _shout() { echo "Nice to meet you"; } } class Robot implements Man { function move() { echo "Defect Robot's movement"; } function _shout() { echo "Nice to meet you"; } } $n = new Human(); $n->move(); $n->_shout(); $i = new Robot(); $i->move(); $i->_shout(); //hm님 강좌 연습
<?php include '../Classes/Robot.php'; $action = isset($_POST['action']) ? $_POST['action'] : ''; $duration = isset($_POST['duration']) ? intval($_POST['duration']) : 1; $performed = ''; $error = ''; try { switch ($action) { case 'fwd': case 'rev': case 'left': case 'right': $robot = new Robot(); $robot->setDuration($duration); $robot->{$action}(); $performed = $action; break; } } catch (Exception $exception) { $error = $exception->getMessage(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>RobotCar</title> </head>
/** * Bubble Websocket服务端 */ date_default_timezone_set("asia/shanghai"); require '../util/db.php'; require '../util/robot.php'; define('SUCCESS_CODE', 200); define('INVALID_CODE', -101); define('ERROR_CODE', 404); define('FORBID_CODE', 403); define('USERNAME_MAXLEN', 6); define('CONTENT_MAXLEN', 500); //创建websocket服务器对象,监听127.0.0.1:9009端口 $ws = new swoole_websocket_server("127.0.0.1", 9009); //机器人类 $robot = new Robot(); //在线用户详情记录 $table = new swoole_table(1024 * 10); $table->column('name', swoole_table::TYPE_STRING, 16); $table->column('fd', swoole_table::TYPE_INT); $table->column('dateline', swoole_table::TYPE_INT); $table->column('avatar', swoole_table::TYPE_INT); $table->column('ip', swoole_table::TYPE_STRING, 16); $table->create(); $ws->table_user = $table; $ws->on('open', function ($ws, $request) { $ws->push($request->fd, jsonResult('open', SUCCESS_CODE, "连接成功!\n")); }); $frames_data = array(); $ws->on('message', function ($ws, $frame) { global $robot, $frames_data;
{ return new self($name, 'red'); } public static function createBlueRobot($name) { return new self($name, 'blue'); } private function __construct($name, $color) { $this->setName($name); $this->color = $color; } public function setName($name) { $this->name = (string) filter_var($name); } public function getName() { return $this->name; } public function getColor() { return $this->color; } } $a = Robot::createRedRobot('ロボ太郎'); echo $a->getName(); echo $a->getColor(); $b = Robot::createBlueRobot('ロボ二郎'); echo $b->getName(); echo $b->getColor();
public function testIssue4() { // Has many -> Belongs to // Should be the same for Has many -> Has one $this->assertEquals((new Loader(Robot::findFirstById(1), 'Bugs.Robot'))->execute()->get()->bugs, []); }
/** * createCertList() Create a list of all valid certificates for the given subscriber * * The function will log the number of certificates found as well, but only the * total number and the number of different users. * * @param String $admin eppn of admin-person (owner of the cerfificate * used in the transaction). * @return Array the list of users and the number of (valid) certificates each user has */ static function createCertList($admin) { $ca = CAHandler::getCA($admin); /* Get all certificates for the organization from where admin originates. */ $list = $ca->getCertListForEPPN("%", $admin->getSubscriber()->getOrgName()); $res = array(); $found_certs = 0; $found_users = 0; if (isset($list) && is_array($list) && count($list) > 0) { foreach ($list as $value) { /* cert is for instance not set when using the * Comodo CA, from Comodo we get things * returned slightly different. */ if (isset($value['cert'])) { $cert = openssl_x509_parse(openssl_x509_read($value['cert']), false); $eppn_array = explode(" ", $value['cert_owner']); $eppn = $eppn_array[count($eppn_array) - 1]; } else { $cert = array(); /* Comodo has the full DN as the cert_owner */ $cert['name'] = $value['cert_owner']; $cert_name = $cert['name']; $eppn = Robot::getEPPN($cert_name); } if (isset($res[$eppn])) { if ($res[$eppn]['fullDN'] != $cert['name']) { $msg = "Several certificates with identical names ({$eppn}) but different DN"; $msg .= " " . $res[$eppn]['fullDN'] . "vs. " . $cert['name'] . "."; Logger::log_event(LOG_ALERT, $msg); continue; } $res[$eppn]['count'] = $res[$eppn]['count'] + 1; } else { $res[$eppn] = array('eppn' => $eppn, 'fullDN' => $cert['name'], 'count' => '1'); $found_users = $found_users + 1; } $found_certs = $found_certs + 1; } } Logger::log_event(LOG_NOTICE, "Created a list of {$found_certs} valid certificates for {$found_users} " . "different user(s) in subscriber " . $admin->getSubscriber()->getOrgName()); return $res; }
<?php /** * Created by PhpStorm. * User: elkuku * Date: 30.09.15 * Time: 18:42 */ ob_start(); include '../Classes/Robot.php'; $action = isset($_POST['action']) ? $_POST['action'] : ''; $response = new stdClass(); $response->performed = ''; $response->error = ''; try { $robot = new Robot(); switch ($action) { case 'connect': $response->performed = 'KuKuRobot001'; break; case 'stop': case 'fwd': case 'rev': case 'left': case 'right': $robot->setDuration(isset($_POST['duration']) ? intval($_POST['duration']) : 0); $robot->{$action}(); $response->performed = $action; break; case 'cam': $direction = isset($_POST['direction']) ? $_POST['direction'] : '';
if (!is_null($xml)) { try { $parsedXML = new SimpleXMLElement($xml); } catch (Exception $e) { echo $e->getMessage(); exit(0); } $name = $parsedXML->getName(); if ($name != "ConfusaRobot") { echo "Wrong type of XML. Aborting.\n"; exit(0); } foreach ($parsedXML as $key => $value) { switch ($key) { case 'revocationList': $res = Robot::parseRevList($value, $admin); break; default: if (Config::get_config('debug')) { echo "Unknown type ({$key}). Are you sure you are following the DTD?\n"; /* only exit in debug-mode to minimize * number of log-entries etc. * * In prod. we want to parse the entire file. */ exit(0); } break; } } }
public static function towersp($param1 = '', $param2 = '') { $sql = "CALL testprocedure(" . "'" . $param1 . "','" . $param2 . "'" . ");"; $robot = new Robot(); return new Resultset(null, $robot, $robot->getReadConnection()->query($sql)); }