Skip to content

Instantly share code, notes, and snippets.

@Nakilon
Last active July 24, 2018 23:18
Show Gist options
  • Save Nakilon/07c384e17dd7b9a4ebdc9ec0fca7c6a3 to your computer and use it in GitHub Desktop.
Save Nakilon/07c384e17dd7b9a4ebdc9ec0fca7c6a3 to your computer and use it in GitHub Desktop.
COLOBOT: Code battle - vs computer :: this one by Nakilon is very short and defeats AI
void titanium() {
object o;
while (null == (o = radar(TitaniumOre, 0, 360, 0, 30))) wait(0.1);
goto(o.position);
grab();
goto(radar(Converter, 0, 360, 0, 20).position);
drop();
move(-2);
}
void _build(float w, point p, int c) {
object o;
while (null == (o = radar(Titanium, 0, 360, 0, 30))) wait(0.1);
goto(o.position);
grab();
goto(flatspace(p, w / 2, 0, 50, w / 2 + 4.5));
drop();
build(c);
}
object object::load_titanium(int c) {
point t = radar(Converter, 0, 360, 0, 30).position;
float d = distance(position, t);
object o;
while (null == (o = radar(Titanium, direction(t), 10, d - 1, d + 1))) wait(0.1);
goto(o.position);
grab();
o = radar(c, 0, 360, 0, 20);
goto(o.position);
drop();
return o;
}
object load_powercell(int c) {
object o = radar(PowerPlant, 0, 360, 0, 30);
goto(o.position);
while (o.energyCell.category != PowerCell) wait(0.1);
if (c == -1) {
grab(EnergyCell); drop(Behind); grab(); drop(EnergyCell); grab(Behind); turn(-90); move(1);
} else {
grab();
while (null == (o = radar(c, 0, 360, 0, 30, 1, FilterFriendly))) wait(0.1);
goto(o.position);
if (null != o.energyCell) {
turn(90); drop(); turn(-90); grab(); turn(-90); drop(); turn(180); grab(); turn(-90);
}
}
drop();
return o;
}
extern void object::Nakilon_1() {
build(Converter); titanium();
_build(4, position, PowerPlant); titanium();
_build(5, position, ResearchCenter); titanium();
_build(8, position, BotFactory);
titanium();
load_titanium(PowerPlant);
load_powercell(ResearchCenter).research(ResearchWinged);
titanium();
object f = load_titanium(BotFactory);
object r = radar(ResearchCenter, 0, 360, 0, 30);
titanium();
load_titanium(PowerPlant);
titanium();
load_powercell(ResearchCenter).research(ResearchShooter);
load_titanium(PowerPlant);
titanium();
load_powercell(-1);
while (r.busy()) wait(0.1);
f.factory(WingedShooter, "start");
load_titanium(PowerPlant);
while(true) {
titanium();
load_powercell(WingedShooter);
move(-7);
load_titanium(BotFactory);
move(-2);
f.factory(WingedShooter, "start");
titanium();
load_titanium(PowerPlant);
}
}
public void object::start() {
while (null == energyCell) wait(1);
wait(2);
move(-7);
winged_shooter();
}
void object::winged_shooter() {
object o;
point e;
float dir, dist, dz;
while (true) {
o = radar(Any, 0, 360, 0, 1000, 1, FilterOnlyFlying);
if (null == o) o = radar(Any, 0, 360, 0, 1000, 1, FilterEnemy);
if (null == o) break;
e = o.position;
try {
e.x += o.velocity.x / 2;
e.y += o.velocity.y / 2;
e.z += o.velocity.z / 2;
}
dz = e.z - position.z - 1;
dist = distance2d(position, e);
dir = direction(e);
aim(atan(dz / dist) - (((pitch + 180) % 360) - 180), -dir);
jet((dz + 3) / 20);
if (dist > 40) {
motor(1 - dir/2, 1 + dir/2);
wait(0.01);
} else {
if (abs(dir) > 30) {
motor(0 - dir/2, 0 + dir/2);
wait(0.01);
} else {
motor(0, 0);
fire(0.1);
jet(0);
wait(0.1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment