Beispiel #1
0
void
TBIndex::setSquare(int pieceNo, int square) {
    if (pieceNo == 0) { // White king
        idx &= ~(0xf << (6*p-5));
        idx |= kingMap[square] << (6*p-5);

        int sym = symType[square];
        if (sym & 1)
            mirrorX();
        if (sym & 2)
            mirrorY();
        if (sym & 4)
            mirrorD();
    } else if (pieceNo == nWhite) { // Black king
        int oldSq = getSquare(pieceNo);
        for (int i = 1; i < p; i++) {
            if (getSquare(i) == oldSq) {
                idx &= ~(0x3f << pieceShift(i));
                idx |= square << pieceShift(i);
            }
        }
    } else {
        idx &= ~(0x3f << pieceShift(pieceNo));
        idx |= square << pieceShift(pieceNo);
    }
}
Beispiel #2
0
void Level::putCreature(Vec2 position, Creature* c) {
  creatures.push_back(c);
  CHECK(getSquare(position)->getCreature() == nullptr);
  c->setLevel(this);
  c->setPosition(position);
  //getSquare(position)->putCreatureSilently(c);
  getSquare(position)->putCreature(c);
  notifyLocations(c);
}
Beispiel #3
0
void Level::moveCreature(Creature* creature, Vec2 direction) {
  CHECK(canMoveCreature(creature, direction));
  Vec2 position = creature->getPosition();
  Square* nextSquare = getSquare(position + direction);
  Square* thisSquare = getSquare(position);
  thisSquare->removeCreature();
  creature->setPosition(position + direction);
  nextSquare->putCreature(creature);
  notifyLocations(creature);
}
Beispiel #4
0
void Level::swapCreatures(Creature* c1, Creature* c2) {
  Vec2 position1 = c1->getPosition();
  Vec2 position2 = c2->getPosition();
  Square* square1 = getSquare(position1);
  Square* square2 = getSquare(position2);
  square1->removeCreature();
  square2->removeCreature();
  c1->setPosition(position2);
  c2->setPosition(position1);
  square1->putCreature(c2);
  square2->putCreature(c1);
  notifyLocations(c1);
  notifyLocations(c2);
}
void BFS()
{
    rear=0,front=1;
    queue[0]=getAddress(square);
    father[0]=-1,operation[0]=0;
    setRecord(square);
    while(rear<front)
    {
        getSquare(queue[rear]);
        for(int i=1; i<=3; i++)
        {
            copy();
            operate(i,temp);
            if(setRecord(temp))
            {
                queue[front]=getAddress(temp);
                father[front]=rear;
                operation[front]=i;
                if(check())
                {
                    getResult(front);
                    return;
                }
                front++;
            }
        }
        rear++;
    }
}
Beispiel #6
0
void Level::killCreature(Creature* creature) {
  removeElement(creatures, creature);
  getSquare(creature->getPosition())->removeCreature();
  model->removeCreature(creature);
  if (creature->isPlayer())
    setPlayer(nullptr);
}
Beispiel #7
0
void Level::changeLevel(Level* destination, Vec2 landing, Creature* c) {
  Vec2 fromPosition = c->getPosition();
  removeElement(creatures, c);
  getSquare(c->getPosition())->removeCreature();
  model->changeLevel(destination, landing, c);
  EventListener::addChangeLevelEvent(c, this, fromPosition, destination, landing);
}
Beispiel #8
0
bool Level::canMoveCreature(const Creature* creature, Vec2 direction) const {
  Vec2 position = creature->getPosition();
  Vec2 destination = position + direction;
  if (!inBounds(destination))
    return false;
  return getSquare(destination)->canEnter(creature);
}
Beispiel #9
0
void Level::changeLevel(StairDirection dir, StairKey key, Creature* c) {
  Vec2 fromPosition = c->getPosition();
  removeElement(creatures, c);
  getSquare(c->getPosition())->removeCreature();
  Vec2 toPosition = model->changeLevel(dir, key, c);
  EventListener::addChangeLevelEvent(c, this, fromPosition, c->getLevel(), toPosition);
}
Beispiel #10
0
void Level::killCreature(Creature* creature) {
  bucketMap.removeElement(creature->getPosition(), creature);
  removeElement(creatures, creature);
  getSquare(creature->getPosition())->removeCreature();
  model->removeCreature(creature);
  if (creature->isPlayer())
    updatePlayer();
}
Beispiel #11
0
void remCell(Grid* W,Cell* killMe){/*dead cell is removed from Grid and added to list of dead cells*/
  killMe->alive=0;
  LL* myDeadLL=malloc(sizeof(LL));
  initLL(myDeadLL,killMe);
  remLL(&getSquare(W,killMe->CellPos)->cells,&killMe->mySqElem);
  addLL(&W->deadCells,myDeadLL);
  freeLL(killMe->BondedCells);
  killMe->BondedCells=NULL;};
Beispiel #12
0
shFeature *
shMapLevel::addTrap (int x, int y, shFeature::Type type)
{
    shFeature *trap = new shFeature ();
    trap->mX = x;
    trap->mY = y;
    if (shFeature::kHole != type) {
        trap->mTrapUnknown = 1;
        trap->mTrapMonUnknown = 1;
    }
retry:
    switch (type) {
    case shFeature::kSewagePit:
        if (kSewage != getSquare (x, y) ->mTerr) {
            type = shFeature::kPit;
        }
        break;
    case shFeature::kPit:
    case shFeature::kAcidPit:
        switch (getSquare (x, y) ->mTerr) {
        case kSewage:
            type = shFeature::kSewagePit;
            break;
        default:
            break;
        }
        break;
    case shFeature::kHole:
    case shFeature::kTrapDoor:
        if (noDig () or isBottomLevel ()) {
            type = shFeature::kPit;
            goto retry;
        } else {
            trap->mDest.mLevel = 0;
            trap->mDest.mX = -1;
            trap->mDest.mY = -1;
        }
        break;
    default:
        break;
    }
    trap->mType = type;
    mFeatures.add (trap);
    return trap;
}
// ===========================================================================
void Galeri::grid::Generator::
getSquareWithQuads(Epetra_Comm& comm, 
                   const int numGlobalElementsX, const int numGlobalElementsY,
                   const int numDomainsX, const int numDomainsY,
                   Galeri::grid::Loadable& domain, Galeri::grid::Loadable& boundary)
{
  getSquare(comm, numGlobalElementsX, numGlobalElementsY,
            numDomainsX, numDomainsY, domain, boundary, "Quad");
}
//Produce a sun at a position
void Gameboard::produceSun(Position position) {
    //create a sun
    Sun sun;
    //get the square thanks to the position
    BoardSquare square = getSquare(position);
    //set the position to 30 in front of the center of the square
    sun.setPosition(Position((square.getX()+0.5)*BoardSquare::size, 0, (square.getZ()+0.5)*BoardSquare::size+30));
    //add it !
    sunList.push_back(sun);
}
Beispiel #15
0
void Level::replaceSquare(Vec2 pos, PSquare square) {
  if (contains(tickingSquares, getSquare(pos)))
    removeElement(tickingSquares, getSquare(pos));
  Creature* c = squares[pos]->getCreature();
  for (Item* it : squares[pos]->getItems())
    square->dropItem(squares[pos]->removeItem(it));
  squares[pos]->onConstructNewSquare(square.get());
  addLightSource(pos, squares[pos]->getLightEmission(), -1);
  square->setCovered(squares[pos]->isCovered());
  square->addLight(squares[pos]->getTotalLight());
  square->setBackground(squares[pos].get());
  squares[pos] = std::move(square);
  squares[pos]->setPosition(pos);
  squares[pos]->setLevel(this);
  if (c) {
    squares[pos]->putCreatureSilently(c);
  }
  addLightSource(pos, squares[pos]->getLightEmission(), 1);
  updateVisibility(pos);
}
Beispiel #16
0
int main(void){

  setDistance();
  getSquare();
  

  while(1){

  }
  return 0;
}
Beispiel #17
0
Square* ChessBoard::findKing( PieceColor color ) {

  for( int i = 0; i < BOARD_WIDTH_HEIGHT; ++i ) {
    for( int j = 0; j < BOARD_WIDTH_HEIGHT; ++j ) {
      Piece* p = getPiece(i,j);
      if( p != NULL ) {
	if( p->type == KING && p->color == color) return getSquare(i,j);
      }
    }
  }
  return NULL;
}
Beispiel #18
0
void Level::throwItem(vector<PItem> item, const Attack& attack, int maxDist, Vec2 position, Vec2 direction,
    VisionInfo visionInfo) {
  CHECK(!item.empty());
  int cnt = 1;
  vector<Vec2> trajectory;
  for (Vec2 v = position + direction;; v += direction) {
    trajectory.push_back(v);
    if (getSquare(v)->itemBounces(item[0].get(), visionInfo)) {
        item[0]->onHitSquareMessage(v, getSquare(v), item.size() > 1);
        trajectory.pop_back();
        EventListener::addThrowEvent(this, attack.getAttacker(), item[0].get(), trajectory);
        if (!item[0]->isDiscarded())
          getSquare(v - direction)->dropItems(std::move(item));
        return;
    }
    if (++cnt > maxDist || getSquare(v)->itemLands(extractRefs(item), attack)) {
      EventListener::addThrowEvent(this, attack.getAttacker(), item[0].get(), trajectory);
      getSquare(v)->onItemLands(std::move(item), attack, maxDist - cnt - 1, direction, visionInfo);
      return;
    }
  }
}
Beispiel #19
0
std::vector<cv::Rect> getIdSquares(int markerSizePx) {
    int allFields = Marker::NUM_SQUARES * Marker::NUM_SQUARES;
    std::vector<cv::Rect> result;

    for (int squareId = 1; squareId < allFields-1; squareId++) {
        if (squareId == getCornerSquareId(UPPER_RIGHT) ||
            squareId == getCornerSquareId(LOWER_LEFT)) continue;

        result.push_back(getSquare(markerSizePx, squareId));
    }

    return result;
}
Beispiel #20
0
void moveCell(Grid* W,Cell* moveMe, double* newLoc){/*Cells moved by summing move ability vectors and bumping into other cells (cellBump)*/
  if(insideWorld(newLoc,0)){
  Square* currSq=getSquare(W,moveMe->CellPos);
  Square* nextSq=getSquare(W,newLoc);
  if(!nextSq){
    fprintf(stderr,"cell detected it has moved off the world, this should never happen, the body should catch this first!");

    //fprintf(stderr,"cell trying to move outside of world");
  }
  //addColor(W,moveMe->color,0,.7,0,MOVEMENT);
  if(currSq!=nextSq){
      remLL(&currSq->cells,&moveMe->mySqElem);
      addLL(&nextSq->cells,&moveMe->mySqElem);
  }
  /* cells lose energy based on how far they have moved */
  double moveCost=pow(getDist(moveMe->CellPos,newLoc)/CELLRAD,MOVE_EXP)*MOVE_COST_MULT;
  EnTransfer(&W->SUN,&moveMe->myBody->energy,moveCost*((1-MOVE_COST_DROP_PROP)+(MOVE_COST_DROP_PROP*(1.0/moveMe->myBody->cellSize))));//getTerrain(W,moveMe->CellPos)->moveCost);///log(moveMe->myBody->cellSize+2));//,__func__,__LINE__);
  //EnTransfer(&W->SUN,&moveMe->myBody->energy,pow(getDist(moveMe->CellPos,newLoc)/CELLRAD,MOVE_EXP)*getTerrain(W,moveMe->CellPos)->moveCost/moveMe->myBody->cellSize);//,__func__,__LINE__);
  moveMe->CellPos[0]=newLoc[0];
  moveMe->CellPos[1]=newLoc[1];
  }
  moveMe->CellPos[2]=wrapAngle(newLoc[2]);
  calcBehindPoint(moveMe->behindPoint,moveMe->CellPos);
};
Beispiel #21
0
static int setPieces(const char *fen, Position * position)
{
   Square square;
   Rank rank = RANK_8;
   File file = FILE_A;
   Piece p;
   int index = 0;
   int imax = (int) (strlen(fen)) - 1;
   char current = '\0';

   ITERATE(square)
   {
      position->piece[square] = NO_PIECE;
   }

   while (index <= imax && (current = fen[index]) != ' ')
   {
      if (current == '/')
      {
         rank--;
         file = FILE_A;
      }
      else if (current >= '1' && current <= '8')
      {
         file = (File) (file + current - '0');
      }
      else
      {
         p = pieceCode[(int) current];

         if (p != NO_PIECE)
         {
            position->piece[getSquare(file, rank)] = p;
            file++;
         }
         else
         {
            return -1;
         }
      }

      index++;
   }

   return rank == RANK_1 ? index : -1;
}
Beispiel #22
0
//flood fills some muck starting at x,y
int
shMapLevel::floodMuck (int sx, int sy, shTerrainType type, int amount)
{
    int x, y, i;
    shDirection dirs[4] = { kNorth, kSouth, kEast, kWest };
    shDirection dir;
    int n = 0;
    shVector <int> points;

    points.add (xytop (sx, sy));

    for (n = 0; n < amount;) {
        int p;
        if (0 == points.count ()) {
            return n;
        }
        p = points.removeByIndex (RNG (points.count ()));
        x = ptox (p);
        y = ptoy (p);

        if (!isFloor (x, y) or kSewage == getSquare (x, y) ->mTerr) {
            continue;
        }
        n++;

        if (RNG(2))
            SETSQ (x, y, kSewage);

        for (i = 0; i < 4; i++) {
            dir = dirs[i];
            int x2 = x;
            int y2 = y;


            if (moveForward (dir, &x2, &y2) and
                RNG (20) >= points.count ())
            {
                points.add (xytop (x2, y2));
            }
        }
    }
    return n;
}
//**********************************************************************
//
//
//**********************************************************************
BOOST_FIXTURE_TEST_CASE( Biomass_Derived_Quantity, C1x1_Fixture ) {

  // Add What we need to configuration
  // Then run our model
  addToConfiguration(ageing);
  addToConfiguration(age_size_vonB);
  addToConfiguration(size_weight_none);
  addToConfiguration(constant_recruitment);
  addToConfiguration(derived_quantity);
  addToConfiguration(constant);
  addToConfiguration(numeric);
  addToTimeStep("ageing constant_recruitment");
  loadAndRunEnvironment();

  // Check our Results
  CDerivedQuantityManager *pManager     = CDerivedQuantityManager::Instance();
  CDerivedQuantity        *pQuantity    = pManager->getDerivedQuantity("derived_quantity");
  CWorldSquare            *pSquare      = getSquare();

  // Check Results
  BOOST_CHECK_EQUAL(15, pQuantity->getValuesSize());
  BOOST_CHECK_EQUAL(pSquare->getAbundance() * 2, pQuantity->getValue(0));
  BOOST_CHECK_EQUAL(pQuantity->getValue(1), 2800.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(2), 2600.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(3), 2400.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(4), 2200.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(5), 2000.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(6), 1800.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(7), 1600.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(8), 1400.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(9), 1200.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(10), 1000.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(11), 800.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(12), 600.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(13), 400.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(14), 200.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(15), 0.0);
  BOOST_CHECK_EQUAL(pQuantity->getValue(16), 0.0); // Too Large, should return 0.0
  BOOST_CHECK_EQUAL(pQuantity->getValue(17), 0.0); // ""
}
//**********************************************************************
//
//
//**********************************************************************
BOOST_FIXTURE_TEST_CASE( AdjacentCellMovementProcess, C3x3_Fixture ) {

  // Add What we need to configuration
  // Then run our model
  addToConfiguration(ageing);
  addToConfiguration(age_size_vonB);
  addToConfiguration(size_weight_none);
  addToConfiguration(constant);
  addToConfiguration(constant_recruitment);
  addToConfiguration(adjacent_cell_movement);
  addToTimeStep("ageing constant_recruitment adjacent_cell");
  BOOST_REQUIRE_NO_THROW(loadAndRunEnvironment());

  // Check our Results
  double immature[] = { 11.110772026909721,159.72208987616949,151.97735027125543,159.72208987616943,292.84392851560114,215.27791012383045,151.97735027125543,215.27791012383045,142.0905989149781 };

  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      CWorldSquare *pSquare = getSquare(i,j);
      BOOST_CHECK_CLOSE(pSquare->getAbundance(), immature[3*i+j], 1e-9);
    }
  }
}
Beispiel #25
0
void initCell(Grid* W,Cell* ret,Brain* parent,Brain* childBrain,double* pos, Body* parentBody, int BodyCellI,int keepBonds,Body* myParent,Ecosystem* data,int* Is){/*if cell has a parent brain, then abilities are copied, otherwise brain is initialized randomly*/
  ret->alive=1;
  ret->myBrain=childBrain;
  ret->myBody=parentBody;
  ret->myParent=myParent;
  ret->BodyCellI=BodyCellI;
  ret->BondedCells=NULL;
  ret->numBonds=0;
  if(data){
    setupCellFromData(data,ret,Is,parentBody);//setup bonds, cellpos and brain from data
    setupBrainFromData(data,childBrain,ret,Is);}//init brain from data
  else{
  if(parent){
    initBrain(W,childBrain,parent,ret,NULL,NULL);
    Cell* parentCell=parent->myCell;
    if(keepBonds){
      for(LL* ParentBondedIs=parentCell->BondedCells;ParentBondedIs;ParentBondedIs=ParentBondedIs->next){
        LL* newBondILL=malloc(sizeof(LL));
        initLL(newBondILL,parentBody->cells[((Cell*)ParentBondedIs->val)->BodyCellI]);
        addLL(&ret->BondedCells,newBondILL);}
      ret->numBonds=parentCell->numBonds;}}
  else{initBrain(W,childBrain,NULL,ret,NULL,NULL);}
  ret->CellPos[0]=pos[0];
  ret->CellPos[1]=pos[1];
  ret->CellPos[2]=pos[2];
  }
  calcBehindPoint(ret->behindPoint,ret->CellPos);
  ret->rotAmount=0;
  ret->color[0]=0.2;
  ret->color[1]=0.2;
  ret->color[2]=0.2;
  ret->color[3]=1;
  ret->livingCost=calcLivingCost(childBrain);
  initLL(&ret->mySqElem,ret);
  Square* birthPlace=getSquare(W,ret->CellPos);
  if(!birthPlace){fprintf(stderr,"%lf, %lf attempting to place a Cell outside the world!",ret->CellPos[0],ret->CellPos[1]);}
  addLL(&birthPlace->cells,&ret->mySqElem);};
Beispiel #26
0
cv::Rect getSquare(int markerSizePx, MarkerCorner corner) {
    int squareId = getCornerSquareId(corner);
    return getSquare(markerSizePx, squareId);
}
Beispiel #27
0
int readFen(const char *fen, Position * position)
{
   int index;

   /*
    * Initialize this module.
    */
   initialize();

   /*
    * Get the piece positions.
    */
   if ((index = setPieces(fen, position)) < 0)
   {
      return -1;
   }

   /*
    * Get the active color.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   if (stringContainsChar("bw", fen[index]))
   {
      position->activeColor = (fen[index] == 'w' ? WHITE : BLACK);
      index++;
   }
   else
   {
      return -1;                /* fen format error */
   }

   /*
    * Get the castling rights.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   position->castlingRights = NO_CASTLINGS;

   while (fen[index] != ' ')
   {
      switch (fen[index++])
      {
      case 'K':
         position->castlingRights += WHITE_00;
         break;
      case 'Q':
         position->castlingRights += WHITE_000;
         break;
      case 'k':
         position->castlingRights += BLACK_00;
         break;
      case 'q':
         position->castlingRights += BLACK_000;
         break;
      case '-':
         position->castlingRights = NO_CASTLINGS;
         break;
      default:
         return -1;             /* fen format error */
      }
   }

   /*
    * Get the en passant square.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   if (fen[index] == '-')
   {
      position->enPassantSquare = NO_SQUARE;
      index++;
   }
   else if (fen[index] >= 'a' && fen[index] <= 'h' &&
            (fen[index + 1] == '3' || fen[index + 1] == '6'))
   {
      File file = (File) (fen[index++] - 'a');
      Rank rank = (Rank) (fen[index++] - '1');

      position->enPassantSquare = getSquare(file, rank);
   }
   else
   {
      return -1;                /* fen format error */
   }

   /*
    * Get the half move clock value.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   position->halfMoveClock = atoi(fen + index);

   /*
    * Get the move number value.
    */
   while (fen[index] != ' ')
   {
      if (!isdigit((int) fen[index]))
      {
         return -1;             /* fen format error */
      }

      index++;
   }

   while (fen[index] == ' ')
   {
      index++;
   }

   position->moveNumber = atoi(fen + index);

   return 0;
}
Beispiel #28
0
void getFen(const Position * position, char *fen)
{
   int rank, file;
   char buffer[16];

   /*
    * Initialize this module.
    */
   initialize();

   for (rank = RANK_8; rank >= RANK_1; rank--)
   {
      int emptyCount = 0;

      for (file = FILE_A; file <= FILE_H; file++)
      {
         Square square = getSquare(file, rank);

         if (position->piece[square] != NO_PIECE)
         {
            if (emptyCount > 0)
            {
               *fen++ = ((char) ('0' + emptyCount));
               emptyCount = 0;
            }

            *fen++ = pieceToken[position->piece[square]];
         }
         else
         {
            emptyCount++;
         }
      }

      if (emptyCount > 0)
      {
         *fen++ = ((char) ('0' + emptyCount));
      }

      if (rank > RANK_1)
      {
         *fen++ = '/';
      }
   }

   *fen++ = ' ';
   *fen++ = (position->activeColor == WHITE ? 'w' : 'b');
   *fen++ = ' ';

   if (position->castlingRights)
   {
      if (position->castlingRights & WHITE_00)
      {
         *fen++ = 'K';
      }

      if (position->castlingRights & WHITE_000)
      {
         *fen++ = 'Q';
      }

      if (position->castlingRights & BLACK_00)
      {
         *fen++ = 'k';
      }

      if (position->castlingRights & BLACK_000)
      {
         *fen++ = 'q';
      }
   }
   else
   {
      *fen++ = '-';
   }

   *fen++ = ' ';

   if (position->enPassantSquare != NO_SQUARE)
   {
      char file = (char) (file(position->enPassantSquare) + 'a');
      char rank = (char) (rank(position->enPassantSquare) + '1');

      *fen++ = file;
      *fen++ = rank;
   }
   else
   {
      *fen++ = '-';
   }

   *fen = '\0';
   sprintf(buffer, " %i %i", position->halfMoveClock, position->moveNumber);
   strcat(fen, buffer);
}
Beispiel #29
0
	Square* Board::getSquare(const Coordinates& coordinates) const
	{
		return getSquare(coordinates.getX(), coordinates.getY());
	}
Beispiel #30
0
bool Level::isWithinVision(Vec2 from, Vec2 to) const {
  return from.distD(to) <= darkViewRadius || getSquare(to)->getLight() > 0.3;
}