Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

My aStar will shine!

Name: Anonymous 2011-02-10 22:36


aStar neibs s t -> with [0=[s no 0]] []
  {:r os:ye? vs -> do o:os.lhd,1 os=:os.ltl // pop lowest scored node
    nG:o,2+1 // score for neighbor nodes
    o,0.{!t -> o.{:r [xy p:ye? @_] -> [@p.r xy]} // found!
        ;xy -> do (xy.neibs |> fe // for each passable neigbor
                    {n -> pG:vs.n
                          if pG.no? ** nG < pG then do // no shorter path?
                            [nG+(map abs t-n).sum=[n o nG] @!os] // g+h
                            [n=nG @!vs]})
                  (r os [o=o,2 @vs])}}

Name: Anonymous 2011-02-10 22:49

>>2
Fuck off and die.

Name: Anonymous 2011-02-10 22:58

Compare to C/C++:
http://www.koders.com/cpp/fidC83C979C41FC6F93DA472C79F50349EF9B60E173.aspx

const REAL AStar::DistWeights[DIR_NUMBER] = {    1, 1, 1, 1, SQRT2, SQRT2, SQRT2, SQRT2,
                                        SQRT5, SQRT5, SQRT5, SQRT5,  SQRT5, SQRT5, SQRT5, SQRT5,
                                        SQRT10, SQRT10, SQRT10, SQRT10, SQRT10, SQRT10, SQRT10, SQRT10,
                                        SQRT13, SQRT13, SQRT13, SQRT13, SQRT13, SQRT13, SQRT13, SQRT13};

AStar::AStar ()
{
    unsigned long i;

  width = 0;
  height = 0;
  matrix = NULL;
  Terrain = NULL;
  TerrainNumber = 0;
  TerrainRatio = 0;
    CurrPresetNr = 4;
    InitPreset(true);
    for(i = 0; i < DIR_NUMBER; i++)
    {
        AllDir[i] = true;
    }

  GetDirectionWeight[0] = &GetDirectionWeight0;
  GetDirectionWeight[1] = &GetDirectionWeight1;
  GetDirectionWeight[2] = &GetDirectionWeight2;
  GetDirectionWeight[3] = &GetDirectionWeight3;
  GetDirectionWeight[4] = &GetDirectionWeight4;
  GetDirectionWeight[5] = &GetDirectionWeight5;
  GetDirectionWeight[6] = &GetDirectionWeight6;
  GetDirectionWeight[7] = &GetDirectionWeight7;
  GetDirectionWeight[8] = &GetDirectionWeight8;
  GetDirectionWeight[9] = &GetDirectionWeight9;
  GetDirectionWeight[10] = &GetDirectionWeight10;
  GetDirectionWeight[11] = &GetDirectionWeight11;
  GetDirectionWeight[12] = &GetDirectionWeight12;
  GetDirectionWeight[13] = &GetDirectionWeight13;
  GetDirectionWeight[14] = &GetDirectionWeight14;
  GetDirectionWeight[15] = &GetDirectionWeight15;
  GetDirectionWeight[16] = &GetDirectionWeight16;
  GetDirectionWeight[17] = &GetDirectionWeight17;
  GetDirectionWeight[18] = &GetDirectionWeight18;
  GetDirectionWeight[19] = &GetDirectionWeight19;
  GetDirectionWeight[20] = &GetDirectionWeight20;
  GetDirectionWeight[21] = &GetDirectionWeight21;
  GetDirectionWeight[22] = &GetDirectionWeight22;
  GetDirectionWeight[23] = &GetDirectionWeight23;
  GetDirectionWeight[24] = &GetDirectionWeight24;
  GetDirectionWeight[25] = &GetDirectionWeight25;
  GetDirectionWeight[26] = &GetDirectionWeight26;
  GetDirectionWeight[27] = &GetDirectionWeight27;
  GetDirectionWeight[28] = &GetDirectionWeight28;
  GetDirectionWeight[29] = &GetDirectionWeight29;
  GetDirectionWeight[30] = &GetDirectionWeight30;
  GetDirectionWeight[31] = &GetDirectionWeight31;
}

AStar::~AStar ()
{
  Destroy ();
}

void AStar::Destroy ()
{
    if(matrix) Destroy2DArray(matrix);
    if(Terrain) Destroy3DArray(Terrain);

  openlist.Destroy ();
  width = 0;
  height = 0;
  TerrainNumber = 0;
  TerrainRatio = 0;
  ImpassableLimit = 255;
}

bool AStar::Create(unsigned long width, unsigned long height, unsigned long TerrainNumber, unsigned char ImpassableLimit)
{
  return Create (width, height, TerrainNumber, ImpassableLimit, TerrainRatio);
}

bool AStar::Create(unsigned long width, unsigned long height, unsigned long TerrainNumber, unsigned char ImpassableLimit, REAL TerrainRatio)
{
    if(TerrainNumber < 1) return false;
    if(TerrainRatio < 0) return false;
    if(width == 0) return false;
    if(height == 0) return false;

  Destroy ();

    if(!Create2DArray(matrix, width, height)) return false;
  if (!Create3DArray (Terrain, width, height, TerrainNumber))
  {
    Destroy ();
    return false;
  }
  memset (GetArray3D (Terrain), 0, width * height * TerrainNumber);

  this->width = width;
  this->height = height;
  this->TerrainNumber = TerrainNumber;
  this->TerrainRatio = TerrainRatio;
  this->ImpassableLimit = ImpassableLimit;

  return true;
}

void AStar::ResetMatrix ()
{
  long x, y;

    if(!matrix) return;
    if(!matrix[0]) return;

  for (y = 0; y < (long) height; y++)
  {
        for(x = 0; x < (long)width; x++) matrix[y][x].Reset();
  }
}

void AStar::InitPreset(bool value)
{
    unsigned char i, j;

    for(i = 0; i < DIR_NUMBER; i++)
    {
        for(j = 0; j < DIR_NUMBER; j++)
        {
            if(i == GetOppositeDir(j)) CheckPaths[i][j] = false;
            else CheckPaths[i][j] = value;
        }
    }
}

unsigned char AStar::GetOppositeDir(unsigned char Dir)
{
    return RealToDir[(DirToReal[Dir] + DIR_MIDDLE) % DIR_NUMBER];
}

void AStar::CreatePreset(unsigned char PresetNr)
{
    unsigned char i, j;
    unsigned char Detail=8;
    double d;
    Point pA, pB;
    Vector2D v1, v2;

    if(PresetNr <= 4)
    {
        switch(PresetNr)
        {
        case 0: Detail = 4; break;
        case 1: Detail = 8; break;
        case 2: Detail = 16; break;
        case 3: Detail = 24; break;
        case 4: Detail = 32; break;
        }
        for(i = 0; i < DIR_NUMBER; i++)
        {
            for(j = 0; j < Detail; j++)
            {
                CheckPaths[i][j] = true;
            }
            for(; j < DIR_NUMBER; j++)
            {
                CheckPaths[i][j] = false;
            }
        }
    }
    else if(PresetNr == 5)
    {
        for(i = 0; i < DIR_NUMBER; i++)
        {
            for(j = 0; j < 4; j++)
            {
                CheckPaths[i][j] = true;
            }
            for(j = 4; j < DIR_NUMBER; j++)
            {
                CheckPaths[i][j] = false;
            }
            CheckPaths[i][i] = true;
            CheckPaths[i][RealToDir[(DirToReal[i] + 1) % DIR_NUMBER]] = true;
            CheckPaths[i][RealToDir[(DirToReal[i] + DIR_NUMBER - 1) % DIR_NUMBER]] = true;
        }
    }
    else if(PresetNr == 6)
    {
        for(i = 0; i < DIR_NUMBER; i++)
        {
            for(j = 0; j < 8; j++)
            {
                CheckPaths[i][j] = true;
            }
            for(j = 8; j < DIR_NUMBER; j++)
            {
                CheckPaths[i][j] = false;
            }
            CheckPaths[i][i] = true;
            CheckPaths[i][RealToDir[(DirToReal[i] + 1) % DIR_NUMBER]] = true;
            CheckPaths[i][RealToDir[(DirToReal[i] + DIR_NUMBER - 1) % DIR_NUMBER]] = true;
        }
    }
    else if(PresetNr == 7)
    {
        pA.Set(0, 0);
        for(i = 0; i < DIR_NUMBER; i++)
        {
            pB = pA.GetNextPoint(i);
            v1.Set(-pB.x, -pB.y);
            for(j = 0; j < 8; j++)
            {
                CheckPaths[i][j] = true;
            }
            for(j = 8; j < DIR_NUMBER; j++)
            {
                CheckPaths[i][j] = false;
            }
            CheckPaths[i][i] = true;
            for(j = 1; j < DIR_NUMBER; j++)
            {
                pB = pA.GetNextPoint(RealToDir[(DirToReal[i] + j) % DIR_NUMBER]);
                v2.Set(-pB.x, -pB.y);
                d = v1.GetAngleBetweenDEG(v2);
                CheckPaths[i][RealToDir[(DirToReal[i] + j) % DIR_NUMBER]] = true;
                if(d >= 10) break;
            }
            for(j = 1; j < DIR_NUMBER; j++)
            {
                pB = pA.GetNextPoint(RealToDir[(DirToReal[i] + DIR_NUMBER - j) % DIR_NUMBER]);
                v2.Set(-pB.x, -pB.y);
                d = v1.GetAngleBetweenDEG(v2);
                CheckPaths[i][RealToDir[(DirToReal[i] + DIR_NUMBER - j) % DIR_NUMBER]] = true;
                if(d >= 10) break;
            }
        }
    }
    else if(PresetNr == 8)
    {

Name: Anonymous 2011-02-10 23:07

>>6>>7
Whats wrong with C++? Everyone seems to love it.

Name: Anonymous 2011-02-10 23:39

Zalgo, is that you?

Name: Anonymous 2011-02-11 0:58

zolotce

Name: Anonymous 2011-02-11 2:14

Well this is certainly an interesting and amusing development.

Don't change these.
Name: Email:
Entire Thread Thread List