AlgorithmConfig* FireworksConfig::createAlgorithmConfig(ParseBlock& block)
{
  AlgorithmConfig *c_ = new FireworksConfig;
  FireworksConfig *c = dynamic_cast<FireworksConfig *>(c_);
  
  Checker *check = getChecker();
  init();
  try {
    block.checkUsing(check);
    c->init(block);
    
    c->am = block("am").as<int>();
    c->bm = block("bm").as<int>();
    c->m = block("m").as<int>();
    c->mm = block("mm").as<int>();
    
    if (block.hasProperty("amplitude_mult")) {
      c->amplitude_mult = block("amplitude_mult").as<double>();
    }
    if (block.hasProperty("A_min")) {
      c->A_min = block("A_min").as<double>();
    }
    if (block.hasProperty("new_mapping")) {
      c->new_mapping = block("new_mapping").as<bool>();
    }if (block.hasProperty("efwa_selection")) {
      c->efwa_selection = block("efwa_selection").as<bool>();
    }
  } catch (std::runtime_error &e) {
	  std::cerr << "SwarmConfig::init() --> error while loading data from block. Content: " << e.what() << std::endl;
	  throw(e);
  }
  delete check;
  return c_;
}
bool BaseAI::startTurn()
{
    static bool initialized = false;
    int count = 0;
    count = getPlayerCount(c);
    players.clear();
    players.resize(count);
    for(int i = 0; i < count; i++)
    {
        players[i] = Player(getPlayer(c, i));
    }

    count = getCheckerCount(c);
    checkers.clear();
    checkers.resize(count);
    for(int i = 0; i < count; i++)
    {
        checkers[i] = Checker(getChecker(c, i));
    }

    if(!initialized)
    {
        initialized = true;
        init();
    }
    return run();
}
Example #3
0
bool CheckerBoard::isSimpleKillTurn(BoardCoord oldCoord, BoardCoord newCoord)
{
        if(isChecker(newCoord)) return false;

        boost::shared_ptr<Checker> current = getChecker(oldCoord);

        int dY = newCoord.y-oldCoord.y;
        int dX = newCoord.x-oldCoord.x;
        int possible_dY;
        if(!(((dX == -2)||(dX == 2))&&(((dY == -2)||(dY == 2))))) return false;


        int enemyPos_X = (newCoord.x+oldCoord.x)/2;
        int enemyPos_Y = (newCoord.y+oldCoord.y)/2;
        if(!isChecker(BoardCoord(enemyPos_X,enemyPos_Y))) return false;

        boost::shared_ptr<Checker> enemy = getChecker(BoardCoord(enemyPos_X, enemyPos_Y));
        if(enemy->getColor() != getOppositeColor(current->getColor())) return false;

        return true;
}
Example #4
0
bool CheckerBoard::isQueenKillTurn(BoardCoord oldCoord, BoardCoord newCoord)
{
        if(isChecker(newCoord)) return false;
        if(!oldCoord.isValid()||!newCoord.isValid()) return false;

        int dY = m_abs(newCoord.y-oldCoord.y);
        int dX = m_abs(newCoord.x-oldCoord.x);
        int sign_dX = m_sign(newCoord.x-oldCoord.x);
        int sign_dY = m_sign(newCoord.y-oldCoord.y);

        if(dX != dY) return false;

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

        boost::shared_ptr<Checker> active = getChecker(oldCoord);
        boost::shared_ptr<Checker> current;

        int countEnemy = 0;
        for(int i=1; i < dX; ++i)
        {
            if(isChecker(BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY)))
            {
                std::cout<<"isChecker"<<x+i<<";"<<y+i<<std::endl;
                current = getChecker(BoardCoord::convertToBoardCoord(x+i*sign_dX, y+i*sign_dY));
                if(current->getColor() != active->getColor())
                    countEnemy++;
                else
                    return false;
            }
        }

        if(countEnemy != 1)
            return false;

        return true;
}
void GeneticConfig::init(ParseBlock& block)
{
	Checker *check = getChecker();
	init();
	try {
		block.checkUsing(check);
    resolution::CostConfig::init(block);
		
		

		if (block.hasProperty("initializer_type")) {
			initializer_type = block("initializer_type").value;
		}
		if (block.hasProperty("crossover_type")) {
			crossover_type = block("crossover_type").as<string>();
		}
		if (block.hasProperty("custom_evolution")) {
			custom_evolution = block("custom_evolution").as<bool>();
		}
		
		if (block.hasProperty("mutator_type")) {
			mutator_type = block("mutator_type").as<string>();
		}
		if (block.hasProperty("search_ratio")) {
			search_ratio = block("search_ratio").as<double>();
		}
		
		if (block.hasProperty("max_checks")) {
			max_checks = block("max_checks").as<int>();
		}
		
		if (block.hasProperty("mutation_probability")) {
		  pMutation = block("mutation_probability").as<double>();
		}
		
		if (block.hasProperty("mutation_deviation")) {
		  mutation_dev = block("mutation_deviation").as<double>();
		}
		
		if (block.hasProperty("crossover_probability")) {
		  pCrossover = block("crossover_probability").as<double>();
		}
		
	} catch (std::exception &e) {
		std::cerr << "GeneticConfig::init() --> error while loading data from block\n";
		throw(e);
	}
	delete check;
}
Example #6
0
bool CheckerBoard::moveChecker(const BoardCoord oldPos, const BoardCoord newPos)
{
    boost::shared_ptr<Checker> activeChecker = getChecker(oldPos);

    if( (newPos.y == 0)&&(activeChecker->getColor() == Checker::WHITE) )
        activeChecker->makeQueen();


    if( (newPos.y == 7)&&(activeChecker->getColor() == Checker::BLACK) )
        activeChecker->makeQueen();

    activeChecker->setSpritePosition(newPos);

    m_board[newPos.x][newPos.y].ptrChecker.swap(activeChecker);
    m_board[oldPos.x][oldPos.y].status = BoardPiece::FREE;
    m_board[newPos.x][newPos.y].status = BoardPiece::OCCUPIED;
}
Example #7
0
bool CheckerBoard::isThereRequiredTurns(Checker::Color playerColor)
{
    for(int i = 0; i < m_board.size(); ++i)
        for(int j = 0; j < m_board.size(); ++j)
        {
            if(isChecker(BoardCoord(i,j)))
            {
                if(getChecker(BoardCoord(i,j))->getColor() == playerColor)
                {
                    if(isThereRequerdTurnForChecker(BoardCoord(i,j)))
                        return true;
                }
            }

        }

    return false;
}
Example #8
0
CheckerBoard::TurnType CheckerBoard::getTurnType(BoardCoord oldCoord, BoardCoord newCoord)
{
    if(!(oldCoord.isValid()&&(newCoord.isValid()))) return INVALID_TURN;
    if( (newCoord.x + newCoord.y) % 2 != 1) return INVALID_TURN;
    if(m_board[newCoord.x][newCoord.y].status == BoardPiece::OCCUPIED ) return INVALID_TURN;


    boost::shared_ptr<Checker> active = getChecker(oldCoord);

    if(isThereRequiredTurns(active->getColor()))
    {
        if(active->getType() == Checker::SIMPLE)
        {
            if(isSimpleKillTurn(oldCoord, newCoord))
                return SIMPLE_KILL_TURN;
        }

        if(active->getType() == Checker::QUEEN)
        {
            if(isQueenKillTurn(oldCoord, newCoord))
                return QUEEN_KILL_TURN;
        }

        return INVALID_TURN;
    }
    else
    {
        if(active->getType() == Checker::SIMPLE)
        {
            if(isSimpleTurn(oldCoord, newCoord))
                return SIMPLE_TURN;
        }


        if(active->getType() == Checker::QUEEN)
        {
            if(isQueenTurn(oldCoord, newCoord))
                return QUEEN_TURN;
        }
    }

    return INVALID_TURN;
}
int main (int argc, char **argv)
{
	int result = 0;

	checkersCache.push_back (new ServiceChecker);
	checkersCache.push_back (new ProcessChecker);

	AbstractChecker *checker = getChecker (argc, argv);

	if (checker) {
		result = checker->check (argc, argv);

		std::cout << checker->lastError() << std::endl;
	}

	deleteAll (checkersCache);

	return result;
}
void ThermalModelSimple::init(ParseBlock &b) {
  Checker *check = getChecker();
  try {
    b.checkUsing(check);
    
    // Get updraft info
    ParseBlock::Blocks *updrafts = b.getBlocks("updraft");
	
    updraft_vector.clear();
    ParseBlock::Blocks::iterator it = updrafts->begin();
    for ( ; it != updrafts->end(); it++) {
      Updraft aux(**it);
      updraft_vector.push_back(aux);
    }
  } catch (exception &e) {
    cerr << "ThermalModelSimple::ThermalModelSimple --> Error: could not load the data.\n";
    throw(e);
  }
  
  delete check;
}
Example #11
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;
}