示例#1
0
/*********************************************************************************
*Description - Defense fn 
*fn that send number of die and faces to Arena class and assesses the amount of 
*damage received 
*Parameters - Passes the amount of damage received to the the Armor fn, using 
polymorphism
*********************************************************************************/
void Reptile::defense() {

	int defend, damage, impact;

	battle3.setNumFaces(R_DEFEND_FACE);
	battle3.setNumDice(R_DEFEND_DIE);
	defend = battle3.Roll();	

	battle3.setDefendRoll(defend);
	damage = battle3.deathBlow();

		if(damage == 0)
		{
			cout << "No damage!!" << endl;
		}
			
			else if(damage > R_ARMOR)
			{	
				impact = damage - R_ARMOR;
				cout << "The Reptile People were injured! Because of armor, it only had an impact of: -"<< impact << endl; 
			}
			
				else if((damage > 0) && (damage <= R_ARMOR))
				{
					cout << "The Reptile People were hit, but were saved by their armor!!" << endl;
				}
	
				Character *chr = &rep;
				chr->armor(damage);
				chr->strength();

}
Battle::Command Battle::Catapult::GetCommand(Arena & arena) const
{
    u32 shots = cat_shots;
    std::vector<u32> values(CAT_MISS + 1, 0);

    values[CAT_WALL1] = arena.GetCastleTargetValue(CAT_WALL1);
    values[CAT_WALL2] = arena.GetCastleTargetValue(CAT_WALL2);
    values[CAT_WALL3] = arena.GetCastleTargetValue(CAT_WALL3);
    values[CAT_WALL4] = arena.GetCastleTargetValue(CAT_WALL4);
    values[CAT_TOWER1] = arena.GetCastleTargetValue(CAT_TOWER1);
    values[CAT_TOWER2] = arena.GetCastleTargetValue(CAT_TOWER2);
    values[CAT_TOWER3] = arena.GetCastleTargetValue(CAT_TOWER3);
    values[CAT_BRIDGE] = arena.GetCastleTargetValue(CAT_BRIDGE);

    Command cmd(MSG_BATTLE_CATAPULT);
    cmd.GetStream() << shots;

    while(shots--)
    {
        int target = GetTarget(values);
        u32 damage = GetDamage(target, arena.GetCastleTargetValue(target));
        cmd.GetStream() << target << damage;
        values[target] -= damage;
    }

    return cmd;
}
示例#3
0
string Player::dropBrain()
{
    if (m_arena->getCellStatus(m_row, m_col) == HAS_BRAIN)
        return "There's already a brain at this spot.";
    m_arena->setCellStatus(m_row, m_col, HAS_BRAIN);
    return "A brain has been dropped.";
}
示例#4
0
文件: heap.cpp 项目: UIKit0/pyston
void* Heap::getAllocationFromInteriorPointer(void* ptr) {
    if (large_arena.contains(ptr)) {
        LargeObj *cur = large_head;
        while (cur) {
            if (ptr >= cur && ptr < &cur->data[cur->obj_size])
                return &cur->data[0];
            cur = cur->next;
        }
        return NULL;
    }

    if (!small_arena.contains(ptr))
        return NULL;

    Block *b = Block::forPointer(ptr);
    size_t size = b->size;
    int offset = (char*)ptr - (char*)b;
    int obj_idx = offset / size;

    if (obj_idx < b->minObjIndex() || obj_idx >= b->numObjects())
        return NULL;

    int atom_idx = obj_idx * (size / ATOM_SIZE);

    int bitmap_idx = atom_idx / 64;
    int bitmap_bit = atom_idx % 64;
    uint64_t mask = 1L << bitmap_bit;
    if (b->isfree[bitmap_idx] & mask)
        return NULL;

    return &b->atoms[atom_idx];
}
示例#5
0
int main()
{
  Comparator cmp;
  Arena arena;
  SkipList<Key, Comparator> list(cmp, &arena);
  const int N = 2000;
  std::set<Key> keys;
  for (int i = 0; i < N; i++)
  {
    list.Insert(i);
    keys.insert(i);
  }

  for (auto it = keys.begin(); it != keys.end(); ++it)
  {
    if (!list.Contains(*it))
    {
      cout<<*it<<"\t";
    }
  }

  size_t * p = (size_t*)(arena.AllocateAligned(sizeof(size_t)));
  *p = 100;
   cout<<*p<<endl;
   list.NewNodeTest(100, 12);
  return 0;
}
示例#6
0
int main(int argc, char** argv) {
    srand(time(NULL));
    
    Arena<Fighter *> arena;
    arena.main();
    
    return 0;
}
示例#7
0
TEST(ArenaTest, AllocateStringPiece) {
    Arena arena;

    toft::StringPiece origin = "hello world";
    toft::StringPiece copy = arena.Allocate(origin);
    EXPECT_EQ(origin, copy);
    EXPECT_NE(origin.data(), copy.data());
    EXPECT_EQ(copy.data(), arena.current_block());
}
示例#8
0
TEST(ArenaTest, AllocateType) {
    Arena arena;

    arena.Allocate< Array<9> >();
    EXPECT_EQ(9, arena.total_reserved_bytes() - arena.remained_buffer_size());

    arena.Allocate<uint32_t>();
    EXPECT_EQ(16, arena.total_reserved_bytes() - arena.remained_buffer_size());
}
示例#9
0
void ciMethodData::load_data() {
  MethodData* mdo = get_MethodData();
  if (mdo == NULL) {
    return;
  }

  // To do: don't copy the data if it is not "ripe" -- require a minimum #
  // of invocations.

  // Snapshot the data -- actually, take an approximate snapshot of
  // the data.  Any concurrently executing threads may be changing the
  // data as we copy it.
  Copy::disjoint_words((HeapWord*) mdo,
                       (HeapWord*) &_orig,
                       sizeof(_orig) / HeapWordSize);
  Arena* arena = CURRENT_ENV->arena();
  _data_size = mdo->data_size();
  _extra_data_size = mdo->extra_data_size();
  int total_size = _data_size + _extra_data_size;
  _data = (intptr_t *) arena->Amalloc(total_size);
  Copy::disjoint_words((HeapWord*) mdo->data_base(), (HeapWord*) _data, total_size / HeapWordSize);

  // Traverse the profile data, translating any oops into their
  // ci equivalents.
  ResourceMark rm;
  ciProfileData* ci_data = first_data();
  ProfileData* data = mdo->first_data();
  while (is_valid(ci_data)) {
    ci_data->translate_from(data);
    ci_data = next_data(ci_data);
    data = mdo->next_data(data);
  }
  if (mdo->parameters_type_data() != NULL) {
    _parameters = data_layout_at(mdo->parameters_type_data_di());
    ciParametersTypeData* parameters = new ciParametersTypeData(_parameters);
    parameters->translate_from(mdo->parameters_type_data());
  }

  load_extra_data();

  // Note:  Extra data are all BitData, and do not need translation.
  _current_mileage = MethodData::mileage_of(mdo->method());
  _invocation_counter = mdo->invocation_count();
  _backedge_counter = mdo->backedge_count();
  _state = mdo->is_mature()? mature_state: immature_state;

  _eflags = mdo->eflags();
  _arg_local = mdo->arg_local();
  _arg_stack = mdo->arg_stack();
  _arg_returned  = mdo->arg_returned();
#ifndef PRODUCT
  if (ReplayCompiles) {
    ciReplay::initialize(this);
  }
#endif
}
示例#10
0
Arena*
Chunk::allocateArena(JSRuntime* rt, Zone* zone, AllocKind thingKind, const AutoLockGC& lock)
{
    Arena* arena = info.numArenasFreeCommitted > 0
                   ? fetchNextFreeArena(rt)
                   : fetchNextDecommittedArena();
    arena->init(zone, thingKind);
    updateChunkListAfterAlloc(rt, lock);
    return arena;
}
示例#11
0
        void traverse(const Arena& arena)                // Build up the name
        {
            if (ArenaPtr p = arena.parent())             // Has a parent arena?
            {
                traverse(*p);                            // ...traverse parent
                *this += '/';                            // ...add a delimiter
            }

            *this += arena.name();                       // Append arena name
        }
示例#12
0
文件: heap.cpp 项目: UIKit0/pyston
void Heap::free(void* ptr) {
    if (large_arena.contains(ptr)) {
        LargeObj *lobj = LargeObj::fromPointer(ptr);
        _freeLargeObj(lobj);
        return;
    }

    assert(small_arena.contains(ptr));
    Block *b = Block::forPointer(ptr);
    _freeFrom(ptr, b);
}
示例#13
0
Spawner::Spawner(Arena& arena): m_level(1),
                                m_spawnDelay(sf::seconds(1.0f)),
                                m_arenaSize(arena.getSize()),
                                m_doorSize
                                (
                                    (arena.getSize().x / 2) - (arena.getSize().x / 6),
                                    (arena.getSize().x / 2) + (arena.getSize().x / 6)
                                ),
                                m_randLoc(0, 3)
{
}
示例#14
0
void
GCMarker::processMarkStackOther(SliceBudget &budget, uintptr_t tag, uintptr_t addr)
{
    if (tag == TypeTag) {
        ScanTypeObject(this, reinterpret_cast<types::TypeObject *>(addr));
    } else if (tag == SavedValueArrayTag) {
        JS_ASSERT(!(addr & Cell::CellMask));
        JSObject *obj = reinterpret_cast<JSObject *>(addr);
        HeapValue *vp, *end;
        if (restoreValueArray(obj, (void **)&vp, (void **)&end))
            pushValueArray(obj, vp, end);
        else
            pushObject(obj);
    } else if (tag == IonCodeTag) {
        MarkChildren(this, reinterpret_cast<ion::IonCode *>(addr));
    } else if (tag == ArenaTag) {
        ArenaHeader *aheader = reinterpret_cast<ArenaHeader *>(addr);
        AllocKind thingKind = aheader->getAllocKind();
        size_t thingSize = Arena::thingSize(thingKind);

        for ( ; aheader; aheader = aheader->next) {
            Arena *arena = aheader->getArena();
            FreeSpan firstSpan(aheader->getFirstFreeSpan());
            const FreeSpan *span = &firstSpan;

            for (uintptr_t thing = arena->thingsStart(thingKind); ; thing += thingSize) {
                JS_ASSERT(thing <= arena->thingsEnd());
                if (thing == span->first) {
                    if (!span->hasNext())
                        break;
                    thing = span->last;
                    span = span->nextSpan();
                } else {
                    JSObject *object = reinterpret_cast<JSObject *>(thing);
                    if (object->hasSingletonType() && object->markIfUnmarked(getMarkColor()))
                        pushObject(object);
                    budget.step();
                }
            }
            if (budget.isOverBudget()) {
                pushArenaList(aheader);
                return;
            }
        }
    }

#if JS_HAS_XML_SUPPORT
    else {
        JS_ASSERT(tag == XmlTag);
        MarkChildren(this, reinterpret_cast<JSXML *>(addr));
    }
#endif
}
示例#15
0
// ------------------------------------------------------------------
// ciMethod::load_code
//
// Load the bytecodes and exception handler table for this method.
void ciMethod::load_code() {
  VM_ENTRY_MARK;
  assert(is_loaded(), "only loaded methods have code");

  methodOop me = get_methodOop();
  Arena* arena = CURRENT_THREAD_ENV->arena();

  // Load the bytecodes.
  _code = (address)arena->Amalloc(code_size());
  memcpy(_code, me->code_base(), code_size());

  // Revert any breakpoint bytecodes in ci's copy
  if (me->number_of_breakpoints() > 0) {
    BreakpointInfo* bp = instanceKlass::cast(me->method_holder())->breakpoints();
    for (; bp != NULL; bp = bp->next()) {
      if (bp->match(me)) {
        code_at_put(bp->bci(), bp->orig_bytecode());
      }
    }
  }

  // And load the exception table.
  typeArrayOop exc_table = me->exception_table();

  // Allocate one extra spot in our list of exceptions.  This
  // last entry will be used to represent the possibility that
  // an exception escapes the method.  See ciExceptionHandlerStream
  // for details.
  _exception_handlers =
    (ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*)
                                         * (_handler_count + 1));
  if (_handler_count > 0) {
    for (int i=0; i<_handler_count; i++) {
      int base = i*4;
      _exception_handlers[i] = new (arena) ciExceptionHandler(
                                holder(),
            /* start    */      exc_table->int_at(base),
            /* limit    */      exc_table->int_at(base+1),
            /* goto pc  */      exc_table->int_at(base+2),
            /* cp index */      exc_table->int_at(base+3));
    }
  }

  // Put an entry at the end of our list to represent the possibility
  // of exceptional exit.
  _exception_handlers[_handler_count] =
    new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0);

  if (CIPrintMethodCodes) {
    print_codes();
  }
}
示例#16
0
bool Player::shoot(int dir)
{
    m_age++;

    if (rand() % 3 != 0)  // miss with 2/3 probability
        return false;

	switch(dir)
	{
	case UP:
		for (int r = m_row; r >= 1; r--) //starts at the player's row position and steps down, stopping at the end of the arena
		{
			if (m_arena->nRobotsAt(r, m_col) >= 1) //if there is a robot at the current step, destroy it and return
			{
				m_arena->destroyRobot(r, m_col);
				return true;
			}
		}
		break;
	case DOWN:
		for (int r = m_row; r <= m_arena->rows(); r++) //starts at player's row and goes down
		{
			if (m_arena->nRobotsAt(r, m_col) >= 1) //if there is a robot at the current step, destroy it and return
			{
				m_arena->destroyRobot(r, m_col);
				return true;
			}
		}
		break;
	case LEFT:
		for (int c = m_col; c >= 1; c--) //starts at player's column position and steps to the left one space at a time
		{
			if (m_arena->nRobotsAt(m_row, c) >= 1)
			{
				m_arena->destroyRobot(m_row, c); //if there is a robot at the current step, destroy it and return
				return true;
			}
		}
		break;
	case RIGHT:
		for (int c = m_col; c <= m_arena->cols(); c++) //starts at player's column and goes right
		{
			if (m_arena->nRobotsAt(m_row, c) >= 1)
			{
				m_arena->destroyRobot(m_row, c); //if there is a robot at the current step, destroy it and return
				return true;
			}
		}
		break;
	}
	return false; //didn't hit anything
}
示例#17
0
/*********************************************************************************
*Description - Attack fn Fn that passes number of die and die faces to Arena fn 
*Parameters - CONST for number of die and die faces
*********************************************************************************/
void Reptile::attack() {
	
	int attack;

	battle3.setNumFaces(R_ATTACK_FACE);
	battle3.setNumDice(R_ATTACK_DIE);
	attack = battle3.Roll();

	cout << "The Reptile People delivered a heavy blow to the opponent with a force of: " << attack << endl;
	
	battle3.setAttackRoll(attack);

}
示例#18
0
文件: esfinder.cpp 项目: avitase/rabi
void ESFinder::initVec(vec &psi, const Arena &arena) {
  const std::size_t N = psi.size();

  VecTools::initRand(0);
  for (std::size_t i=0; i<N; i++) {
    const double pot = std::abs(arena.evaluatePotentialAtGridPoint(i));
    const double rnd = VecTools::getRandom(-pot, pot);
    psi[i] = rnd;
  }

  const double dx = arena.getStepSizeX();
  VecTools::normalize(psi, dx);
}
示例#19
0
void Map::optimize(const fs::path& directory, const fs::path& target,
                   const Options& options) {
  const auto descriptor = internal::Descriptor::readFromDirectory(directory);
  checkDescriptor(descriptor, directory);
  fs::path prefix = directory / getPartitionPrefix(0);
  const Stats stats = internal::Partition::stats(prefix);
  Options new_options = options;
  new_options.error_if_exists = true;
  new_options.create_if_missing = true;
  if (options.block_size == 0) {
    new_options.block_size = stats.block_size;
  }
  if (options.num_partitions == 0) {
    new_options.num_partitions = descriptor.num_partitions;
  }
  Map new_map(target, new_options);

  for (int i = 0; i < descriptor.num_partitions; i++) {
    prefix = directory / getPartitionPrefix(i);
    if (options.verbose) {
      mt::log() << "Optimizing partition " << (i + 1) << " of "
                << descriptor.num_partitions << std::endl;
    }
    if (options.compare) {
      Arena arena;
      std::vector<Slice> values;
      internal::Partition::forEachEntry(
          prefix, [&new_map, &arena, &options, &values](const Slice& key,
                                                        Iterator* iter) {
            arena.deallocateAll();
            values.reserve(iter->available());
            values.clear();
            while (iter->hasNext()) {
              values.push_back(iter->next().makeCopy(&arena));
            }
            std::sort(values.begin(), values.end(), options.compare);
            for (const auto& value : values) {
              new_map.put(key, value);
            }
          });
    } else {
      internal::Partition::forEachEntry(
          prefix, [&new_map](const Slice& key, Iterator* iter) {
            while (iter->hasNext()) {
              new_map.put(key, iter->next());
            }
          });
    }
  }
}
示例#20
0
void timerGasBar(int value){
	// on posto
	if(player.getFlying() && !onPosto(player, arena.getPostoAbastecimento())){
		player.decGas();
	}

	// refuels
	if(onPosto(player, arena.getPostoAbastecimento())){
		player.setGas(player.getTempoDeVoo());
	}

	glutTimerFunc((1000),timerGasBar,0);
	glutPostRedisplay();
}
示例#21
0
  // Return false without changing anything if moving one step from (r,c)
  // in the indicated direction would hit a run off the edge of the arena.
  // Otherwise, update r and c to the position resulting from the move and
  // return true.
bool attemptMove(const Arena& a, int dir, int& r, int& c)
{
    int rnew = r;
    int cnew = c;
    switch (dir)
    {
      case NORTH:  if (r <= 1)        return false; else rnew--; break;
      case EAST:   if (c >= a.cols()) return false; else cnew++; break;
      case SOUTH:  if (r >= a.rows()) return false; else rnew++; break;
      case WEST:   if (c <= 1)        return false; else cnew--; break;
    }
    r = rnew;
    c = cnew;
    return true;
}
示例#22
0
文件: heap.cpp 项目: UIKit0/pyston
static Block* alloc_block(uint64_t size, Block** prev) {
    // TODO use mmap

    Block* rtn = (Block*)small_arena.doMmap(sizeof(Block));
    assert(rtn);
    rtn->size = size;
    rtn->prev = prev;
    rtn->next = NULL;

#ifndef NVALGRIND
    // Not sure if this mempool stuff is better than the malloc-like interface:
    //VALGRIND_CREATE_MEMPOOL(rtn, 0, true);
#endif

    // Don't think I need to do this:
    memset(rtn->isfree, 0, sizeof(Block::isfree));

    int num_objects = rtn->numObjects();
    int num_lost = rtn->minObjIndex();
    int atoms_per_object = rtn->atomsPerObj();
    for (int i = num_lost * atoms_per_object; i < num_objects * atoms_per_object; i += atoms_per_object) {
        int idx = i / 64;
        int bit = i % 64;
        rtn->isfree[idx] ^= (1L << bit);
        //printf("%d %d\n", idx, bit);
    }

    //printf("%d %d %d\n", num_objects, num_lost, atoms_per_object);
    //for (int i =0; i < BITFIELD_ELTS; i++) {
        //printf("%d: %lx\n", i, rtn->isfree[i]);
    //}
    return rtn;
}
示例#23
0
std::string startMachine(std::vector<std::string> &champions)
{
	Arena *arena = new Arena();
	std::vector<std::string> championss;

/*	std::cout << "BEGIN LOAD" << std::endl;
	championss.push_back("C:\\Users\\norman_e\\Pictures\\reference_champion.out");
	championss.push_back("C:\\Users\\norman_e\\Pictures\\forker.out");*/
	for (std::vector<std::string>::iterator it = champions.begin(); it != champions.end(); it++)
		std::cout << "Path champion: " << *it << std::endl;
	std::cout << "DONE LOAD" << std::endl;
	if (arena->setupArena(champions))
		return (arena->start());
	std::cout << "DONE GAME" << std::endl;
	return "";
}
示例#24
0
/*********************************************************************************
*Description - Strength fn 
*Fn that assess damage from the attack die minus the defenders roll, when the 
*character is the defender  
*********************************************************************************/
void Reptile::strength() {
	
	if (getStrength() > 8)
	{
		cout << "The fight continues! Health status is: " << getStrength() << endl;
	}
		
		if((getStrength() > 5) && (getStrength() <= 8))
		{	
			cout << "The Reptile People are taking a beating, health status is: " << getStrength() << endl;
		}
			
			if((getStrength() >= 1) && (getStrength() <= 5))
			{
				cout << "The Reptile People are hanging by a thread! Health status is: " << getStrength() << endl;
			}
				
				if(getStrength() <= 0)
				{
					cout << "\nThe Reptile People have suffered a death blow and have perished in battle3. " << endl;
					setStatus(false);
					battle3.setGoblinFactor(false);
					
				}
}
示例#25
0
string Game::takePlayerTurn()
{
    for (;;)
    {
        cout << "Your move (n/e/s/w/x or nothing): ";
        string playerMove;
        getline(cin, playerMove);

        Player* player = m_arena->player();
        int dir;

        if (playerMove.size() == 0)
        {
            if (recommendMove(*m_arena, player->row(), player->col(), dir))
                return player->move(dir);
            else
                return player->dropBrain();
        }
        else if (playerMove.size() == 1)
        {
            if (tolower(playerMove[0]) == 'x')
                return player->dropBrain();
            else if (charToDir(playerMove[0], dir))
                return player->move(dir);
        }
        cout << "Player move must be nothing, or 1 character n/e/s/w/x." << endl;
    }
}
示例#26
0
void Player::moveOrAttack(int dir)
{
    m_age++;
    int r = m_row;
    int c = m_col;
    if (m_arena->determineNewPosition(r, c, dir))
    {
        if (m_arena->nRobotsAt(r, c) > 0)
            m_arena->attackRobotAt(r, c, dir);
        else
        {
            m_row = r;
            m_col = c;
        }
    }
}
示例#27
0
void display(void){

	glClear (GL_COLOR_BUFFER_BIT);

		// arena and helicopter
		glPushMatrix();
			arena.drawArena(ARENAX, ARENAY);
		glPopMatrix();

		if(!checkDefeat(player, ARENAX/2.0,ARENAY/2.0)){
			// shots
			glPushMatrix();
				for(int i = 0 ; i < playerShots.size() ; i++) playerShots.at(i).draw();
				if(enemyShots.size() > 0){
					for(int i = 0 ; i < enemyShots.size() ; i++) enemyShots.at(i).draw();
				}
			glPopMatrix();

			glPushMatrix();
				player.draw();
			glPopMatrix();
			glPushMatrix();
				enemies.at(0).draw();
				enemies.at(1).draw();
				enemies.at(2).draw();
			glPopMatrix();
		}
	glEnd();
	glutSwapBuffers();
}
示例#28
0
int main(int argc, char **argv) 
{
	std::cout << 
		"\n"
		"-----------------------------------------------------------------------\n"
  	"Tetris 3D Testing Program:\n"
		" - a/d/w:  rotate about x/y/z-axis\n"
		" - arrow keys: move the superblock in the x-y plane\n"
		" - s: move the superblock down\n"
		" - SPACE: insert superblock and switch to the next random tetris block\n"
		" - R: Reset the game\n"
		"-----------------------------------------------------------------------" << endl;
	glutInit(&argc, argv); // initialize glut state
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	glutCreateWindow("Super Block Test");

	// register callbacks
	glutReshapeFunc(reshapeCallback); // window reshape callback
	glutDisplayFunc(drawCallback); // (re)display callback
	glutIdleFunc(idleCallback); // incremental update 
	glutMouseFunc(mouseButton);			 // process mouse button push/release
	glutMotionFunc(mouseMove);			 // process mouse dragging 
	glutIgnoreKeyRepeat(1);				// ignore key repeat when holding key down
	glutKeyboardFunc(processNormalKeysCallback); // process standard key clicks
	glutSpecialFunc(processSpecialKeysCallback);

	initGL(WINDOW_WIDTH, WINDOW_HEIGHT);

	//Assign arena to world
	Arena a;
	world.setArena(&a);

	// set up player bindings
	Player player1; KeyMapping map1(KeyMapping::MULTI_PLAYER_A);
	ic1.bindPlayerToMapping(&player1, map1);
	a.assignToArena(&player1, Arena::TOP_ARENA);

	world.startNetworkGame();

	// enter GLUT event processing cycle
	glutMainLoop();

	return 0;
}
示例#29
0
Arena*
Chunk::fetchNextDecommittedArena()
{
    MOZ_ASSERT(info.numArenasFreeCommitted == 0);
    MOZ_ASSERT(info.numArenasFree > 0);

    unsigned offset = findDecommittedArenaOffset();
    info.lastDecommittedArenaOffset = offset + 1;
    --info.numArenasFree;
    decommittedArenas.unset(offset);

    Arena* arena = &arenas[offset];
    MarkPagesInUse(arena, ArenaSize);
    arena->setAsNotAllocated();

    return arena;
}
示例#30
0
文件: robots.cpp 项目: nwtsai/CS31
void Player::moveOrAttack(int dir)
{
    m_age++;
    // If there is a robot adjacent to the player in the direction
    // dir, attack it.  Otherwise, move the player to that position if
    // possible (i.e., if the move would not be off the edge of the arena).

    int tempr = m_row;
    int tempc = m_col;
    m_arena->determineNewPosition(tempr, tempc, dir);
    int nRobots = m_arena->nRobotsAt(tempr, tempc);

    if (nRobots > 0)
        m_arena->attackRobotAt(tempr, tempc, dir);
    else
        m_arena->determineNewPosition(m_row, m_col, dir);
}