⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client2dview.c

📁 robocup rcssmonitor-11.1.1.zip
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <cstdio>#include <cstdlib>#include <cstring>#include <fstream>#include "udpsocket.h"#include "tcpsocket.h"#include "valueparser.h"//#include "randomize.h"#include "global_defs.h"#include "angle.h"#ifdef HAVE_CONFIG_H#include "config.h"#endif#ifdef HAVE_SSTREAM#include <sstream>#else#include <strstream>#endif#include <unistd.h> // wegen {u}sleep()void move_frame_5(UDPsocket & sock) {#ifdef HAVE_SSTREAM  std::ostringstream o;#else  std::ostrstream o;#endif  while (true)    for (int t=1; t<= 50; t++) {      usleep(100000);      o << "MOV 5 (" <<  20 << "," << t << ");";#ifdef HAVE_SSTREAM      sock.send_msg( o.str().c_str(), o.str().length() );#else      o << std::ends;      sock.send_msg( o.str(), strlen( o.str() ) );      o.freeze( false );#endif    }}void move_ascii_tree_input(UDPsocket & sock) {  //init_drand();  float angle[10];  const float a= 0.22;  const float b= 0.36;  const float c= 0.46;  float range[10][2]= { { a,-a},		       {0.78+b,0.78-b},{b,-b},{-0.78+b,-0.78-b},		       {0.52+c,0.52-c},{-0.52+c,-0.52-c},		       {0.52+c,0.52-c},{-0.52+c,-0.52-c},		       {0.52+c,0.52-c},{-0.52+c,-0.52-c} };  for (int i=0; i<10; i++)    angle[i]= 0.5*( range[i][0]+range[i][1] );#ifdef HAVE_SSTREAM  std::ostringstream o;#else  std::ostrstream o;#endif  for (;;)    for (int t=1; t<= 50; t++) {      usleep(100000);      for (int i=0; i< 10; i++) {        float max= range[i][0];        float min= range[i][1];        float ang;        //ang= min + (max-min)*float(t)/50.0;        ang= angle[i];        float s= drand48();        if (s < 0.5)          s= (max-min)/50.0;        else          s= -(max-min)/50.0;        ang+= s;        if (ang > max)          ang= max;        else if (ang < min)          ang= min;        o << "MOV " << i+1 << "(" <<  ang  << ");";        angle[i]= ang;      }#ifdef HAVE_SSTREAM      sock.send_msg( o.str().c_str(), o.str().length() );#else      o << std::ends;      sock.send_msg( o.str(), strlen( o.str() ) );      o.freeze( false );#endif    }}void loop_input(UDPsocket & sock) {  for (;;)    for (int t=1; t<= 50; t++) {      usleep(50000);#ifdef HAVE_SSTREAM  std::ostringstream o;#else  std::ostrstream o;#endif      o << "MOV 1 (" << 6.28 * float(t)/50 << ")" ;#ifdef HAVE_SSTREAM      sock.send_msg( o.str().c_str(), o.str().length() );#else      o << std::ends;      sock.send_msg( o.str(), strlen( o.str() ) );      o.freeze( false );#endif    }}void file_input(UDPsocket & sock, const char * fname) {  std::ifstream  in(fname);  if (!in) {    std::cerr << "\nproblems with reading file " << fname;    exit(1);  }  char send_buffer[1026];  send_buffer[0]= '[';  send_buffer[1]= ']';  char *buffer= send_buffer+2;  while ( in ) {    in.getline(buffer,1023);    char *dum= buffer;    while (*dum == ' ')      dum++;    if (*dum == '#' || *dum == '\0')      continue;    std::cout << "\nsending \"" << send_buffer << "\"";    sock.send_msg(send_buffer,strlen(send_buffer));  }}void file_input_over_tcp(const char * fname) {  TCPsocket tcp_sock;  if ( !TCPutils::init_client("localhost",20000,tcp_sock) )  //if ( !TCPutils::init_client("robocup7",20000,tcp_sock) )    return;  std::ifstream  in(fname);  if (!in) {    std::cerr << "\nproblems with reading file " << fname;    tcp_sock.close();    exit(1);  }  char send_buffer[1026];#if 0  send_buffer[0]= '[';  send_buffer[1]= ']';  char *buffer= send_buffer+2;#else  char *buffer= send_buffer;#endif  while ( in ) {    in.getline(buffer,1023);    char *dum= buffer;    while (*dum == ' ')      dum++;    if (*dum == '#' || *dum == '\0')      continue;    std::cout << "\nsending \"" << send_buffer << "\"";    tcp_sock.send_msg(send_buffer,strlen(send_buffer));  }  std::cout << "\nTCP SEND END" << std::flush;  tcp_sock.close();}void command_line_input(UDPsocket & sock) {  char buffer[1024];  while (1) {    std::cout << "\n>";    std::cin.getline(buffer,1023);    if (*buffer== 'q')      return;    else {      std::cout << "\nsending \"" << buffer << "\"";      sock.send_msg(buffer,strlen(buffer));    }  }}void middle_size_input(UDPsocket & sock) {}#define HALMA#ifdef HALMAconst int initialGrid[19][19]=  {        /* ------                    columns                ---------- */             /* 0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8 */    /*   0 */  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},    /*   1 */  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1},    /*   2 */  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2, 2,-1,-1,-1,-1,-1},    /* r 3 */  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2, 2, 2,-1,-1,-1,-1,-1},    /* o 4 */  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2, 2, 2, 2,-1,-1,-1,-1,-1},    /* w 5 */  {-1,-1,-1,-1,-1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0,-1},    /* s 6 */  {-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1},    /*   7 */  {-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1},    /*   8 */  {-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1},    /*   9 */  {-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1},    /*   0 */  {-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1},    /*   1 */  {-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1},    /*   0 */  {-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1},    /*   3 */  {-1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,-1,-1,-1,-1,-1},    /*   4 */  {-1,-1,-1,-1,-1, 1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},    /*   5 */  {-1,-1,-1,-1,-1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},    /*   6 */  {-1,-1,-1,-1,-1, 1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},    /*   7 */  {-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},    /*   8 */  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}  };class HalmaBoard  {  int XCENTER;  // Zentrum des Spielbrettes  int YCENTER;  //  int chRadius; //radius of a checker  static const int BSIZE   = 19; public:  HalmaBoard(int size);  void MatrixRC_2_ScreenXY(int row, int col, double & x, double & y);};HalmaBoard::HalmaBoard(int size) {  XCENTER = 0;  //300  YCENTER = 0;  //350  chRadius = size/35;}void HalmaBoard::MatrixRC_2_ScreenXY(int row, int col, double & x, double & y) {  int LY_offset, LX_offset;  int bx= col;  int by= row;  LX_offset = ( bx - 9 );  LY_offset = ( by - 9 );  x = XCENTER + LX_offset * 2*chRadius + LY_offset * chRadius;  y = YCENTER - LY_offset * 2*chRadius;}void halma_input(UDPsocket & sock) {  HalmaBoard hb(100);#define c_black "000000"#define c_red   "ff0000"#define c_blue  "0000ff"#define c_green "00ff00"  char color[7][8] = { c_black, c_red, c_blue , c_green, c_red, c_blue,  c_black};#ifdef HAVE_SSTREAM  std::ostringstream o;#else  std::ostrstream o;#endif  int num_circles= 0;  //field  o << "VA (0,0,80,80); EMP 0;";  o << "\nINS CIRCLE col=" << c_black << " ";  for (int row=0; row < 19; row++)    for (int col=0; col < 19; col++) {      double cx,cy;      hb.MatrixRC_2_ScreenXY(row,col,cx,cy);      const int idx= initialGrid[row][col];      if ( idx >= 0) {        o << "\n  (" << cx << "," << cy << "," << 100.0/55.0 << ")";        num_circles++;      }    }  o << ";";#if 1  for (int row=0; row < 19; row++)    for (int col=0; col < 19; col++) {      double cx,cy;      hb.MatrixRC_2_ScreenXY(row,col,cx,cy);      const int idx= initialGrid[row][col];      if ( idx > 0) {        int frame= row*19+col+1;        o << "\nINS FRAME id=" << frame << " (" << cx << "," << cy << ");"          << "\n  INS " << frame << " CIRCLE fil=1 col=" << color[idx] << " (0,0," << 100.0/60.0 <<");";      }    }#endif#ifdef HAVE_SSTREAM      sock.send_msg( o.str().c_str(), o.str().length() );      std::cout << o.str();      std::cout << "\nsize= " << o.str().length() << ", num_circles= " << num_circles << std::endl;#else      o << std::ends;      sock.send_msg( o.str(), strlen( o.str() ) );      std::cout << o.str();      std::cout << "\nsize= " << strlen( o.str() ) << ", num_circles= " << num_circles << std::endl;      o.freeze( false );#endif  o.seekp(0);  o << "\nINS CIRCLE col=  cccccc";  for (int row=0; row < 19; row++)    for (int col=0; col < 19; col++) {      double cx,cy;      hb.MatrixRC_2_ScreenXY(row,col,cx,cy);      const int idx= initialGrid[row][col];      if ( idx < 0) {        o << "\n  (" << cx << "," << cy << "," << 100.0/55.0 << ")";        num_circles++;      }    }  o << ";" << std::ends;#ifdef HAVE_SSTREAM      sock.send_msg( o.str().c_str(), o.str().length() );#else      o << std::ends;      sock.send_msg( o.str(), strlen( o.str() ) );      o.freeze( false );#endif}#endif#ifdef HAVE_LINUX_JOYSTICK_H#include <linux/joystick.h>#include <sys/ioctl.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include "vector2d.h"class Robot {public:    virtual ~Robot() { }  int frame;  virtual void read_joystick(int num_axes, int * axis) { }  virtual void print_pos(std::ostream &) { }  virtual void print_skin(std::ostream &)= 0;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -