Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Powercells that needs charging
#3
Hello,

Im quite new in programming (last time i was trying 10 years ago - in Colobot too) and i have problem with my program. I have no idea how to solve it.
I want it to:
1) find fully charged NuclearCell and grab it
2) find a robot with empty NuclearCell, go there
3) exchange him Cell to fresh one

So i wrote that code:
Code:
extern void object::Power_Rescue()
{
while (true)
{
if (this.load != null)
{
goto(space(position));
drop();
}

FindFullCell();
FindEmptyCell();  
ChangeCell();
wait(10);
}
}

void object::FindFullCell()
{
while (true)
{
object[] list;

for (int i=0, j=0;; i++)
{
object item = retobject(i);
if (item == null) break;
if (item.category != NuclearCell) continue;
if (item.position.x == nan) continue; // jesli ogniwo nie jest w robocie
if (item.energyLevel == 1)
{
list[j++] = item;
}
}

for (int i=0; i < sizeof(list); i++)
{
object item = list[i];
goto(item.position);
grab();
break;
}
break;
}

}

void object::FindEmptyCell()
{
object item;
int j;
object[] list;

for (int i=0, j=0;; i++)
{
object item = retobject(i);
if (item == null) break;
if (item.category != NuclearCell) continue;
if (item.position.x != nan) continue; // jesli ogniwo nie jest w robocie
if (item.energyLevel < 0.1)
{
list[j++] = item;
}
}

for (int i=0; i < sizeof(list); i++)
{
object item = list[i];
goto(item.position);
}
}

void object::ChangeCell()
{
turn(90);
drop();  
turn(-90);  
grab();
turn(-90);
drop();
turn(180);    
grab();
turn(-90);
drop();
}
So, FindFullCell works fine and the problem is with FindEmptyCell - it finds a cell with position.x == null, so that cell is installed in robot and that's good. But how the robot can goto robot's position, while the position (of cell) == null ? Big Grin How to get a position of the robot?

P.S. I know there may be a lot of bugs in program and maybe it's not well iptimized but its my third day, so I'm just a begginer.


Messages In This Thread
Finding Powercells that needs charging - by Jono - 04-09-2015, 08:14 AM
RE: Finding Powercells that needs charging - by krakers - 12-04-2015, 04:13 PM

Forum Jump:


Users browsing this thread: 5 Guest(s)