Example #1
0
void Match::setPlayerStatus(Player* p)
{
    if(p->getStatus() == p->DEAD)
    {
        p->respawn();
    }
    int team = p->getTeam();
    if(ball->getTeam() == team)
    {
        if(p->getNumber() == ball->getPlayer())
        {
            if(checkSquare(p, team) != -1)
            {
                p->setStatus(p->BALL_WITH_OPP);
            }
            else
            {
                p->setStatus(p->HAS_BALL);
            }
        }
        else if(checkSquare(p, team) != -1)
        {
            p->setStatus(p->OPP_IN_SQUARE);
        }
        else
        {
            p->setStatus(p->TEAM_WITH_BALL);
        }
    }
    else if(ball->getTeam() == -1)
    {
        if(checkSquare(p, team) != -1)
        {
            p->setStatus(p->OPP_IN_SQUARE);
        }
        else
        {
            p->setStatus(p->LOOSE_BALL);
        }
    }
    else
    {
        if(checkSquare(p, team) != -1)
        {
            p->setStatus(p->OPP_IN_SQUARE);
        }
        else
        {
            p->setStatus(p->WITHOUT_BALL);
        }
    }
}
Example #2
0
void Match::dodge(Player *p)
{
    int randRating = Player::maxRating + 1;
    //cout << " Jumps";
    int team = p->getTeam(), oppTeam;
    Player *opp;
    if(team == 1)
    {
        oppTeam = 2;
        opp = teamTwo->getPlayer(checkSquare(p, 1));
    }
    else if(team == 2)
    {
        oppTeam = 1;
        opp = teamOne->getPlayer(checkSquare(p, 2));
    }
    int attackRoll = (rand()%randRating) + opp->getAttack();
    int dodgeRoll = (rand()%randRating) + p->getJump();

    if(attackRoll > dodgeRoll)
    {
        //cout << " but is killed by Kills " << opp->getName() << endl;
        p->kill();
        playersToMove.erase(playersToMove.begin()+ findPlayer(p));
        ball->drop();
        screen->updateKill(opp, p);
        screen->updateKillFeed(opp, p);
    }
    else
    {
        screen->updateDodge(opp, p);
        //cout << " and gets past" << opp->getName() << endl;
        if(team == 1)
        {
            p->setPosX(p->getPosX() + 1);
        }
        else if(team == 2)
        {
            p->setPosX(p->getPosX() - 1);
        }
        if(p->getNumber() == ball->getPlayer())
        {
            updateBall(p);
        }
    }

}
Example #3
0
void Match::attack(Player *p)
{
    int randRating = Player::maxRating + 1;
    //cout << " Attacks";
    int n = p->getTeam(), oppTeam;
    Player *opp;
    if(n == 1)
    {
        oppTeam = 2;
        opp = teamTwo->getPlayer(checkSquare(p, n));
    }
    else if(n == 2)
    {
        oppTeam = 1;
        opp = teamOne->getPlayer(checkSquare(p, n));
    }
    int attackRoll = (rand()%randRating) + p->getAttack();
    int dodgeRoll = (rand()%randRating) + opp->getJump();

    if(attackRoll > dodgeRoll)
    {
        //cout << " and Kills " << opp->getName() << endl;
        opp->kill();
        playersToMove.erase(playersToMove.begin()+ findPlayer(opp));
        screen->updateKillFeed(p, opp);

        if(ball->getPlayer() == opp->getNumber())
        {
            screen->updateKill(p, opp);
            ball->drop();
        }

    }
    else
    {
        if(ball->getPlayer() == opp->getNumber())
        {
            screen->updateDodge(p, opp);
            ball->drop();
        }
        //cout << " but misses " << opp->getName() << endl;
    }
}
Example #4
0
int main()
	{
	int numBoards;
	int i, j;
	int check;
	int sudoku[9][9];
	char c;
	int caseNum;
	
	FILE *in = fopen("sudokode.in", "r");
	
	/* get number of boards and then process each board */
	fscanf(in, "%d ", &numBoards);
	for (caseNum = 1; caseNum <= numBoards; caseNum++)
		{
		/* get input */
		for (i = 0; i < 9; i++)
			{
			for (j = 0; j < 9; j++)
				{
				/* convert values to 0-8 to make indexing easier */
				fscanf(in, "%c ", &c);
				sudoku[i][j] = c - '1';
				}
			}
		
		/* test all rows */
		check = TRUE;
		for (i = 0; i < 9 && check == TRUE; i++)
			check = checkRow(sudoku, i);
		
		/* test all columns */
		for (j = 0; j < 9 && check == TRUE; j++)
			check = checkCol(sudoku, j);
		
		/* test all 3x3 subsquares */
		for (i = 0; i < 9 && check == TRUE; i += 3)
			{
			for (j = 0; j < 9 && check == TRUE; j += 3)
				{
				check = checkSquare(sudoku, i, j);
				}
			}
		
		/* print output */
		printf("Sudoku #%d:  ", caseNum);
		if (check)
			printf("Dave's the man!\n\n");
		else
			printf("Try again, Dave!\n\n");
		}
	
	fclose(in);
	return 0;
	}
Example #5
0
// вычисление определителя матрицы по методу Гаусса
TYPE CMatrix::detGauss() const{
	if (checkSquare())
	{
		CMatrix temp = *this;
		
		int n = getRowCount();
		if (n == 1)
		{
			return temp[0][0]; // в случае, если матрица состоит из одного эл-та
		}

		for (int i = 0; i < n; i++)
		{
			if (temp[i][i] == 0)
			{
				int k = i + 1;
				if (k >= n) return 0; // последний элемент оказался нулевым

				while ((k < n) && (temp[k][i] == 0)) k++;

				if (temp[k][i] != 0)
				{
					for (int p = i; p < n; p++)	temp[i][p] += temp[k][p];
				}
				else
				{
					return 0;
				}
			} // проверили текущий диагональный элемент на 0

			for (int j = n - 1; j >= i; j--)
			{
				for (int p = i + 1; p < n; p++)
				{
					temp[p][j] -= temp[i][j] * (temp[p][i] / temp[i][i]);
				}
			}
		}

		TYPE result = 1;
		for (int i = 0; i < n; i++)
		{
			result *= temp[i][i];
		}
		
		return result;
	}
//	else return INFINITY;
	else return sizeof(TYPE);
}
Example #6
0
int main(){
    int count = 0, ac=0;
    vector<int> veca, vecb;
    veca.resize(6);
    vecb.resize(6);
    for(unsigned int i = 0; i< 6; ++i){
        veca[i] = i;
        vecb[i] = i;
    }

    do{
        do{ 
            ++ac;
            if(checkSquare(veca, vecb))
                ++count; // all test passed
        }while(next_combination(vecb, 10, 6));   //for b
    }while(next_combination(veca, 10, 6));       //for a
    printf("%d %d\n", count, ac);
}
void TerrainFile::updateGrid( const Point2I &minPt, const Point2I &maxPt )
{
   // here's how it works:
   // for the current terrain renderer we only care about
   // the minHeight and maxHeight on the GridSquare
   // so we do one pass through, updating minHeight and maxHeight
   // on the level 0 squares, then we loop up the grid map from 1 to
   // the top, expanding the bounding boxes as necessary.
   // this should end up being way, way, way, way faster for the terrain
   // editor

   PROFILE_SCOPE( TerrainFile_UpdateGrid );

   for ( S32 y = minPt.y - 1; y < maxPt.y + 1; y++ )
   {
      for ( S32 x = minPt.x - 1; x < maxPt.x + 1; x++ )
      {
         S32 px = x;
         S32 py = y;
         if ( px < 0 )
            px += mSize;
         if ( py < 0 )
            py += mSize;

         TerrainSquare *sq = findSquare( 0, px, py );
         sq->minHeight = 0xFFFF;
         sq->maxHeight = 0;

         // Update the empty state.
         if ( isEmptyAt( x, y ) )
            sq->flags |= TerrainSquare::Empty;
         else
            sq->flags &= ~TerrainSquare::Empty;

         getMinMax( sq->minHeight, sq->maxHeight, getHeight( x, y ) );
         getMinMax( sq->minHeight, sq->maxHeight, getHeight( x+1, y ) );
         getMinMax( sq->minHeight, sq->maxHeight, getHeight( x, y+1 ) );
         getMinMax( sq->minHeight, sq->maxHeight, getHeight( x+1, y+1 ) );
      }
   }

   // ok, all the level 0 grid squares are updated:
   // now update all the parent grid squares that need to be updated:
   for( S32 level = 1; level <= mGridLevels; level++ )
   {
      S32 size = 1 << level;
      S32 halfSize = size >> 1;  

      for( S32 y = (minPt.y - 1) >> level; y < (maxPt.y + size) >> level; y++ )
      {
         for ( S32 x = (minPt.x - 1) >> level; x < (maxPt.x + size) >> level; x++ )
         {
            S32 px = x << level;
            S32 py = y << level;

            TerrainSquare *sq = findSquare(level, px, py);
            sq->minHeight = 0xFFFF;
            sq->maxHeight = 0;
            sq->flags &= ~( TerrainSquare::Empty | TerrainSquare::HasEmpty );

            checkSquare( sq, findSquare( level - 1, px, py ) );
            checkSquare( sq, findSquare( level - 1, px + halfSize, py ) );
            checkSquare( sq, findSquare( level - 1, px, py + halfSize ) );
            checkSquare( sq, findSquare( level - 1, px + halfSize, py + halfSize ) );
         }
      }
   }
}
Example #8
0
// вычисление определителя матрицы по методу Гаусса
TYPE CMatrix::detGauss() const{
	if (checkSquare())
	{
		CMatrix temp = *this;
		
		UINT n = getRowCount();
		if (n == 1)
		{
			return temp[0][0]; // в случае, если матрица состоит из одного эл-та
		}

		for (int i = 0; i < n; i++)
		{
			if (temp[i][i] == 0)
			{
				UINT k = i + 1;
				if (k >= n) return 0; // последний элемент оказался нулевым

				while ((k < n) && (temp[k][i] == 0)) k++;

				if (temp[k][i] != 0)
				{
					for (UINT p = i; p < n; p++)	temp[i][p] += temp[k][p];
				}
				else
				{
					return 0;
				}
			} // проверили текущий диагональный элемент на 0

			for (int j = n - 1; j >= i; j--)
			{
				for (UINT p = i + 1; p < n; p++)
				{
					temp[p][j] -= temp[i][j] * (temp[p][i] / temp[i][i]);
				}
			}
		}

		TYPE result = 1;
		for (UINT i = 0; i < n; i++)
		{
			result *= temp[i][i];
		}
		
		return result;
	}
//	else return INFINITY;
//	return NAN;
	else
	{
		std::string 
			error, msg, place,
			reason, object;
		error = "Error: length_error: ";
		place = "CMatrix::detGauss(), checkSquare = ";
		reason = "false";
		object = std::to_string(UINT(this));

		msg = error + place + reason + ", Object = " + object;
		throw std::length_error(msg);
	}
	
}