[resources] added dota maps

This commit is contained in:
2018-02-07 22:49:23 +03:00
parent 3096fba7c5
commit 89ac9fd225
7 changed files with 61 additions and 11 deletions

View File

@@ -1,5 +1,8 @@
package ru.m.tankz.bot;
import ru.m.tankz.core.Tank;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.game.Game;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.control.Control;
@@ -7,11 +10,49 @@ import ru.m.geom.Direction;
import haxe.Timer;
class BotHelper {
public static function findEagle(team:TeamId, handler:ControlHandler):Null<Eagle> {
for (entity in handler.entities) {
switch (EntityTypeResolver.of(entity)) {
case EntityType.EAGLE(eagle):
if (eagle.team != team) {
return eagle;
}
case x:
}
}
return null;
}
public static function getDirectionTo(entity:Entity, target:Entity):Direction {
var x:Float = target.rect.x - entity.rect.x;
var y:Float = target.rect.y - entity.rect.y;
var xD:Direction = Direction.from(Std.int(x / Math.abs(x)), 0);
var yD:Direction = Direction.from(0, Std.int(y / Math.abs(y)));
if (entity.rect.direction == xD) return yD;
if (entity.rect.direction == yD) return xD;
return Math.abs(x) > Math.abs(y) ? xD : yD;
}
public static function randomDirection():Direction {
return [
Direction.TOP,
Direction.BOTTOM,
Direction.LEFT,
Direction.RIGHT,
][Math.floor(Math.random() * 4)];
}
}
class BotControl extends Control {
private var shotTimer:Timer;
private var turnRandomTimer:Timer;
private var turnTimer:Timer;
private var tank(get, null):Tank;
public function new(playerId:PlayerId) {
super(playerId);
@@ -27,7 +68,6 @@ class BotControl extends Control {
override public function start():Void {
if (handler == null) return;
var tank = handler.entities.get(tankId);
action(TankAction.MOVE(tank.rect.direction));
if (shotTimer == null) {
shotTimer = new Timer(1000);
@@ -65,15 +105,17 @@ class BotControl extends Control {
turnTimer.stop();
turnTimer = null;
}
action(TankAction.MOVE(randomDirection()));
// ToDo:
if (handler == null || tank == null) return;
var eagle:Eagle = BotHelper.findEagle(playerId.team, handler);
if (eagle != null && Math.random() > 0.25) {
action(TankAction.MOVE(BotHelper.getDirectionTo(tank, eagle)));
} else {
action(TankAction.MOVE(BotHelper.randomDirection()));
}
}
private function randomDirection():Direction {
return [
Direction.TOP,
Direction.BOTTOM,
Direction.LEFT,
Direction.RIGHT,
][Math.floor(Math.random() * 4)];
private function get_tank():Tank {
return cast handler.entities[tankId];
}
}