12-04-2015, 04:13 PM
(This post was last modified: 12-05-2015, 03:13 AM by krakers.
Edit Reason: i placed "[/code]" in wrong place
)
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:
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 ? 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.
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();
}
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.