示例#1
0
void Allocator::retain(void *ptr, int object_style)
{
#ifdef DEBUG
  AllocatorNode *dbg_ptr = isMine(ptr);
  if(dbg_ptr)
  {
    if(object_style != 2)
      error("Allocator [debug mode]: try to retain a previously retained pointer! You'll destruct an inexistant object.");    
    if(object_style == dbg_ptr->object_style)
      error("Allocator [debug mode]: try to retain a previously retained pointer with same mode [%d]!", object_style);
  }
#endif

  // Create a new node to be placed *before* the root
  AllocatorNode *ptrs_ = (AllocatorNode *)sysAlloc(sizeof(AllocatorNode));
  if(!ptrs_)
    error("Allocator: not enough memory. Buy new ram.");
  ptrs_->prev = NULL;
  ptrs_->next = ptrs;
  if(ptrs)
    ptrs->prev = ptrs_;
  
  // Save the root
  ptrs = ptrs_;

  // Save the pointer
  ptrs->ptr = ptr;
  ptrs->object_style = object_style;
}
示例#2
0
文件: field.cpp 项目: busserull/tiles
void Field::setOpen(int x, int y){
  if(minesPlaced == false){
    startTime = time(nullptr);
    placeMines(x, y);
    minesPlaced = true;
  }
  int index = y * width + x;
  if(field[index].isOpen == false){
    openTiles++;
  }
  field[index].isOpen = true;
  if(field[index].isMine){
    minesOpened = true;
    endTime = time(nullptr);
    endTimeSet = true;
    for(int i = 0; i < height * width; i++){
      if(field[i].isMine){
        field[i].isOpen = true;
      }
    }
  }
  if(isMine(x,y) == false && getSurroundingMines(x, y) == 0){
    flushSurrounding(x, y);
  }
  if(onlyMinesLeft()){
    endTime = time(nullptr);
    endTimeSet = true;
    for(int i = 0; i < height * width; i++){
      if(field[i].isMine){
        field[i].isFlagged = true;
      }
    }
  }
}
示例#3
0
// Note: The "type" property is set in EntityItem::getActionArguments().
QVariantMap ObjectDynamic::getArguments() {
    QVariantMap arguments;
    withReadLock([&]{
        if (_expires == 0) {
            arguments["ttl"] = 0.0f;
        } else {
            quint64 now = usecTimestampNow();
            arguments["ttl"] = (float)(_expires - now) / (float)USECS_PER_SECOND;
        }
        arguments["tag"] = _tag;

        EntityItemPointer entity = _ownerEntity.lock();
        if (entity) {
            ObjectMotionState* motionState = static_cast<ObjectMotionState*>(entity->getPhysicsInfo());
            if (motionState) {
                arguments["::active"] = motionState->isActive();
                arguments["::motion-type"] = motionTypeToString(motionState->getMotionType());
            } else {
                arguments["::no-motion-state"] = true;
            }
        }
        arguments["isMine"] = isMine();
    });
    return arguments;
}
示例#4
0
文件: path.c 项目: EraYaN/MiDeRP
void backTrace()
{
	//Init
	Node *node, *nextNode;
	int i, direction = 0;
	path = (Node**)safeMalloc (sizeof (Node*) * (exitNode->label));
	node = exitNode;
	nextNode = NULL;
	i = exitNode->label;

	//Keep tracing until we reach the entry node
	while (node != entryNode)
	{
		nextNode = getAdjNode (node, direction, 0);

		if (nextNode && !isMine(node, nextNode) && nextNode->label >= 0 && nextNode->label < node->label) 
		{
			path[i--] = node = nextNode; 
		} 
		else 
		{ 
			direction = (direction + 1)%4; 
		}
	}
}
示例#5
0
/**
 * @brief Cell::paintEvent - paints circles on the cells, red for mine, blue for flag
 * @param event - paint event
 */
void Cell::paintEvent(QPaintEvent *event) {
    if (isOpened() && isMine() == false && 0 == m_value)
        return;
    QPushButton::paintEvent(event);
    QPainter p(this);
    if (isOpened()) {
        if (isMine()) {
            p.setBrush(QBrush(Qt::red, Qt::SolidPattern));
            p.drawEllipse(2, 2, width() - 4, height() - 4);
            return;
        }
        setText(QString::number(m_value));
        return;
    }
    if (m_isFlag) {
    p.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
    p.drawEllipse(2, 2, width() - 4, height() - 4);
  }
}
示例#6
0
文件: rate.c 项目: yulcat/shogi
int effectRange(Board board){ // Getting various moves is strategic benefit.
							  // Give additional score for each possible moves.
	int x,y,effect = 0;
	for(x=0;x<3;x++){
		for(y=0;y<4;y++){
			Tile tile = board.tile[x][y];
			if(isMine(tile.occupied)==0)
				effect += tile.myNum;
		}
	}
	return effect;
}
示例#7
0
static void FreeEntry(void* allocator, void* ptr)
{
	if (!isMine(allocator, ptr))
	{
		g_origMemFree(allocator, ptr);
		return;
	}

	void* memReal = ((char*)ptr - (16 - (*(uint32_t*)((uintptr_t)ptr - 4) & 0xF)) - 3);

	HeapFree(hHeap, 0, memReal);
	//free(memReal);
}
示例#8
0
文件: rate.c 项目: yulcat/shogi
int getPlaceDanger(Board board, Animal enemy){
	int i;
	int type = charToAnimalnum(enemy.type);
	for(i=0; i<animalDirectionCount[type]; i++){
		int dirc = animalDirections[type][i];
		int x = moveX(enemy.x, dirc);
		int y = moveY(enemy.y, dirc);
		if(x>=3 || x<0 || y>=4 || y<0)
			continue;
		char myType = charToAnimalnum(board.tile[x][y].occupied);
		if(!isMine(myType))
			continue;
		if(!animalCanFlee(board, x, y, myType))
			return typeToScore(board.tile[x][y].occupied)/2;
	}
	return 0;
}
示例#9
0
文件: rate.c 项目: yulcat/shogi
int getDanger(Tile tile){ // Get danger from cost comparing
	char target = tile.occupied;
	if(isMine(target)==0 || tile.enemyNum == 0)
		return 0;
		// If target is not mine, or there is no enemy nearby, Danger is 0.
	int myLoss = typeToScore(tile.occupied);
	if(tile.enemyNum > tile.myNum)
		return myLoss;
		// If enemy is outnumbered, count it loss.
	int i, minEnemyLoss = typeToScore(tile.enemyReach[0]);
	for(i=0; i<tile.enemyNum; i++){
		int enemyLoss = typeToScore(tile.enemyReach[i]);
		if(minEnemyLoss < enemyLoss)
			minEnemyLoss = enemyLoss;
	}
	return myLoss + minEnemyLoss;
	// If we can retake the tile, calculate profit and loss.
}
/**
  * @brief get here on reply
  */
void OpenNICQueryHistoryDialog::dataReady(OpenNICNet* net)
{
	QMapIterator<QString, QVariant>i(net->rxPacket().data());
	while (i.hasNext())
	{
		i.next();
		QString key = i.key();
		QVariant value = i.value();
		if ( key == OpenNICPacket::resolver_history )
		{
			QStringList data = value.toStringList();
			if (isMine(data))
			{
				setCursor(Qt::ArrowCursor);
				history(data);
			}
		}
	}
}
示例#11
0
文件: rate.c 项目: yulcat/shogi
void applyReach(Animal anim, Board* board){
	// Apply moveable range to each tiles from animal piece.
	int i, type = charToAnimalnum(anim.type);
	for(i=0; i<animalDirectionCount[type]; i++){
		if(isMine(anim.type))
			applyMy(
				anim.type, 
				anim.x, 
				anim.y, 
				animalDirections[type][i], 
				board);
		else
			applyEnemy(
				anim.type, 
				anim.x, 
				anim.y, 
				animalDirections[type][i], 
				board);
	}
}
示例#12
0
文件: Cell.cpp 项目: zeno15/Games
	CellSprites::Sprite Cell::getSpriteType(void) const {


		switch (m_State) {
		case State::Unrevealed:
			return CellSprites::Sprite::Starting;
		case State::Unkown:
			return CellSprites::Sprite::Unknown;
		case State::Mine:
			return CellSprites::Sprite::MineFlag;
		case State::Revealed:
			if (isMine()) {
				return CellSprites::Sprite::Mine;
			}
			return static_cast<CellSprites::Sprite>(CellSprites::Sprite::Mines_0 + m_NumberOfNeighbouringMines);
			break;
		}




		return CellSprites::Sprite::Mines_9;
	}
示例#13
0
文件: rate.c 项目: yulcat/shogi
int typeToScore(char type){ // Animal type to score
	if(isMine(type)==0 && isEnemy(type)==0)
		return 0;
	else
		return animalScores[charToAnimalnum(type)];
}
示例#14
0
文件: util.c 项目: EraYaN/MiDeRP
void displayGrid ()
{
	//Init
	unsigned int i, j;
	Node *current, *next;

	if (m > 20 || n > 20)
	{
		print (1, 1, "Wave expansion done (took %.4lfs), grid is too big to print\n", expansionTime);
		return;
	}

	print (1, 1, "Wave expansion done (took %.4lfs), displaying results!\n\n", expansionTime);

	//Loop through nodes top->down, left->right
	for (i=2*n-2; i!=-1; i--)
	{
		for (j=0; j<m; j++)
		{
			if (i % 2 == 0)
			{
				current = getNodeByXY(j, (i + 2)/2 - 1);
				next = getAdjNode(current, 1, 0);

				if (j < (m - 1))
				{
					//Check for mine
					if (!isMine (current, next))
					{
						if (current->label == -1)
							print(1, 1, "# - ");
						else
							print(1, 1, "%02d - ", current->label);
					}
					else
					{
						if (current->label == -1)
							print(1, 1, "# X ");
						else
							print(1, 1, "%02d X ", current->label);
					}
				}
				else
				{
					if (current->label == -1)
						print(1, 1, "#");
					else
						print(1, 1, "%02d", current->label);
				}
			}
			else
			{
				if (i > 0)
				{
					current = getNodeByXY(j, (i + 1)/2);
					next = getAdjNode(current, 3, 0);

					if (j < m)
					{
						//Check for mine
						if (!isMine (current, next))
							print(1, 1, "|    ");
						else
							print(1, 1, "X    ");
					}
					else 
					{
						//Check for mine
						if (!isMine (current, next))
							print(1, 1, "|");
						else
							print(1, 1, "X");
					}
				}
			}
		}
		print(1, 1, "\n");
	}
	print(1, 1, "\n");
}
示例#15
0
static bool isMineHook(void* allocator, void* mem)
{
	return isMine(allocator, mem) || g_origIsMine(allocator, mem);
}