示例#1
0
void Encoder::new_point(Point2f _new_position, unsigned int _print_select)
  {
	  position = _new_position;
	  backlog[index % samples_size] = position;
	  index = (index+1) % samples_size;

	  switch(_print_select)
	  {
		  case PRINT_POLAR:
			  polar_coordinate();
			  break;

		  case PRINT_XY:
			  xy_coordinate();
			  break;

		  case NO_PRINT: default:
			  break;
      }

  }
示例#2
0
文件: xq.cpp 项目: DoBuiThao/hoxchess
 string XQ::get_fen()const
 {
     if (m_player == Empty)
         return string();
     vector<char> chars;
     for (sint y = 9; y >= 0; --y)
     {
         if (y != 9)
             chars.push_back('/');
         sint32 empty_count = 0;
         for (uint x = 0; x < 9; ++x)
         {
             uint sq = xy_coordinate(x,y);
             sint c = piece_char(coordinate(sq));
             if (c)
             {
                 if (empty_count)
                 {
                     chars.push_back(static_cast<char>('0' + empty_count));
                     empty_count = 0;
                 }
                 chars.push_back(static_cast<char>(c));
             }
             else
             {
                 ++empty_count;
             }
         }
         if (empty_count)
         {
             chars.push_back(static_cast<char>('0' + empty_count));
         }
     }
     chars.push_back(' ');
     chars.push_back(m_player == Red ? 'r' : 'b');
     return string(chars.begin(), chars.end());
 }
示例#3
0
文件: xq.cpp 项目: DoBuiThao/hoxchess
 bool XQ::set_fen(string const &fen)
 {
     clear();
     uint idx = 0UL, len = (uint)fen.size();
     uint y = 9UL, x = 0UL;
     while (idx < len)
     {
         sint32 c = fen[idx++];
         uint32 type = char_type(c);
         if (type != InvaildPiece)
         {
             if (y >= 10UL || x >= 9UL)
             {
                 //error
                 clear();
                 return false;
             }
             uint32 begin = type_begin(type);
             uint32 end = type_end(type);
             while (end >= begin)
             {
                 if (piece(begin) == InvaildCoordinate)
                 {
                     break;
                 }
                 ++begin;
             }
             if (begin > end)
             {
                 //error
                 clear();
                 return false;
             }
             uint32 sq = xy_coordinate(x++, y);
             m_coordinates[sq] = static_cast<uint8>(begin);
             m_pieces[begin] = static_cast<uint8>(sq);
         }
         else if (c == ' ')
         {
             if (y || x != 9UL || (idx == len))
             {
                 //error
                 clear();
                 return false;
             }
             c = fen[idx];
             m_player = ((c == 'b') ? Black : Red);
             for (int i = 0; i < 32; i++)
             {
                 uint32 sq = piece(i);
                 if (sq != InvaildCoordinate)
                 {
                     if (!(coordinate_flag(sq) & piece_flag(i)))
                     {
                         //error
                         clear();
                         return false;
                     }
                     m_bitmap.setbit(sq);
                 }
             }
             //ok
             return true;
         }
         else if (c == '/')
         {
             if (!y || x != 9UL)
             {
                 //error
                 clear();
                 return false;
             }
             --y;
             x = 0UL;
         }
         else if (c >= '1' && c <= '9')
         {
             x += c - '0';
         }
         else
         {
             //error
             clear();
             return false;
         }
     }
     //error
     clear();
     return false;
 }