Blast06

Javascript Reach binary

Jun 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Descendez tooouuut en bas...
  2. global moyenne = 0;
  3. global obstacles = getObstacles(),
  4.     _line = [0:-17,1:-17,2:-17,3:-17,4:-17,5:-17,6:-17,7:-17,8:-17,9:-17,10:-17,11:-17,12:-17,13:-17,14:-17,15:-17,16:-17,17:-17,18:-16,19:-16,20:-16,21:-16,22:-16,23:-16,24:-16,25:-16,26:-16,27:-16,28:-16,29:-16,30:-16,31:-16,32:-16,33:-16,34:-16,35:-15,36:-15,37:-15,38:-15,39:-15,40:-15,41:-15,42:-15,43:-15,44:-15,45:-15,46:-15,47:-15,48:-15,49:-15,50:-15,51:-15,52:-15,53:-14,54:-14,55:-14,56:-14,57:-14,58:-14,59:-14,60:-14,61:-14,62:-14,63:-14,64:-14,65:-14,66:-14,67:-14,68:-14,69:-14,70:-13,71:-13,72:-13,73:-13,74:-13,75:-13,76:-13,77:-13,78:-13,79:-13,80:-13,81:-13,82:-13,83:-13,84:-13,85:-13,86:-13,87:-13,88:-12,89:-12,90:-12,91:-12,92:-12,93:-12,94:-12,95:-12,96:-12,97:-12,98:-12,99:-12,100:-12,101:-12,102:-12,103:-12,104:-12,105:-11,106:-11,107:-11,108:-11,109:-11,110:-11,111:-11,112:-11,113:-11,114:-11,115:-11,116:-11,117:-11,118:-11,119:-11,120:-11,121:-11,122:-11,123:-10,124:-10,125:-10,126:-10,127:-10,128:-10,129:-10,130:-10,131:-10,132:-10,133:-10,134:-10,135:-10,136:-10,137:-10,138:-10,139:-10,140:-9,141:-9,142:-9,143:-9,144:-9,145:-9,146:-9,147:-9,148:-9,149:-9,150:-9,151:-9,152:-9,153:-9,154:-9,155:-9,156:-9,157:-9,158:-8,159:-8,160:-8,161:-8,162:-8,163:-8,164:-8,165:-8,166:-8,167:-8,168:-8,169:-8,170:-8,171:-8,172:-8,173:-8,174:-8,175:-7,176:-7,177:-7,178:-7,179:-7,180:-7,181:-7,182:-7,183:-7,184:-7,185:-7,186:-7,187:-7,188:-7,189:-7,190:-7,191:-7,192:-7,193:-6,194:-6,195:-6,196:-6,197:-6,198:-6,199:-6,200:-6,201:-6,202:-6,203:-6,204:-6,205:-6,206:-6,207:-6,208:-6,209:-6,210:-5,211:-5,212:-5,213:-5,214:-5,215:-5,216:-5,217:-5,218:-5,219:-5,220:-5,221:-5,222:-5,223:-5,224:-5,225:-5,226:-5,227:-5,228:-4,229:-4,230:-4,231:-4,232:-4,233:-4,234:-4,235:-4,236:-4,237:-4,238:-4,239:-4,240:-4,241:-4,242:-4,243:-4,244:-4,245:-3,246:-3,247:-3,248:-3,249:-3,250:-3,251:-3,252:-3,253:-3,254:-3,255:-3,256:-3,257:-3,258:-3,259:-3,260:-3,261:-3,262:-3,263:-2,264:-2,265:-2,266:-2,267:-2,268:-2,269:-2,270:-2,271:-2,272:-2,273:-2,274:-2,275:-2,276:-2,277:-2,278:-2,279:-2,280:-1,281:-1,282:-1,283:-1,284:-1,285:-1,286:-1,287:-1,288:-1,289:-1,290:-1,291:-1,292:-1,293:-1,294:-1,295:-1,296:-1,297:-1,298:0,299:0,300:0,301:0,302:0,303:0,304:0,305:0,306:0,307:0,308:0,309:0,310:0,311:0,312:0,313:0,314:0,315:1,316:1,317:1,318:1,319:1,320:1,321:1,322:1,323:1,324:1,325:1,326:1,327:1,328:1,329:1,330:1,331:1,332:1,333:2,334:2,335:2,336:2,337:2,338:2,339:2,340:2,341:2,342:2,343:2,344:2,345:2,346:2,347:2,348:2,349:2,350:3,351:3,352:3,353:3,354:3,355:3,356:3,357:3,358:3,359:3,360:3,361:3,362:3,363:3,364:3,365:3,366:3,367:3,368:4,369:4,370:4,371:4,372:4,373:4,374:4,375:4,376:4,377:4,378:4,379:4,380:4,381:4,382:4,383:4,384:4,385:5,386:5,387:5,388:5,389:5,390:5,391:5,392:5,393:5,394:5,395:5,396:5,397:5,398:5,399:5,400:5,401:5,402:5,403:6,404:6,405:6,406:6,407:6,408:6,409:6,410:6,411:6,412:6,413:6,414:6,415:6,416:6,417:6,418:6,419:6,420:7,421:7,422:7,423:7,424:7,425:7,426:7,427:7,428:7,429:7,430:7,431:7,432:7,433:7,434:7,435:7,436:7,437:7,438:8,439:8,440:8,441:8,442:8,443:8,444:8,445:8,446:8,447:8,448:8,449:8,450:8,451:8,452:8,453:8,454:8,455:9,456:9,457:9,458:9,459:9,460:9,461:9,462:9,463:9,464:9,465:9,466:9,467:9,468:9,469:9,470:9,471:9,472:9,473:10,474:10,475:10,476:10,477:10,478:10,479:10,480:10,481:10,482:10,483:10,484:10,485:10,486:10,487:10,488:10,489:10,490:11,491:11,492:11,493:11,494:11,495:11,496:11,497:11,498:11,499:11,500:11,501:11,502:11,503:11,504:11,505:11,506:11,507:11,508:12,509:12,510:12,511:12,512:12,513:12,514:12,515:12,516:12,517:12,518:12,519:12,520:12,521:12,522:12,523:12,524:12,525:13,526:13,527:13,528:13,529:13,530:13,531:13,532:13,533:13,534:13,535:13,536:13,537:13,538:13,539:13,540:13,541:13,542:13,543:14,544:14,545:14,546:14,547:14,548:14,549:14,550:14,551:14,552:14,553:14,554:14,555:14,556:14,557:14,558:14,559:14,560:15,561:15,562:15,563:15,564:15,565:15,566:15,567:15,568:15,569:15,570:15,571:15,572:15,573:15,574:15,575:15,576:15,577:15,578:16,579:16,580:16,581:16,582:16,583:16,584:16,585:16,586:16,587:16,588:16,589:16,590:16,591:16,592:16,593:16,594:16,595:17,596:17,597:17,598:17,599:17,600:17,601:17,602:17,603:17,604:17,605:17,606:17,607:17,608:17,609:17,610:17,611:17,612:17],
  5.     _baseLine = [-17:0,-16:18,-15:35,-14:53,-13:70,-12:88,-11:105,-10:123,-9:140,-8:158,-7:175,-6:193,-5:210,-4:228,-3:245,-2:263,-1:280,0:298,1:315,2:333,3:350,4:368,5:385,6:403,7:420,8:438,9:455,10:473,11:490,12:508,13:525,14:543,15:560,16:578,17:595],
  6.     _eMap = [-17:0,-16:0,-15:0,-14:0,-13:0,-12:0,-11:0,-10:0,-9:0,-8:0,-7:0,-6:0,-5:0,-4:0,-3:0,-2:0,-1:0,0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0],
  7.     _map = [-17:262143,-16:131071,-15:262143,-14:131071,-13:262143,-12:131071,-11:262143,-10:131071,-9:262143,-8:131071,-7:262143,-6:131071,-5:262143,-4:131071,-3:262143,-2:131071,-1:262143,0:131071,1:262143,2:131071,3:262143,4:131071,5:262143,6:131071,7:262143,8:131071,9:262143,10:131071,11:262143,12:131071,13:262143,14:131071,15:262143,16:131071,17:262143],
  8.     entities = getAliveAllies()+getAliveEnemies();
  9. removeElement(entities, getLeek());
  10.  
  11. /*----initialisation----*/
  12. if(getTurn()==1){
  13.     for(var obs in obstacles){
  14.         var l = @_line[obs];
  15.         _map[l] = _map[l] ^ (1 << (obs - _baseLine[l]));
  16.        
  17.     }
  18. }
  19.  
  20.  
  21. /*----chaque tour----*/
  22. var new_eMap = [-17:0,-16:0,-15:0,-14:0,-13:0,-12:0,-11:0,-10:0,-9:0,-8:0,-7:0,-6:0,-5:0,-4:0,-3:0,-2:0,-1:0,0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0];
  23. for(var cell in arrayMap(entities, getCell)){
  24.     var l = @_line[cell];
  25.     new_eMap[l] |= (1 << (cell - _baseLine[l]));
  26. }
  27. for(var l = -17; l <= 17; l++){
  28.     _map[l] = _map[l] ^ new_eMap[l] ^ _eMap[l];
  29.     _eMap[l] = @new_eMap[l];
  30. }
  31.  
  32. /*----la fonction----*/
  33. function getReachablesCells(@CELL, @MP){
  34.     if(MP === 0 or CELL < 0 or CELL > 612){
  35.         return [];
  36.     }
  37.    
  38.     var cells = [CELL:0],
  39.         bLine = [-17:0,-16:0,-15:0,-14:0,-13:0,-12:0,-11:0,-10:0,-9:0,-8:0,-7:0,-6:0,-5:0,-4:0,-3:0,-2:0,-1:0,0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0],
  40.         L = @_line[CELL],
  41.         next = false;
  42.     bLine[L] = 1 << CELL - _baseLine[L];
  43.     //debug("L:"+L);
  44.     if(L%2 === 0){
  45.         for(var mp = 1; mp <= MP; mp++){
  46.             if(mp%2 != 0){
  47.                 for(var l = (L-mp > -17)? L-mp:-17; l <= ((L+mp < 17)? L+mp+1:17); l+=2){
  48.                     var oldL = @bLine[l],
  49.                         upL = @bLine[l+1],
  50.                         downL = @bLine[l-1],
  51.                         newL = (oldL | upL | upL<<1 | downL | downL<<1) & _map[l];
  52.                     if(newL != oldL){
  53.                         (!next)? next = true:0;
  54.                         oldL = oldL ^ newL;
  55.                         var base = @_baseLine[l];
  56.                         (oldL & 1)? cells[base]+=mp:0;
  57.                         (oldL & 2)? cells[base+1]+=mp:0;
  58.                         (oldL & 4)? cells[base+2]+=mp:0;
  59.                         (oldL & 8)? cells[base+3]+=mp:0;
  60.                         (oldL & 16)? cells[base+4]+=mp:0;
  61.                         (oldL & 32)? cells[base+5]+=mp:0;
  62.                         (oldL & 64)? cells[base+6]+=mp:0;
  63.                         (oldL & 128)? cells[base+7]+=mp:0;
  64.                         (oldL & 256)? cells[base+8]+=mp:0;
  65.                         (oldL & 512)? cells[base+9]+=mp:0;
  66.                         (oldL & 1024)? cells[base+10]+=mp:0;
  67.                         (oldL & 2048)? cells[base+11]+=mp:0;
  68.                         (oldL & 4096)? cells[base+12]+=mp:0;
  69.                         (oldL & 8192)? cells[base+13]+=mp:0;
  70.                         (oldL & 16384)? cells[base+14]+=mp:0;
  71.                         (oldL & 32768)? cells[base+15]+=mp:0;
  72.                         (oldL & 65536)? cells[base+16]+=mp:0;
  73.                         (oldL & 131072)? cells[base+17]+=mp:0;
  74.                         bLine[l] = @newL;
  75.                     }
  76.                 }
  77.             }
  78.             else {
  79.                 for(var l = (L-mp > -16)? L-mp:-16; l <= ((L+mp < 16)? L+mp:16); l+=2){
  80.                     var oldL = @bLine[l],
  81.                         upL = @bLine[l+1],
  82.                         downL = @bLine[l-1],
  83.                         newL = (oldL | upL | upL>>1 | downL | downL>>1) & _map[l];
  84.                     if(newL != oldL){
  85.                         (!next)? next = true:0;
  86.                         oldL = oldL ^ newL;
  87.                         var base = @_baseLine[l];
  88.                         (oldL & 1)? cells[base]+=mp:0;
  89.                         (oldL & 2)? cells[base+1]+=mp:0;
  90.                         (oldL & 4)? cells[base+2]+=mp:0;
  91.                         (oldL & 8)? cells[base+3]+=mp:0;
  92.                         (oldL & 16)? cells[base+4]+=mp:0;
  93.                         (oldL & 32)? cells[base+5]+=mp:0;
  94.                         (oldL & 64)? cells[base+6]+=mp:0;
  95.                         (oldL & 128)? cells[base+7]+=mp:0;
  96.                         (oldL & 256)? cells[base+8]+=mp:0;
  97.                         (oldL & 512)? cells[base+9]+=mp:0;
  98.                         (oldL & 1024)? cells[base+10]+=mp:0;
  99.                         (oldL & 2048)? cells[base+11]+=mp:0;
  100.                         (oldL & 4096)? cells[base+12]+=mp:0;
  101.                         (oldL & 8192)? cells[base+13]+=mp:0;
  102.                         (oldL & 16384)? cells[base+14]+=mp:0;
  103.                         (oldL & 32768)? cells[base+15]+=mp:0;
  104.                         (oldL & 65536)? cells[base+16]+=mp:0;
  105.                         bLine[l] = @newL;
  106.                     }
  107.                 }
  108.             }
  109.             if(!next){
  110.                 break;
  111.             }
  112.             else{
  113.                 next = false;
  114.             }
  115.         }
  116.     }
  117.     else{
  118.         for(var mp = 1; mp <= MP; mp++){
  119.             if(mp%2 == 0){
  120.                 for(var l = (L-mp > -17)? L-mp:-17; l <= ((L+mp < 17)? L+mp:17); l+=2){
  121.                     var oldL = @bLine[l],
  122.                         upL = @bLine[l+1],
  123.                         downL = @bLine[l-1],
  124.                         newL = (oldL | upL | upL<<1 | downL | downL<<1) & _map[l];
  125.                     if(newL != oldL){
  126.                         (!next)? next = true:0;
  127.                         oldL = oldL ^ newL;
  128.                         var base = @_baseLine[l];
  129.                         (oldL & 1)? cells[base]+=mp:0;
  130.                         (oldL & 2)? cells[base+1]+=mp:0;
  131.                         (oldL & 4)? cells[base+2]+=mp:0;
  132.                         (oldL & 8)? cells[base+3]+=mp:0;
  133.                         (oldL & 16)? cells[base+4]+=mp:0;
  134.                         (oldL & 32)? cells[base+5]+=mp:0;
  135.                         (oldL & 64)? cells[base+6]+=mp:0;
  136.                         (oldL & 128)? cells[base+7]+=mp:0;
  137.                         (oldL & 256)? cells[base+8]+=mp:0;
  138.                         (oldL & 512)? cells[base+9]+=mp:0;
  139.                         (oldL & 1024)? cells[base+10]+=mp:0;
  140.                         (oldL & 2048)? cells[base+11]+=mp:0;
  141.                         (oldL & 4096)? cells[base+12]+=mp:0;
  142.                         (oldL & 8192)? cells[base+13]+=mp:0;
  143.                         (oldL & 16384)? cells[base+14]+=mp:0;
  144.                         (oldL & 32768)? cells[base+15]+=mp:0;
  145.                         (oldL & 65536)? cells[base+16]+=mp:0;
  146.                         (oldL & 131072)? cells[base+17]+=mp:0;
  147.                         bLine[l] = @newL;
  148.                     }
  149.                 }
  150.             }
  151.             else {
  152.                 for(var l = (L-mp > -16)? L-mp:-16; l <= ((L+mp < 16)? L+mp:16); l+=2){
  153.                     var oldL = @bLine[l],
  154.                         upL = @bLine[l+1],
  155.                         downL = @bLine[l-1],
  156.                         newL = (oldL | upL | upL>>1 | downL | downL>>1) & _map[l];
  157.                     if(newL != oldL){
  158.                         (!next)? next = true:0;
  159.                         oldL = oldL ^ newL;
  160.                         var base = @_baseLine[l];
  161.                         (oldL & 1)? cells[base]+=mp:0;
  162.                         (oldL & 2)? cells[base+1]+=mp:0;
  163.                         (oldL & 4)? cells[base+2]+=mp:0;
  164.                         (oldL & 8)? cells[base+3]+=mp:0;
  165.                         (oldL & 16)? cells[base+4]+=mp:0;
  166.                         (oldL & 32)? cells[base+5]+=mp:0;
  167.                         (oldL & 64)? cells[base+6]+=mp:0;
  168.                         (oldL & 128)? cells[base+7]+=mp:0;
  169.                         (oldL & 256)? cells[base+8]+=mp:0;
  170.                         (oldL & 512)? cells[base+9]+=mp:0;
  171.                         (oldL & 1024)? cells[base+10]+=mp:0;
  172.                         (oldL & 2048)? cells[base+11]+=mp:0;
  173.                         (oldL & 4096)? cells[base+12]+=mp:0;
  174.                         (oldL & 8192)? cells[base+13]+=mp:0;
  175.                         (oldL & 16384)? cells[base+14]+=mp:0;
  176.                         (oldL & 32768)? cells[base+15]+=mp:0;
  177.                         (oldL & 65536)? cells[base+16]+=mp:0;
  178.                         bLine[l] = @newL;
  179.                     }
  180.                 }
  181.             }
  182.             if(!next){
  183.                 break;
  184.             }
  185.             else{
  186.                 next = false;
  187.             }
  188.         }
  189.     }
  190.     return @cells;
  191. }
  192.  
  193. function getProgressiveColor(x, lim){
  194.     var r=0, g=0, b=0;
  195.     if(x >= lim) x%=lim;
  196.     var coef = (255*((6*x)%lim))/lim;
  197.     x/=lim;
  198.     if(x < (1/6))       { r= 255;       g= coef; }
  199.     else if (x < (2/6)) { r= 255-coef;  g= 255;}
  200.     else if (x < (3/6)) {               g= 255;         b= coef; }
  201.     else if (x < (4/6)) {               g= 255-coef;    b= 255;}
  202.     else if (x < (5/6)) { r= coef;                      b= 255; }
  203.     else if (x < (6/6)) { r= 255;                       b= 255-coef;}
  204.     return r*65536+g*256+b;
  205. }
  206.  
  207. function fonctionBenchPerso(@cell, @mp){
  208.     var res = [];
  209.     if(cell < 0 or cell > 612) cell = randInt(0,613);
  210.     if(mp < 0) mp = randInt(1,40);
  211.     mark(getObstacles(), COLOR_RED);
  212.     mark(arrayMap(getAliveAllies()+getAliveEnemies(), getCell), COLOR_BLUE);
  213.     mark(cell, COLOR_GREEN);
  214.     /**/var ops = getOperations() + 3;
  215.     res = getReachablesCells(cell, mp);
  216.     /**/debug("Coût pour la cell : "+cell+" avec "+mp+" : "+(getOperations() - ops));
  217.     moyenne += (getOperations()- ops -23)/mp;
  218.     debug("soit un ratio de "+((getOperations()- ops -23)/mp)+" ops/mp");
  219.     debug("moyenne : "+(moyenne/getTurn()));
  220.     for(var CELL: var MP in res){
  221.         mark(CELL, getProgressiveColor(MP, 30));   
  222.     }
  223.     pause();
  224. }
  225.  
  226.  
  227.  
  228. //la ligne de code dt les paramètres sont modifiable : cell, mp
  229. //si les valeurs sont négative, elles seront tirés aléatoirement.
  230. fonctionBenchPerso(-1,-1);
Add Comment
Please, Sign In to add comment