// merge in sens invers al parcurgerii miscarilor si calculeaza // un punctaj pentru fiecare mutare // citez : "Drumurile noastre poate... Se vor intalni vreodata" int getPoints(board someBoard, vector<int> mutari, int playerNo) { int punctajFinal = 0; int posX = someBoard.getPlayerPositionX(playerNo); int posY = someBoard.getPlayerPositionY(playerNo); position posXY = someBoard.getPlayerPosition(playerNo); int mutariPosibile = someBoard.getPossibleMoves(posXY); int punctajTemp = awardPoints(mutariPosibile); punctajFinal += punctajTemp; for (int i = mutari.size() - 1; i >= 0; i--) { switch (mutari[i]) { case (UP) : posX ++; mutariPosibile = someBoard.getPossibleMoves(posX,posY); punctajTemp = awardPoints(mutariPosibile); punctajFinal += punctajTemp; break; case (DOWN) : posX --; mutariPosibile = someBoard.getPossibleMoves(posX,posY); punctajTemp = awardPoints(mutariPosibile); punctajFinal += punctajTemp; break; case (LEFT) : posY ++; mutariPosibile = someBoard.getPossibleMoves(posX,posY); punctajTemp = awardPoints(mutariPosibile); punctajFinal += punctajTemp; break; case (RIGHT) : posY --; mutariPosibile = someBoard.getPossibleMoves(posX,posY); punctajTemp = awardPoints(mutariPosibile); punctajFinal += punctajTemp; break; } } return punctajFinal; }
// 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; } }