LCOV - code coverage report
Current view: top level - simulation/ai/common-api - utils.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 39 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 8 0.0 %

          Line data    Source code
       1           0 : var API3 = function(m)
       2             : {
       3             : 
       4           0 : m.warn = function(output)
       5             : {
       6           0 :         if (typeof output === "string")
       7           0 :                 warn("PlayerID " + PlayerID + " |   " + output);
       8             :         else
       9           0 :                 warn("PlayerID " + PlayerID + " |   " + uneval(output));
      10             : };
      11             : 
      12             : /**
      13             :  * Useful for simulating consecutive AI matches.
      14             :  */
      15           0 : m.exit = function()
      16             : {
      17           0 :         Engine.Exit();
      18             : };
      19             : 
      20           0 : m.VectorDistance = function(a, b)
      21             : {
      22           0 :         return Math.euclidDistance2D(a[0], a[1], b[0], b[1]);
      23             : };
      24             : 
      25           0 : m.SquareVectorDistance = function(a, b)
      26             : {
      27           0 :         return Math.euclidDistance2DSquared(a[0], a[1], b[0], b[1]);
      28             : };
      29             : 
      30             : /** Utility functions for conversions of maps of different sizes */
      31             : 
      32             : /**
      33             :  * Returns the index of map2 with max content from indices contained inside the cell i of map1
      34             :  * map1.cellSize must be a multiple of map2.cellSize
      35             :  */
      36           0 : m.getMaxMapIndex = function(i, map1, map2)
      37             : {
      38           0 :         let ratio = map1.cellSize / map2.cellSize;
      39           0 :         let ix = (i % map1.width) * ratio;
      40           0 :         let iy = Math.floor(i / map1.width) * ratio;
      41             :         let index;
      42           0 :         for (let kx = 0; kx < ratio; ++kx)
      43           0 :                 for (let ky = 0; ky < ratio; ++ky)
      44           0 :                         if (!index || map2.map[ix+kx+(iy+ky)*map2.width] > map2.map[index])
      45           0 :                                 index = ix+kx+(iy+ky)*map2.width;
      46           0 :         return index;
      47             : };
      48             : 
      49             : /**
      50             :  * Returns the list of indices of map2 contained inside the cell i of map1
      51             :  * map1.cellSize must be a multiple of map2.cellSize
      52             :  */
      53           0 : m.getMapIndices = function(i, map1, map2)
      54             : {
      55           0 :         let ratio = map1.cellSize / map2.cellSize;      // TODO check that this is integer >= 1 ?
      56           0 :         let ix = (i % map1.width) * ratio;
      57           0 :         let iy = Math.floor(i / map1.width) * ratio;
      58           0 :         let ret = [];
      59           0 :         for (let kx = 0; kx < ratio; ++kx)
      60           0 :                 for (let ky = 0; ky < ratio; ++ky)
      61           0 :                         ret.push(ix+kx+(iy+ky)*map2.width);
      62           0 :         return ret;
      63             : };
      64             : 
      65             : /**
      66             :  * Returns the list of points of map2 contained inside the cell i of map1
      67             :  * map1.cellSize must be a multiple of map2.cellSize
      68             :  */
      69           0 : m.getMapPoints = function(i, map1, map2)
      70             : {
      71           0 :         let ratio = map1.cellSize / map2.cellSize;      // TODO check that this is integer >= 1 ?
      72           0 :         let ix = (i % map1.width) * ratio;
      73           0 :         let iy = Math.floor(i / map1.width) * ratio;
      74           0 :         let ret = [];
      75           0 :         for (let kx = 0; kx < ratio; ++kx)
      76           0 :                 for (let ky = 0; ky < ratio; ++ky)
      77           0 :                         ret.push([ix+kx, iy+ky]);
      78           0 :         return ret;
      79             : };
      80             : 
      81           0 : return m;
      82             : 
      83             : }(API3);

Generated by: LCOV version 1.14