Ejemplo n.º 1
0
/**
 * @brief Resolve the reaction fire for an entity, this checks that the entity can fire and then takes the shot
 * @param[in] shooter The entity using reaction fire
 * @param[in] target The victim of the reaction fire
 * @return true if the entity fired, false otherwise
 */
bool ReactionFire::tryToShoot (Actor* shooter, const Edict* target)
{
	/* check for valid target */
	assert(target);

	/* shooter can't take a reaction shot if it's not possible - and check that
	 * the target is still alive */
	if (!isPossible(shooter, target)) {
		rft.remove(shooter, target);
		return false;
	}

	/* take the shot */
	const actorHands_t hand = shooter->chr.RFmode.getHand();
	const shoot_types_t type = (hand == ACTOR_HAND_RIGHT ? ST_RIGHT_REACTION
			: (hand == ACTOR_HAND_LEFT ? ST_LEFT_REACTION : ST_NUM_SHOOT_TYPES));
	const bool tookShot = rf.shoot(shooter, target->pos, type, shooter->chr.RFmode.getFmIdx());

	if (tookShot) {
		/* clear any shakenness */
		shooter->removeShaken();
	}

	return tookShot;
}
Ejemplo n.º 2
0
int solve(int puzzle[][9], int i, int j)
{
    int x, lin, col;
    col = j; lin = i;

    if(i == 9) // Econtramos uma solução
        return 1;

    // 1
    if(col < 8) col++;
    else
    {
        lin++;
        col = 0;
    }

    // 2
    if(puzzle[i][j]) return solve(puzzle, lin, col);
    else
    {
        for(x = 1; x <= 9; x++) // 2.1
        {
            if(isPossible(i, j, puzzle, x))
            {
                puzzle[i][j] = x;
                // 3
                if(solve(puzzle, lin, col)) return 1;
                puzzle[i][j] = 0;
            }
        }
    }
    return 0; // não encotramos solução
}
Ejemplo n.º 3
0
void CMapGenerator::createObstaclesCommon2()
{
	if (map->twoLevel)
	{
		//finally mark rock tiles as occupied, spawn no obstacles there
		for (int x = 0; x < map->width; x++)
		{
			for (int y = 0; y < map->height; y++)
			{
				int3 tile(x, y, 1);
				if (map->getTile(tile).terType == ETerrainType::ROCK)
				{
					setOccupied(tile, ETileType::USED);
				}
			}
		}
	}

	//tighten obstacles to improve visuals

	for (int i = 0; i < 3; ++i)
	{
		int blockedTiles = 0;
		int freeTiles = 0;

		for (int z = 0; z < (map->twoLevel ? 2 : 1); z++)
		{
			for (int x = 0; x < map->width; x++)
			{
				for (int y = 0; y < map->height; y++)
				{
					int3 tile(x, y, z);
					if (!isPossible(tile)) //only possible tiles can change
						continue;

					int blockedNeighbours = 0;
					int freeNeighbours = 0;
					foreach_neighbour(tile, [this, &blockedNeighbours, &freeNeighbours](int3 &pos)
					{
						if (this->isBlocked(pos))
							blockedNeighbours++;
						if (this->isFree(pos))
							freeNeighbours++;
					});
					if (blockedNeighbours > 4)
					{
						setOccupied(tile, ETileType::BLOCKED);
						blockedTiles++;
					}
					else if (freeNeighbours > 4)
					{
						setOccupied(tile, ETileType::FREE);
						freeTiles++;
					}
				}
			}
		}
		logGlobal->traceStream() << boost::format("Set %d tiles to BLOCKED and %d tiles to FREE") % blockedTiles % freeTiles;
	}
}
Ejemplo n.º 4
0
int calRoute( int (*sMap)[MAX_M], int N, int M )
{
	int i = 0;
	int j = 0;
	int sSum = 0;

	int sIsPossible = 0;
	int sCheck[MAX_N][MAX_M] = { {0}, };
	int destX = M - 1;
	int destY = N - 1;
	int startMin = 0; // start minute
	int destMin = sMap[destY][destX]; // dest minute
	int sMinDiff = 0;

	destMin = sMap[destY][destX];

	sIsPossible = isPossible( destX, destY, destMin );
	if ( sIsPossible == 1 )
	{
		sSum += nextRoute( sMap, sCheck, destX, destY - 1, destMin - 1, N, M ); //UP
		sSum += nextRoute( sMap, sCheck, destX - 1, destY, destMin - 1, N, M ); //LEFT

		printf( "%d\n", sSum % MAX_ROUTE );
	}
	else
	{
		printf( "0\n" );
	}
}
Ejemplo n.º 5
0
bool Actuator::setTarget(float L, bool force) {
  if(force || isPossible(L)) {
    targetLength = L;
    return true;
  }
  return false;
}
Ejemplo n.º 6
0
bool Possibilities::isValid(SolvedPuzzle &puzzle)
{
    for (int row = 0; row < PUZZLE_SIZE; row++)
        for (int col = 0; col < PUZZLE_SIZE; col++)
            if (! isPossible(col, row, puzzle[row][col]))
                return false;
    return true;
}
Ejemplo n.º 7
0
int isPossible(char str[],int i,int len,int left,int right)
{
	if(i==len)
		return left==right;
	if(str[i]=='(')
	{
		if(left>=right)
			return isPossible(str,i+1,len,left+1,right);
		else
			return 0;
	}
	if(str[i]==')')
		return isPossible(str,i+1,len,left,right+1);
	if(str[i]==':')
	{
		if(i+1<len)
		{
			if(str[i+1]=='(')
				return isPossible(str,i+2,len,left+1,right) || isPossible(str,i+2,len,left,right);
			else if(str[i+1]==')')
				return isPossible(str,i+2,len,left,right+1) || isPossible(str,i+2,len,left,right);
		}
	}
	return isPossible(str,i+1,len,left,right);
}
Ejemplo n.º 8
0
/* 
 * Joins possibilities from two sources:
 * For example the one for the row and column
 * of a square. Only what is possible for both
 * is preserved.
 */
possibility possibility::operator+(const possibility &b) const
{
  possibility result(size);
  int i;
  for (i=1; i<=size; i++){
    if (!isPossible(i) || !b.isPossible(i)) result.removePossibility(i);
  }
  return result;
}
Ejemplo n.º 9
0
bool isPossible(int idx, int sum, int len)
{
    if (len == 0) return (sum == 0);
    if (idx >= total) return false;
 
    if (dp[idx][sum][len] == false) return false;
 
    if (sum >= real[idx])
    {
        res.push_back(real[idx]);
        if (isPossible(idx + 1, sum - real[idx], len - 1)) return true;
        res.pop_back();
    }
     
    if (isPossible(idx + 1, sum, len)) return true;
 
    return dp[idx][sum][len] = false;
}
Ejemplo n.º 10
0
 bool judgePoint24(vector<int>& nums) {
     sort(nums.begin(), nums.end());
     do{
         if(isPossible(nums)) {
             return true;
         }
     } while(next_permutation(nums.begin(), nums.end()));
     
     return false;
 }
Ejemplo n.º 11
0
 bool isPossible(double a, double b, double c) {
     if(isPossible(a + b, c) 
        or isPossible(a - b, c) 
        or isPossible(a * b, c) 
        or (b and isPossible(a / b, c))) return true;
     
     if(isPossible(a, b + c) 
        or isPossible(a, b - c) 
        or isPossible(a, b * c) 
        or (c and isPossible(a, b / c))) return true;
     return false;
 }
Ejemplo n.º 12
0
int main(){
	int i;
	while(cin>>i)
	{
		if (i==0)break;
		isPossible(i);
		cin>>i;
		}
	return 0;
}
Ejemplo n.º 13
0
bool Move::execute(Board& b, Color player, int& movesLeft) const
{
	if(!isPossible(b, player, movesLeft))
		return false;

	b.movePiece(m_position, m_destination);
	movesLeft -= m_cost;

	return true;
}
Ejemplo n.º 14
0
static void generateMaze(int x, int y)
{
  int *po;
  Maze[x][y]= Maze[x][y] + SET;
  po = isPossible(x,y);
  while (*po>0)
    {
      int nr = *po;
      int ran, in;
      in=(g_random_int()%nr)+1;
      //printf("random: %d en %d mogelijkheden\n", in, *po);
      ran=*(po + in);
      if (nr>=1)
	switch (ran)
	  {
	  case EAST:
	    Maze[x][y]&=~EAST;
	    Maze[x+1][y]&=~WEST;
	    generateMaze(x+1,y);
	    break;
	  case SOUTH:
	    Maze[x][y]&=~SOUTH;
	    Maze[x][y+1]&=~NORTH;
	    generateMaze(x,y+1);
	    break;
	  case WEST:
	    Maze[x][y]&=~WEST;
	    Maze[x-1][y]&=~EAST;
	    generateMaze(x-1,y);
	    break;
	  case NORTH:
	    Maze[x][y]&=~NORTH;
	    Maze[x][y-1]&=~SOUTH;
	    generateMaze(x,y-1);
	    break;

	  }
      po=isPossible(x,y);
    }

}
Ejemplo n.º 15
0
int nextRoute( int (*sMap)[MAX_M], int (*sCheck)[MAX_M], int destX, int destY, int destMin, int N, int M )
{
	int sIsPossible = 0;
	int sSum = 0;

	if ( sCheck[destY][destX] == 1 ) // 이미 한번 온 길
	{
		return 0;
	}

	if ( ( destX == 0 ) && 
		 ( destY == 0 ) && 
		 ( destMin == 0 ) ) // 출발점 도착
	{
		return 1;
	}

	if ( ( destX >= M ) || 
		 ( destY >= N ) || 
		 ( destX < 0 ) || 
		 ( destY < 0 ) || 
		 ( destMin < 0 ) ) // 가로 세로 한계를 넘어섬
	{
		return 0;
	}

	if ( ( sMap[destY][destX] > -1 ) && 
		 ( sMap[destY][destX] != destMin ) ) // 기록된 정보와 다르다
	{
		return 0;
	}

	sIsPossible = isPossible( destX, destY, destMin );
	if ( sIsPossible == 1 )
	{
		sCheck[destY][destX] = 1;

		sSum += nextRoute( sMap, sCheck, destX, destY - 1, destMin - 1, N, M ); //UP
		sSum += nextRoute( sMap, sCheck, destX, destY + 1, destMin - 1, N, M ); //Down
		sSum += nextRoute( sMap, sCheck, destX - 1, destY, destMin - 1, N, M ); //Left
		sSum += nextRoute( sMap, sCheck, destX + 1, destY, destMin - 1, N, M ); //Right
	}
	else
	{
		return 0; // 도달할 수 없는 경로
	}

	sCheck[destY][destX] = 0;

	return sSum;
}
Ejemplo n.º 16
0
void possibility::removePossibility(const int a)
{
  int result[n], i, j=0;
  if (isPossible(a)){
    for (i=0; i<n; i++){
      if (numbers[i] != a){
	result[j] = numbers[i];
	j++;
      }
    }
    n--;
    for (i=0; i<n; i++) numbers[i] = result[i];
  }
}
Ejemplo n.º 17
0
// --------------------------------------------------------
// does nothing on blank squares. Otherwise, it checks that the square's mark is in its possibility set and throws a fatal error if not. Finally, it updates the possibility sets in all the clusters to which it belongs by calling its delegate Cluster::shoop().
void BSquare::
shoop() const
{
    if ( !isBlank() )
    {
        if ( !isPossible(getMark()) )
            throw Fatal("Mark %d not possible in square (%d, %d)", getMark(), row, column);
        else {
            // update possibleSet in the cluster
            for (std::vector<Cluster*>::const_iterator it = clu.begin(); it < clu.end(); it++)
                (*it)->shoop(this);
        }
    }
}
Ejemplo n.º 18
0
int getNQueenCases(int col, int n, int* columnBoard) {
	int ret = 0;
	if (n == 1) return 1;
	if (isPossible(col, columnBoard)) {
		if (col == n) return 1;
		else {
			for (int row = 1; row <= n; row++) {
				columnBoard[col + 1] = row;
				ret += getNQueenCases(col + 1, n, columnBoard);
			}
		}
	}
	return ret;
}
Ejemplo n.º 19
0
vector<vector<int> > Solution::avgset(vector<int> &arr) {
    sort(arr.begin(), arr.end());
    real.clear();
    real = arr;
    dp.clear();
    res.clear();
 
    int total_sum = 0;
    total = arr.size();
 
    for(int i = 0; i < total; ++i)
        total_sum += arr[i];
     
    dp.resize(real.size(), vector<vector<bool> > (total_sum + 1, vector<bool> (total, true)));
 
    // We need to minimize size_of_set1. So, lets search for the first size_of_set1 which is isPossible. 
    for (int i = 1; i < total; i++)
    {
        // Sum_of_Set1 has to be an integer
        if ((total_sum * i) % total != 0) continue;
        int Sum_of_Set1 = (total_sum * i) / total;
        if (isPossible(0, Sum_of_Set1, i))
        {
            // Ok. Lets find out the elements in arr, not in res, and return the result.
            int ptr1 = 0, ptr2 = 0;
            vector<int> res1 = res;
            vector<int> res2;
            while (ptr1 < arr.size() || ptr2 < res.size())
            {
                if (ptr2 < res.size() && res[ptr2] == arr[ptr1])
                {
                    ptr1++;
                    ptr2++;
                    continue;
                }
                res2.push_back(arr[ptr1]);
                ptr1++;
            }
 
            vector<vector<int> > ans;
            ans.push_back(res1);
            ans.push_back(res2);
            return ans;
        }
    }
 
    vector<vector<int> > ans;
    return ans;
}
Ejemplo n.º 20
0
/**
 * @brief Check whether 'target' has just triggered any new reaction fire
 * @param[in] target The entity triggering fire
 */
void ReactionFire::updateAllTargets (const Edict* target)
{
	Actor* shooter = nullptr;

	/* check all possible shooters */
	while ((shooter = G_EdictsGetNextLivingActor(shooter))) {
		/* check whether reaction fire is possible (friend/foe, LoS) */
		if (isPossible(shooter, target)) {
			const int TUs = G_ReactionFireGetTUsForItem(shooter, target);
			if (TUs < 0)
				continue;	/* no suitable weapon */
			rft.add(shooter, target, TUs);
		} else {
			rft.remove(shooter, target);
		}
	}
}
bool JumpToTargetMovement::calculateBaseVelocity(Real &velocity)
{
    // Code from Weitsprung but do not jump as far
    velocity = (mMovingCreature->getCreature()->getEigenschaft("GE") +
                mMovingCreature->getCreature()->getEigenschaft("KK")) / 5.0;
    velocity*=0.8f;

    // steht nicht in den Regeln aber finde ich sinnvoll
    // velocityBase *= (1 - getrageneLast/KK);
    // steht in den Regeln: pro Ersch�pfung ein KK abziehen
    //if( mErschoepfung > getEigenschaft("KO") )
    //    velocity -= (mErschoepfung - getEigenschaft("KO")) / 5.0;
    // steht nicht in den Regeln, aber finde ich sinnvoll
    //if( getAu() < getAuBasis() / 3.0 )
    //    velocity -= (getAu() / getAuBasis() * 3.0) * getEigenschaft("GE") / 5.0;
    return isPossible();
}
Ejemplo n.º 22
0
int main()
{
	int t,i,j=1;
	char str[101];
	scanf("%d",&t);
	char c=getchar();
	while(t--)
	{
		gets(str);
	//	puts(str);
		int left=0,right=0;
		//printf("%d %d\n",left,right);
		if(isPossible(str,0,strlen(str),0,0))
			printf("Case %d:YES\n",j++);
		else
			printf("Case %d:NO\n",j++);
	}
	return 0;
}
Ejemplo n.º 23
0
bool solution() {
	memset(DP, 0, sizeof(DP));

	int len=strlen(str);

	// DP[pos][x][y] => (x, y)의 문자를 str의 pos번째 문자와 매칭시켰을 때 경우의 수(그 전 글자들도 매칭이 되야 함)
	// DP[pos][x][y] += if(data[x][y]==str[pos]) DP[pos-1][x.1][y.1]
	// (x, y)의 문자와 str의 pos번째 문자가 같다면 현재 위치의 경우의 수는 현재 위치로 올 가능성이 있는 8방향의
	// pos-1번째 DP테이블의 값을 더해주면 구할 수 있다.
	// 하지만 전 값을 가져오기 귀찮으므로 pos+1번째로 보내주는 형식으로 구현을 했다

	// 기저사례, 첫 글자가 같으면 1로 설정을 해 준다
	for(int i=0 ; i<5 ; i++)
		for(int j=0 ; j<5 ; j++)
			if(str[0]==data[i][j]) DP[0][i][j]=1;

	for(int pos=0 ; pos<len ; pos++) {
		for(int x=0 ; x<5 ; x++) {
			for(int y=0 ; y<5 ; y++) {
				// 현재 글자가 일치하지 않으면 볼 필요가 없다
				if(str[pos]!=data[x][y]) continue;

				// 글자가 같다면 다음 위치로 가능한 8방향에 현재의 값을 더해준다
				for(int k=0 ; k<8 ; k++) {
					int nextX=x+dx[k], nextY=y+dy[k];
					if(!isPossible(nextX, nextY)) continue;
					DP[pos+1][nextX][nextY]+=DP[pos][x][y];
				}
			}
		}
	}

	// 마지막 글자까지 확인할 수 있는 방법이 있다면 true를 반환
	for(int i=0 ; i<5 ; i++)
		for(int j=0 ; j<5 ; j++)
			if(DP[len][i][j]) return true;

	// 방법이 없다면 false를 반환
	return false;
}
Ejemplo n.º 24
0
/**
 * @brief Resolve the reaction fire for an entity, this checks that the entity can fire and then takes the shot
 * @param[in] shooter The entity using reaction fire
 * @param[in] target The victim of the reaction fire
 * @return true if the entity fired, false otherwise
 */
bool ReactionFire::tryToShoot (Actor* shooter, const Edict* target)
{
	/* check for valid target */
	assert(target);

	/* shooter can't take a reaction shot if it's not possible - and check that
	 * the target is still alive */
	if (!isPossible(shooter, target)) {
		rft.remove(shooter, target);
		return false;
	}

	/* take the shot */
	const bool tookShot = rf.shoot(shooter, target->pos, ST_RIGHT_REACTION, shooter->chr.RFmode.getFmIdx());

	if (tookShot) {
		/* clear any shakenness */
		shooter->removeShaken();
	}

	return tookShot;
}
Ejemplo n.º 25
0
        long long paint(int K, int T, vector<int> Vec) {
		    
            int N = Vec.size();
            
            long long end = 0;
            long long start = 0;

            for(int i = 0; i < N; ++i) {
                end += Vec[i];
            }
            long long ans = INT_MAX;
            ans *= INT_MAX;
            while(start <= end) {
                long long mid = (start + end) / 2;
                if(isPossible(mid, K, Vec)) {
                    ans = min(ans, mid);
                    end = mid - 1;
                } else {
                    start = mid + 1;
                }
            }
            
            return (ans * (long long) T) % 10000003;
	}
Ejemplo n.º 26
0
 bool WalkMovement::calculateBaseVelocity(Real &velocity)
 {
     velocity = mMovingCreature->getCurrentGS() / 3.6f * 0.7f;
     return isPossible();
 }
Ejemplo n.º 27
0
 bool isPossible(vector<int>& nums) {
     double a = nums[0], b = nums[1], c = nums[2], d = nums[3];
     if(isPossible(a + b, c, d) 
        or isPossible(a - b, c, d) 
        or isPossible(a * b, c, d) 
        or (b and isPossible(a / b, c, d))) return true;
     
     if(isPossible(a, b + c, d) 
        or isPossible(a, b - c, d) 
        or isPossible(a, b * c, d) 
        or (c and isPossible(a, b / c, d))) return true;
     
     if(isPossible(a, b, c + d) 
        or isPossible(a, b, c - d) 
        or isPossible(a, b, c * d) 
        or (d and isPossible(a, b, c / d))) return true;
     
     return false;
 }
Ejemplo n.º 28
0
 bool JogMovement::calculateBaseVelocity(Real &velocity)
 {
     velocity = mMovingCreature->getCurrentGS() / 2.0f;
     return isPossible();
 }
Ejemplo n.º 29
0
bool StrafeMovement::calculateBaseVelocity(Real &velocity)
{
    velocity = mMovingCreature->getCurrentGS() / 4.0;
    return isPossible();
}
 bool StepRecognitionMovement::calculateBaseVelocity(Real &velocity)
 {
     velocity = 0.0f;
     return isPossible();
 }