예제 #1
0
 // aplica un backtracking amarat pe fiecare dintre cele 4 directii cardinale
 // (la rascruce de vanturi) si calculeaza in momentul in care ajunge la adancimea 
 // maxima (fundul putului) calculeaza un punctaj pentru fiecare mutare
 // din pacate drumul inapoi nu are gropi k ar mai fi taiat din punctaj 
 int getMovePoints(board previousBoard, int currentDepth, vector<int> mutari) {
   position posXYEnemy = previousBoard.getPlayerPosition(2); 
   position posXYMyPlayer = previousBoard.getPlayerPosition(1); 
   if (currentDepth >= maxDepth_ || 
       previousBoard.getPossibleMoves(posXYEnemy) == 0 ||
       previousBoard.getPossibleMoves(posXYMyPlayer) == 0 
       ) {
     return getPoints(previousBoard, mutari, 1 /*Player1*/);    
   } else {
     int maxProfit = 0; 
     for (int i = 0; i < 4; i++) {
       int eachProfit = 0; 
       board tempBoard = previousBoard.copyBoard(); 
       position myPosition = tempBoard.getPlayerPosition(1);
       if (tempBoard.isEmpty(i, myPosition)) {
         tempBoard.doMove(i,1);
         mutari.push_back(i);
         eachProfit = getMovePoints(tempBoard, currentDepth + 1, mutari);
         if (eachProfit > maxProfit) {
           maxProfit = eachProfit;     
         }
         mutari.pop_back(); 
       }
     }
     return maxProfit;
   }
 }
예제 #2
0
    int nextMove(board currentBoard) {
      int punctajBun  = 0;
      int punctajTemp = 0;
      int mutareBuna  = 4; //PlayDead

      for (int i = 0; i < 4; i++) {
        board tempBoard = currentBoard.copyBoard();
        position currentPosition = tempBoard.getPlayerPosition(1);
        if (tempBoard.isEmpty(i,currentPosition)) {
          tempBoard.doMove(i, 1);
          punctajTemp = getMovePoints(tempBoard, 0, mutari_);
          if (punctajTemp > punctajBun) {
            punctajBun = punctajTemp;
            mutareBuna = i;
          } 
        }
      }

      return mutareBuna;
    }