Board representation

Board representation (see board.h) is the main pillar of the whole program. Several crucial classes are defined here, for instance: Class Board handles various tasks connected to the board abstraction, most important are: Board::genStepsOne wrapper
  //Board::genStepsOne
  ...
  if (bits::getBit(calcMovable(player), coord)){
    u64 victims[7];  
    //calculates weaker (opponent's) bitboards for all piece types for given player
    calcWeaker(player, victims);

    assert(getPlayer(coord) == player); 
    piece_t piece = getPiece(coord, player);
    //generate steps for given piece and store them in steps, victims for actual piece are passed ...
    genStepsOneTuned(coord, player, piece, steps, stepsNum, victims[piece]);
    return;
  }
  ...
  //end Board::genStepsOne
}

single steps generation in Board::genStepsOneTuned

  ... 
  //Board::genStepsOneTuned
  //piece at from must not be frozen (ensured in wrappers)
  //in victims there are already all weaker pieces than given piece (ensured in wrappers)

  u64 empty = ~(bitboard_[0][0] | bitboard_[1][0]);
  u64 whereStep = empty & bits::stepOffset_[player][piece][from];
    
  //single steps
  for (int i = 0; i < 4; i++) {
    coord_t to = from + bdirection[i];
    if (whereStep & BIT_ON(to)) {
      //destination is empty  -> add step
      steps[stepsNum++].setValues(STEP_SINGLE, player, piece, from, to);
    }
  }
  
  //finish if push/pulls are not possible
  if ( piece == RABBIT || stepCount_ >= 3 || 
       ! (bits::stepOffset_[player][piece][from] & bitboard_[OPP(player)][0])) { 
    return;
  }

push/pulls generation

  ...
  //collect potential victims (weaker & neighbours)
  victims &= bits::stepOffset_[player][piece][from];
   
  //cycle through neighbors and perform push/pull if there is a victim 
  //and there is where to push/pull
  for (int i = 0; i < 4; i++) {
    coord_t victimFrom = from + bdirection[i];
    if (! (victims & BIT_ON(victimFrom))) {
      continue;
    }

    //pull
    u64 wherePull = empty & bits::stepOffset_[player][piece][from];          
    for (int j = 0; j < 4; j++) {
      coord_t pullerTo = from + bdirection[j];
      if (! (wherePull & BIT_ON(pullerTo))) {
        continue;
      }

      steps[stepsNum++].setValues(STEP_PULL, player, piece, from, pullerTo, 
                            getPiece(victimFrom, OPP(player)), victimFrom, from); 
    }

    //push
    u64 wherePush = empty & bits::stepOffset_[player][piece][victimFrom]; 
    for (int k = 0; k < 4; k++) {
      coord_t victimTo = victimFrom + bdirection[k];
      if (! (wherePush & BIT_ON(victimTo))) {
        continue;
      }

      steps[stepsNum++].setValues(STEP_PUSH, player, piece, from, victimFrom,
                        getPiece(victimFrom, OPP(player)), victimFrom, victimTo);
    }
  } 
  ...
  //end Board::genStepsOneTuned

All steps might be generated via Board::genSteps, which basically cycles through all pieces belonging to given player and gathers their steps via Board::genStepsOneTuned.

    //Board::makeStep
    ... 
    //handle push/pull steps
    if (step.isPushPull()) {  
      //delSquare/setSquare automatically update position signature
      delSquare(step.oppFrom_, OPP(step.player_), step.oppPiece_);
      setSquare(step.oppTo_, OPP(step.player_), step.oppPiece_);
      stepCount_++;
    }

    //handle single step
    delSquare(step.from_, step.player_, step.piece_);
    setSquare(step.to_, step.player_, step.piece_);
    stepCount_++;
    ...
    //handle deaths in traps
    for (int player = 0; player < 2; player++){
      fullTraps = (TRAPS & bitboard_[player][0]);
      //fullTraps without support
      dieHard = fullTraps ^ (fullTraps & bits::neighbors(bitboard_[player][0]));

      if (dieHard){
        int trap = bits::lix(dieHard);             
        if ( trap != BIT_EMPTY){
          delSquare(trap, player);
          //no more than one dead per player
          assert(bits::lix(dieHard) == BIT_EMPTY); 
        }
      }
    } 
    ...
    //end Board::makeStep


Generated on Thu Aug 6 23:29:07 2009 for akimot by  doxygen 1.5.7.1