void AddOpenNeighboursToList (location_t here)
{
  if (HasExit (here, NORTH)) {
    ListAdd (Neighbour (here, NORTH));
  }
  if (HasExit (here, EAST)) {
    ListAdd (Neighbour (here, EAST));
  }
  if (HasExit (here, SOUTH)) {
    ListAdd (Neighbour (here, SOUTH));
  }
  if (HasExit (here, WEST)) {
    ListAdd (Neighbour (here, WEST));
  }
}
示例#2
0
direction_t SmallestNeighbourDirection (location_t loc)
{
  direction_t result = NORTH;
  location_t neighbour;
  cost_t smallestCost;
  cost_t cost;

  smallestCost = MAX_COST;
  if (HasExit (loc, NORTH)) {
    neighbour = Neighbour (loc, NORTH);
    cost = Cost (neighbour);
    if (cost < smallestCost) {
      smallestCost = cost;
      result = NORTH;
    }
  }
  if (HasExit (loc, EAST)) {
    neighbour = Neighbour (loc, EAST);
    cost = Cost (neighbour);
    if (cost < smallestCost) {
      smallestCost = cost;
      result = EAST;
    }
  }
  if (HasExit (loc, SOUTH)) {
    neighbour = Neighbour (loc, SOUTH);
    cost = Cost (neighbour);
    if (cost < smallestCost) {
      smallestCost = cost;
      result = SOUTH;
    }
  }
  if (HasExit (loc, WEST)) {
    neighbour = Neighbour (loc, WEST);
    cost = Cost (neighbour);
    if (cost < smallestCost) {
      smallestCost = cost;
      result = WEST;
    }
  }
  return result;
}
示例#3
0
LateReturn<> SubpatchExit::on_init_latereturn(){
  
  Relay<> r;
  Sync s(4);
  
  // Check if parent canvas is managed by a subpatch.
  std::shared_ptr<Module> owner = canvas.lock()->owner_hint;
  auto owner_subpatch = std::dynamic_pointer_cast<Subpatch>(owner);
  // If not, throw a DoNotWantToBeCreated exception.
  if(!owner_subpatch) {r.LateThrow<Exceptions::ModuleDoesNotWantToBeCreated>("This module can only be created inside a subpatch."); return r;}
  if(owner_subpatch->HasExit()) {r.LateThrow<Exceptions::ModuleDoesNotWantToBeCreated>("Currently it is not possible to create multiple exits inside the same subpatch."); return r;}
  // Otherwise link to that entrance.
  owner_subpatch->LinkToExit(std::static_pointer_cast<SubpatchExit>( shared_from_this() ));
  subpatch = owner_subpatch;
  
  // Create inlets.
  inlets.resize(4);
  
  bool fake = ! Config::Global().use_sc;
  
  Module::Inlet::Create("in1","Inlet 1",shared_from_this(),fake).Then([this,s](auto inlet){
    inlets[0] = inlet;
    subpatch->LinkOutput(0, inlet->bus->GetID());
    s.Trigger();
  });
  Module::Inlet::Create("in2","Inlet 2",shared_from_this(),fake).Then([this,s](auto inlet){
    inlets[1] = inlet;
    subpatch->LinkOutput(1, inlet->bus->GetID());
    s.Trigger();
  });
  Module::Inlet::Create("in3","Inlet 3",shared_from_this(),fake).Then([this,s](auto inlet){
    inlets[2] = inlet;
    subpatch->LinkOutput(2, inlet->bus->GetID());
    s.Trigger();
  });
  Module::Inlet::Create("in4","Inlet 4",shared_from_this(),fake).Then([this,s](auto inlet){
    inlets[3] = inlet;
    subpatch->LinkOutput(3, inlet->bus->GetID());
    s.Trigger();
  });
  s.WhenAll([r, this](){  
    if(modulegui) modulegui->OnInletsChanged();
    r.Return();
  });
  
  return r;
}
void FloodMazeClassic (location_t target)
{
  location_t here;
  location_t nextLoc;
  cost_t costHere;
  cost_t costNext;
  for (here.row = 0; here.row < MAZE_ROWS; here.row++) {
    for (here.col = 0; here.col < MAZE_COLS; here.col++) {
      SetCost (here, MAX_COST);
      SetDirection (here, INVALID);
    }
  }
  SetCost (target, 0);
  ListReset();
  ListAdd (target);
  while (!ListIsEmpty()) {
    /*
     * TODO: show costs and directions for all combinations
     * of testing against MAX_COST vs smaller than and stack vs queue
     */
    here = ListQueueHead();
    //here = ListStackPop();
    costNext = Cost (here) + 1;
    if (HasExit (here, NORTH)) {
      nextLoc = Neighbour (here, NORTH);
      if (Cost (nextLoc) > costNext) {
        SetDirection (nextLoc, SOUTH);
        SetCost (nextLoc, costNext);
        ListAdd (nextLoc);
      }
    }

    if (HasExit (here, EAST)) {
      nextLoc = Neighbour (here, EAST);
      if (Cost (nextLoc) > costNext) {
        SetDirection (nextLoc, WEST);
        SetCost (nextLoc, costNext);
        ListAdd (nextLoc);
      }
    }

    if (HasExit (here, SOUTH)) {
      nextLoc = Neighbour (here, SOUTH);
      if (Cost (nextLoc) > costNext) {
        SetDirection (nextLoc, NORTH);
        SetCost (nextLoc, costNext);
        ListAdd (nextLoc);
      }
    }

    if (HasExit (here, WEST)) {
      nextLoc = Neighbour (here, WEST);
      if (Cost (nextLoc) > costNext) {
        SetDirection (nextLoc, EAST);
        SetCost (nextLoc, costNext);
        ListAdd (nextLoc);
      }
    }

  }
  //printf ("Max List Length = %d List additions = %d path cost = %d\n", ListMaxSize(), ListAdditions(), Cost (Home()));
}