Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Powercells that needs charging
#6
It's not impossible.

I'm testing your program now.

Your program needs to be modified to search for a "robot" which has an empty PowerCell.

Wow that was tough. I re-wrote most of it. Tell me if you find any bugs. Smile

Code:
extern void object::Power_Rescue()
{
    while (true)
    {
        if (this.load != null)
        {
            goto(space(position));
            drop();
        }
        
        FindObjectReplaceCell();  
        if (this.load != null) continue;
        wait(10);
    }
}

void object::GrabNearestFullCell()
{
    object item, NearestItem = null;
    int i = 0;
    while (true)
    {
        item = retobject(i++);
        if (item == null) break;
        if (item.category != NuclearCell) continue;
        if (item.position.x == nan) continue;
        if (item.energyLevel == 1)
        {
            if (NearestItem == null)
            {
                NearestItem = item;
                continue;
            }
            if (distance(this.position, item.position) < distance(this.position, NearestItem.position) )
            {
                NearestItem = item;
            }
        }
    }
    if (NearestItem == null) return; // did not find an item
    goto(NearestItem.position);
    grab(InFront);
    return;
}

void object::ChangeCell()
{
    drop(Behind);  
    grab(InFront);
    
    turn(-90);  
    drop(InFront);
    turn(90);    
    
    grab(Behind);
    drop(InFront);
    
    turn(-90);
    grab(InFront);
}


void object::FindObjectReplaceCell()
{
    object item;
    int i = 0, t = 0;
    float speed;
    
    int types[];
    types[t++] = WheeledShooter;
    types[t++] = WheeledGrabber;
    types[t++] = TrackedGrabber;
    
    while (true)
    {
        item = retobject(i++);
        if (item == null) break;
        for (int k = 0; k < sizeof(types); k++)
        {
            if (item.category == types[k])      // must be in the list
            {
                if (item.id == this.id) break; // <--------- not this bot
                if (item.energyCell == null)
                {
                    message("INFO: "+item.category+" Has No energyCell");
                    break; //<--------------------------------------- must have an energyCell
                }
                if (item.energyCell.energyLevel < 0.1)
                {
                    if (item.velocity.x != nan)
                    {
                        speed =  abs(item.velocity.x);
                        speed += abs(item.velocity.y);
                        speed += abs(item.velocity.z);
                    } else speed = 0.0;
                    
                    if (speed != 0.0 and item.altitude > 0.0) break;// not moving or flying
                    GrabNearestFullCell();
                    if (this.load == null) return; // did not find a FuelCell
                    goto(item.position);
                    ChangeCell();
                    return;
                }
            }
        }
    }
    return;
}


Messages In This Thread
Finding Powercells that needs charging - by Jono - 04-09-2015, 08:14 AM
RE: Finding Powercells that needs charging - by melex750 - 12-05-2015, 01:28 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)