Esempio n. 1
0
Coord * parseReference(Collector * c, Tokenizer * tt) {
	if (tt->c.len < 2) {
		printf("invalid cell specification\n");
		return NULL;
	}

	int col = tt->c.value[0] - 'A';
	int row = tt->c.number - 1;

	if (col >= 0 && col < 26 && row >= 0) return newCoord(c, col, row);
	return NULL;
}
bool CoordsController::EditCoord(QWidget *parent, const Coord &coord)
{
	Coord newCoord(coord);
	EditCoordDlg dlg(parent, newCoord);
	if (QDialog::Accepted == dlg.exec())
	{
		QString update = newCoord.GetUpdateQueryString(coord.m_name);
		return Utils::ExecQuery(update);
	}

	return false;
}
Esempio n. 3
0
std::vector<sf::Vector2f> PhysicsBehavior::GetCoordsVectorFromString(const gd::String &str, char32_t coordsSep, char32_t composantSep)
{
    std::vector<sf::Vector2f> coordsVec;

    std::vector<gd::String> coordsDecomposed = str.Split(coordsSep);

    for(std::size_t a = 0; a < coordsDecomposed.size(); a++)
    {
        std::vector<gd::String> coordXY = coordsDecomposed.at(a).Split(composantSep);

        if(coordXY.size() != 2)
            continue;

        sf::Vector2f newCoord(coordXY.at(0).To<float>(), coordXY.at(1).To<float>());
        coordsVec.push_back(newCoord);
    }

    return coordsVec;
}
Esempio n. 4
0
 vector< vector< float > > K_MeansPredict::Test( const int PItype, const vector< vector< float > >& Examples ) const
 {
  cout << "# Testing:\n";
  vector< vector< float > > returnVal( Examples.size() );
  for( int i=0; i<returnVal.size(); i++ )
  {
    returnVal[i] = vector< float >( 5 );
  }
  float sum_x=0.;
  float sum_xx=0.;
  for( int i=0; i<Examples.size(); i++ )
  {
    vector< float > temp( Examples[i].size()-1 );
    for( int j=0; j< temp.size(); j++ )
    {
      temp[j] = Examples[i][j+1];
    }
    Coord< float > newCoord( temp );
    vector< float > predVal = PredictKey( PItype, newCoord );
    returnVal[i][0] = Examples[i][0];
    returnVal[i][1] = predVal[1];
    returnVal[i][2] = predVal[2];
    returnVal[i][3] = predVal[3];
    //  Here is where I could add a support requirement (e.g. if( predVal[0] > threshold)
    // Calcu
    float err = returnVal[i][2]-returnVal[i][0];
    sum_x += err;
    sum_xx += pow( err, 2 );
    if( returnVal[i][1] <= returnVal[i][0] && returnVal[i][0] <= returnVal[i][3] )
    {
      returnVal[i][4] = 1.0;
    }
    else
    {
      returnVal[i][4] = 0.0;
    }
  }
  cout << "#   Error:\n";
  cout << "#     Mean of Squared Errors (MSE) is: " <<  sum_xx/float( returnVal.size() ) << endl;
  cout << "#     Error Mean is : " << sum_x/float( returnVal.size() ) << endl;
  cout << "#     Error Variance is: " << (sum_xx-pow(sum_x/float(returnVal.size()),2))/float( returnVal.size()-1 ) << endl;
  return( returnVal );
 }
Esempio n. 5
0
/****************************************************************************************
 * vector< float > TestHelper( const vector< float >& Ex, const float& t_val ) const
 * purpose:
 *   evaluates target value of pattern
 *   Inherently uses global error variance -- to work with k fold cross validation
 * Input:
 *	Ex: vector of examples
 *	t_val: T-test value
 * Output:
 *	Lower PI bound
 *	Prediction
 *	Upper Prediction bound
 *	(yes/no) is in prediction band	
 * 
 * 02.17.2006	djh	created
 * 03.08.2006	djh	added t_val to parameter list
 *****************************************************************************************/
 vector< float > K_MeansPredict::TestHelper( const vector< float >& Ex, const float& t_val ) const{
   vector< float > returnVal( 5 );
   vector< float > temp( Ex.size()-1 );
   for( int j=0; j< temp.size(); j++ ){
      temp[j] = Ex[j+1];
   }
   Coord< float > newCoord( temp );
   // Inherent use of global error variance
   vector< float > predVal = PredictKey( 1, newCoord, t_val );
   returnVal[0] = Ex[0];
   returnVal[1] = predVal[1];
   returnVal[2] = predVal[2];
   returnVal[3] = predVal[3];
   if( returnVal[1] <= returnVal[0] && returnVal[0] <= returnVal[3] ){
      returnVal[4] = 1.0;
   }
   else {
      returnVal[4] = 0.0;
   }
   return( returnVal );
 }
Esempio n. 6
0
bool CheckerBoard::isThereRequerdTurnForChecker(BoardCoord oldCoord)
{
    if(!isChecker(oldCoord)) return false;

    if(getChecker(oldCoord)->getType() == Checker::SIMPLE)
    {
        boost::array<boost::array<int, 2>, 4> dXdY;

        dXdY[0][0] =  2; dXdY[0][1] =  2;
        dXdY[1][0] = -2; dXdY[1][1] = -2;
        dXdY[2][0] = -2; dXdY[2][1] =  2;
        dXdY[3][0] =  2; dXdY[3][1] = -2;

        int x = oldCoord.x;
        int y = oldCoord.y;

        BoardCoord newCoord;
        for(int i=0; i<dXdY.size(); ++i)
        {
            newCoord = BoardCoord(x + dXdY[i][0], y + dXdY[i][1]);
            if(newCoord.isValid())
            {
                if(isSimpleKillTurn(oldCoord, newCoord))
                {
                    return true;
                }
            }
        }
    }


    if(getChecker(oldCoord)->getType() == Checker::QUEEN)
    {
        std::cout<<"QUEEN"<<std::endl;

        boost::array<boost::array<int, 2>, 4> dXdY;

        dXdY[0][0] =  1; dXdY[0][1] =  1;
        dXdY[1][0] = -1; dXdY[1][1] = -1;
        dXdY[2][0] = -1; dXdY[2][1] =  1;
        dXdY[3][0] =  1; dXdY[3][1] = -1;

        Checker::Color playerColor = getChecker(oldCoord)->getColor();

        for(int i=0; i<dXdY.size(); ++i)
        {
            bool enemy = false;
            int x = oldCoord.x;
            int y = oldCoord.y;

            x += dXdY[i][0];
            y += dXdY[i][1];

            BoardCoord newCoord(x,y);
            while(newCoord.isValid())
            {
                if(isChecker(newCoord))
                {
                    if((getChecker(newCoord)->getColor() == playerColor)||enemy)
                    {
                        enemy = false;
                        break;
                    }
                    else
                        enemy = true;

                }
                else
                {
                    if(enemy)
                    {
                        return true;
                    }
                }

                newCoord.x += dXdY[i][0];
                newCoord.y += dXdY[i][1];
            }
        }
    }

    return false;
}
Esempio n. 7
0
void WHtreeProcesser::coarseTree( const unsigned int coarseRatio )
{
    if( coarseRatio < 2 )
    {
        return;
    }

    std::map< WHcoord, size_t > roimap;
    size_t count( 0 );
    //create a matrix with seed voxels positions
    std::vector< std::vector< std::vector< bool > > > roimatrix;
    roimatrix.resize( m_tree.m_datasetSize.m_x );
    for( size_t i = 0; i < roimatrix.size(); ++i )
    {
        roimatrix[i].resize( m_tree.m_datasetSize.m_y );
        for( size_t j = 0; j < roimatrix[i].size(); ++j )
        {
            roimatrix[i][j].resize( m_tree.m_datasetSize.m_z, false );
        }
    }

    for( std::vector< WHcoord >::const_iterator coordIter = m_tree.m_coordinates.begin(); coordIter != m_tree.m_coordinates.end(); ++coordIter )
    {
        //std::cout <<*coord_iter<< std::endl;
        roimatrix[coordIter->m_x][coordIter->m_y][coordIter->m_z] = true;
        roimap.insert( std::make_pair( *coordIter, count++ ) );
    }

    // convert previously discarded elements to new grid
    std::list< WHcoord > newDiscarded( m_tree.m_discarded );
    for( std::list< WHcoord >::iterator iter( newDiscarded.begin() ); iter != newDiscarded.end(); ++iter )
    {
        iter->m_x = iter->m_x / coarseRatio;
        iter->m_y = iter->m_y / coarseRatio;
        iter->m_z = iter->m_z / coarseRatio;
    }
    newDiscarded.sort();
    newDiscarded.unique();
    WHcoord newDataSetSize( m_tree.m_datasetSize.m_x / coarseRatio, m_tree.m_datasetSize.m_y / coarseRatio,
                    m_tree.m_datasetSize.m_z / coarseRatio );

    //loop through coarser grid
    for( coord_t k = 0; k < m_tree.m_datasetSize.m_z; k += coarseRatio )
    {
        for( coord_t j = 0; j < m_tree.m_datasetSize.m_y; j += coarseRatio )
        {
            for( coord_t i = 0; i < m_tree.m_datasetSize.m_x; i += coarseRatio )
            {
                //loop through finer grid
                std::list< WHcoord > bigGridVoxel;

                for( unsigned int n = 0; n < coarseRatio; ++n )
                {
                    for( unsigned int m = 0; m < coarseRatio; ++m )
                    {
                        for( unsigned int l = 0; l < coarseRatio; ++l )
                        {
                            if( roimatrix[i + l][j + m][k + n] )
                            {
                                WHcoord tempCoord( i + l, j + m, k + n );
                                bigGridVoxel.push_back( tempCoord );
                            }
                        }
                    }
                }
                if( !bigGridVoxel.empty() )
                {
                    WHcoord keptCoord( bigGridVoxel.front() );
                    bigGridVoxel.pop_front();
                    size_t keptID( roimap[keptCoord] );
                    WHcoord newCoord( keptCoord.m_x / coarseRatio, keptCoord.m_y / coarseRatio, keptCoord.m_z / coarseRatio );
                    m_tree.m_coordinates[keptID] = newCoord;

                    for( std::list< WHcoord >::iterator iter( bigGridVoxel.begin() ); iter != bigGridVoxel.end(); ++iter )
                    {
                        size_t decimatedID( roimap[*iter] );
                        m_tree.fetchLeaf( decimatedID )->setFlag( true );
                        WHcoord emptyCoord;
                        m_tree.m_coordinates[decimatedID] = emptyCoord;
                    }
                }
            }
        }
    }

    m_tree.cleanup();
    m_tree.debinarize();
    m_tree.m_discarded = newDiscarded;
    m_tree.m_datasetSize = newDataSetSize;
    m_tree.m_treeName += ( "_coarse" + string_utils::toString( coarseRatio ) );

    return;
} // end "coarseTree()" -----------------------------------------------------------------
bool PlayerCharacterEntity::goNumTilesAway(int numToMove)
{
  // set an immediate GO_TO instruction if a suitable tile is found
  set<coord> searched;
  list<pair<int,coord> > toSearch;

  toSearch.push_front(pair<int, coord>(0, coord(getTileX(), getTileY())));

  while (!toSearch.empty())
  {
    // get head of toSearch
    pair<int, coord> currentLocation = toSearch.front();
    toSearch.pop_front();

    // is this the tile we want?
    if (currentLocation.first >= numToMove)
    {
      // it is, set GO_TO instruction and be happy
      AIInstruction * ins = new AIInstruction(AIInstruction::GO_TO,
                                              0, getType(), currentLocation.second.first, currentLocation.second.second);
      m_insList.push_front(ins);

      return true;
    }
    else
    {
      // add valid adjoining tiles to toSearch list

      searched.insert(currentLocation.second);

      Map * staticMap = Map::getInstance();
      AIGameView * view = AIGameView::getInstance();

      for (int i = 0; i < 4; ++i)
      {
        int x, y;
        x = currentLocation.second.first;
        y = currentLocation.second.second;

        switch (i)
        {
          case 0:
            x++;
            break;
          case 1:
            x--;
            break;
          case 2:
            y++;
            break;
          case 3:
            y--;
            break;
        }

        if (staticMap->staticTileAt(x, y) == Map::EMPTY)
        {
          // check for hostile mines
          bool badMineFound = false;

          vector<EntityInfo> info = view->getEntityInfoAtLocation(x, y);
          vector<EntityInfo>::iterator it;
          for (it = info.begin(); it != info.end(); ++it)
          {
            if (it->type == MINE && it->team != getTeam())
            {
              badMineFound = true;
              break;
            }
          }

          if (badMineFound)
          {
            continue;
          }

          coord newCoord(x, y);
          pair<int, coord> newLocation(currentLocation.first + 1, newCoord);
          // check searched set
          if (searched.find(newCoord) == searched.end())
          {
            toSearch.push_back(newLocation);
          }
        }

      } // end for 0..3

    } // end else static entry found

  } // end while toSearch not-empty

  return false;
}