From ce1e701a1762e7010508c5f03226deba5afa251b Mon Sep 17 00:00:00 2001 From: pierretienne Date: Sat, 6 Dec 2014 22:16:17 +0100 Subject: [PATCH] mise en prod version test retreat --- src/IA_Exemple__4393.lks | 71 ++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/src/IA_Exemple__4393.lks b/src/IA_Exemple__4393.lks index ac0d471..0af41d7 100644 --- a/src/IA_Exemple__4393.lks +++ b/src/IA_Exemple__4393.lks @@ -478,6 +478,8 @@ debug("<<< moveAfter()"); +global COEF_ESTIMATD_COMPLEXITY_G = 8; +global MIN_SECURITY_INSTRUCTION_G = 25000; function retreat(){ //choper les couples item,enemy les plus dangereux var itemEnemyDangerIt_l = 0; @@ -485,7 +487,6 @@ function retreat(){ var itemEnemyDanger_l = []; for(var enemy_l in ENEMIES_G){ if(isAlive(enemy_l)){ - debug("getItemsAttack(enemy_l) = " + getItemsAttack(enemy_l)); for(var item_l : var average_l in getItemsAttack(enemy_l)){ if(canShootBasic(enemy_l, item_l)){ var probaCooldownOK_l = 1; @@ -505,46 +506,32 @@ function retreat(){ } } assocSort(scoreTable_l, SORT_DESC); - debug(scoreTable_l); - debug(itemEnemyDanger_l); updateReachableCells(); var retreatCells_l = []; for(var cellIt_l : var pathIt_l in REACHABLE_CELLS_G){ - retreatCells_l[cellIt_l] = 0; + retreatCells_l[cellIt_l] = 1; } var previousEnemy_l = -1; for(itemEnemyDangerIt_l : var score_l in scoreTable_l) { - var countInstruction_l = getInstructionsCount(); - var nbCellAccessibleEnemy_l = count(getReachableCellCloseToMe(getCell(itemEnemyDanger_l[itemEnemyDangerIt_l][1]), LEEKS_VARIABLE_CARAC_G[itemEnemyDanger_l[itemEnemyDangerIt_l][1]][TURN_G][CARAC_MP])); - var securityInstructions_l = 25000; - if(nbCellAccessibleEnemy_l * count(retreatCells_l) * 8 > securityInstructions_l){ - securityInstructions_l = nbCellAccessibleEnemy_l * count(retreatCells_l) * 8; + var nbInstructionBeginItemScore_l = getInstructionsCount(); + var item_l = itemEnemyDanger_l[itemEnemyDangerIt_l][0]; + var enemy_l = itemEnemyDanger_l[itemEnemyDangerIt_l][1]; + var cellsReachablebleEnemy_l = getReachableCellCloseToMe(LEEK_MOVEMENTS_G[enemy_l][TURN_G], LEEKS_VARIABLE_CARAC_G[enemy_l][TURN_G][CARAC_MP]); + var estimatedComplexity_l = count(cellsReachablebleEnemy_l) * count(retreatCells_l) * COEF_ESTIMATD_COMPLEXITY_G; + var securityInstructions_l = MIN_SECURITY_INSTRUCTION_G; + if(estimatedComplexity_l > securityInstructions_l){ + securityInstructions_l = estimatedComplexity_l; } if(INSTRUCTIONS_LIMIT - getInstructionsCount() < securityInstructions_l){ break; } - debug("retreat from : " + getItemName(itemEnemyDanger_l[itemEnemyDangerIt_l][0]) + " by " + getLeekID(itemEnemyDanger_l[itemEnemyDangerIt_l][1]) + " danger = " + score_l); - //on range en fonction de la distance a l'enemy - if(previousEnemy_l != itemEnemyDanger_l[itemEnemyDangerIt_l][1] && LEVEL_G >= 5){ - previousEnemy_l = itemEnemyDanger_l[itemEnemyDangerIt_l][1]; - for(var cellIt_l : var distanceEnemy_l in retreatCells_l){ - retreatCells_l[cellIt_l] = getCellDistance(cellIt_l, getCell(previousEnemy_l)); - } - assocSort(retreatCells_l, SORT_ASC); - } var currentRetreatCells = retreatCells_l; //on elimine les cellules dangereuse for(var reachableCellMe_l : var pathMe_l in retreatCells_l){ - var isAttackable_l = false; - //debug("reachableCellMe_l = " + reachableCellMe_l); - for(var reachableCellEnemy_l : var pathEnemy_l in getReachableCellCloseToMe(getCell(itemEnemyDanger_l[itemEnemyDangerIt_l][1]), LEEKS_VARIABLE_CARAC_G[itemEnemyDanger_l[itemEnemyDangerIt_l][1]][TURN_G][CARAC_MP])){ - //debug("reachableCellEnemy_l = " + reachableCellEnemy_l); - if(canShootCellToCell(reachableCellEnemy_l, itemEnemyDanger_l[itemEnemyDangerIt_l][1], itemEnemyDanger_l[itemEnemyDangerIt_l][0], reachableCellMe_l, ME_G)){ + for(var reachableCellEnemy_l : var pathEnemy_l in cellsReachablebleEnemy_l){ + if(canShootCellToCell(reachableCellEnemy_l, enemy_l, item_l, reachableCellMe_l, ME_G)){ removeKey(currentRetreatCells, reachableCellMe_l); - isAttackable_l = true; - //debug("reachableCellEnemy_l = " + reachableCellEnemy_l); - //debug("isAttackable"); break; } } @@ -553,34 +540,40 @@ function retreat(){ retreatCells_l = currentRetreatCells; } - debug("cout instructions = " + (getInstructionsCount() - countInstruction_l)); - debug("proportion = " + (getInstructionsCount() - countInstruction_l) / nbCellAccessibleEnemy_l / count(retreatCells_l)); - //debug("retreatCells_l = " + retreatCells_l); + var nbInstructions_l = getInstructionsCount() - nbInstructionBeginItemScore_l; + var estimationQuality_l = nbInstructions_l / estimatedComplexity_l; + if(nbInstructions_l > MIN_SECURITY_INSTRUCTION_G && estimationQuality_l > 1){ + COEF_ESTIMATD_COMPLEXITY_G *= estimationQuality_l; + debugE("nbInstructions_l = " + nbInstructions_l + " and estimationQuality_l = " + estimationQuality_l + ". New COEF_ESTIMATD_COMPLEXITY_G = " + COEF_ESTIMATD_COMPLEXITY_G); + }else if(nbInstructions_l > 0.5 * MIN_SECURITY_INSTRUCTION_G && estimationQuality_l < 0.7){ + debugW("nbInstructions_l = " + nbInstructions_l + " and estimationQuality_l = " + estimationQuality_l + ". New COEF_ESTIMATD_COMPLEXITY_G = " + COEF_ESTIMATD_COMPLEXITY_G); + }else{ + debug("nbInstructions_l = " + nbInstructions_l + " and estimationQuality_l = " + estimationQuality_l); + } } - var distanceWeakest_l = 10000; var distanceCenter_l = 10000; - var cell_l = 306; + var targetCell_l = 306; + var weakestCell_l = LEEK_MOVEMENTS_G[WEAKEST_ENEMY_G][TURN_G]; for(var cellIt_l : var distanceEnemyIt_l in retreatCells_l){ var distanceEnemy_l = 0; - if(getName(WEAKEST_ENEMY_G) !== null){ - distanceEnemy_l = getCellDistance(cellIt_l, LEEK_MOVEMENTS_G[WEAKEST_ENEMY_G][TURN_G]); + if(weakestCell_l !== null){ + distanceEnemy_l = getCellDistance(cellIt_l, weakestCell_l); } if(LEVEL_G > 5 && ((distanceEnemy_l < distanceWeakest_l) - ||(distanceEnemy_l < distanceWeakest_l && getCellDistance(cellIt_l, 306) < distanceCenter_l))){ + ||(distanceEnemy_l == distanceWeakest_l && getCellDistance(cellIt_l, 306) < distanceCenter_l))){ distanceWeakest_l = distanceEnemy_l; distanceCenter_l = getCellDistance(cellIt_l, 306); - cell_l = cellIt_l; - debug("goto cell " + cellIt_l); + targetCell_l = cellIt_l; } } - for(var pathCell_l in REACHABLE_CELLS_G[cell_l][0]){ + for(var pathCell_l in REACHABLE_CELLS_G[targetCell_l][0]){ moveToCell(pathCell_l, 1); } - if(cell_l !== getCell()){ - moveToCell(cell_l, 1); + if(targetCell_l !== getCell()){ + moveToCell(targetCell_l, 1); } } -- 2.11.4.GIT