From 89ac9fd225a9da300589807e2b53b4da70d87773 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 7 Feb 2018 22:49:23 +0300 Subject: [PATCH] [resources] added dota maps --- package.json | 2 +- src/client/resources/dota/config.yaml | 2 +- src/client/resources/dota/levels/level003.txt | 2 + src/client/resources/dota/levels/level004.txt | 2 + src/client/resources/dota/levels/level005.txt | 2 + src/client/resources/dota/levels/level006.txt | 2 + src/common/haxe/ru/m/tankz/bot/BotControl.hx | 60 ++++++++++++++++--- 7 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/client/resources/dota/levels/level003.txt create mode 100644 src/client/resources/dota/levels/level004.txt create mode 100644 src/client/resources/dota/levels/level005.txt create mode 100644 src/client/resources/dota/levels/level006.txt diff --git a/package.json b/package.json index c5c0d75..ba26d0e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tankz", - "version": "0.5.0", + "version": "0.5.1", "private": true, "devDependencies": { "ansi-colors": "^1.0.1", diff --git a/src/client/resources/dota/config.yaml b/src/client/resources/dota/config.yaml index 9ff2e9b..f5dd432 100644 --- a/src/client/resources/dota/config.yaml +++ b/src/client/resources/dota/config.yaml @@ -1,5 +1,5 @@ game: - levels: 3 + levels: 7 friendlyFire: true map: diff --git a/src/client/resources/dota/levels/level003.txt b/src/client/resources/dota/levels/level003.txt new file mode 100644 index 0000000..d3fc13f --- /dev/null +++ b/src/client/resources/dota/levels/level003.txt @@ -0,0 +1,2 @@ +points: [{index: -1, direction: right, team: radiant, x: 24, type: eagle, y: 26}, {index: 0, direction: right, team: radiant, x: 14, type: tank, y: 26}, {index: 1, direction: right, team: radiant, x: 20, type: tank, y: 20}, {index: 2, direction: right, team: radiant, x: 26, type: tank, y: 20}, {index: 3, direction: right, team: radiant, x: 34, type: tank, y: 24}, {index: 4, direction: right, team: radiant, x: 38, type: tank, y: 22}, {index: -1, direction: right, team: dire, x: 22, type: eagle, y: 2}, {index: 0, direction: left, team: dire, x: 8, type: tank, y: 2}, {index: 1, direction: left, team: dire, x: 12, type: tank, y: 6}, {index: 2, direction: left, team: dire, x: 20, type: tank, y: 6}, {index: 3, direction: left, team: dire, x: 21, type: tank, y: 10}, {index: 4, direction: left, team: dire, x: 28, type: tank, y: 4}] +data: "444444444400000000440000004444000000000044444444440000000044000000444400000000004444440000004444004400000044440033444400444444000000444400440000004444003344440000000000440000440044000000000000000000000000000044000044004400000000000000000000003344004400000000000044004444440000444400334400440000000000004400444444000044440000000000004400444444440033440000005544000000000000440044444444003344000000554444004433440044444400000000004400440000004400443344004444440000000000440044000000440000000000004444004444440044004444440044000000000000444400444444004400444444000000440055440044440044440000000055444400000044005544004444004444000000005544440000444400444400000000000000443300000000000044440044440000000000000044330000000000000044004444003300444444004444004433004400004400444400330044444400444400443300444400000000000033000000000000000044000000440000000000003300000000000000004400000044440044004444444400444444440000440044004444004400444444440044444444000044004400000000000000440000000000000000000000440000000000000044000000000000000000000044004455003344000000440044000000440033444400445500334400000044004400000044003344440044440000000044000000440000004400000000004444000000004400000044000000440000000000" diff --git a/src/client/resources/dota/levels/level004.txt b/src/client/resources/dota/levels/level004.txt new file mode 100644 index 0000000..5c630c7 --- /dev/null +++ b/src/client/resources/dota/levels/level004.txt @@ -0,0 +1,2 @@ +points: [{index: -1, direction: right, team: radiant, x: 12, type: eagle, y: 2}, {index: 0, direction: right, team: radiant, x: 6, type: tank, y: 6}, {index: 1, direction: right, team: radiant, x: 10, type: tank, y: 10}, {index: 2, direction: right, team: radiant, x: 14, type: tank, y: 10}, {index: 3, direction: right, team: radiant, x: 18, type: tank, y: 6}, {index: 4, direction: right, team: radiant, x: 20, type: tank, y: 2}, {index: -1, direction: right, team: dire, x: 22, type: eagle, y: 26}, {index: 0, direction: left, team: dire, x: 12, type: tank, y: 26}, {index: 1, direction: left, team: dire, x: 18, type: tank, y: 22}, {index: 2, direction: left, team: dire, x: 24, type: tank, y: 22}, {index: 3, direction: left, team: dire, x: 28, type: tank, y: 18}, {index: 4, direction: left, team: dire, x: 30, type: tank, y: 10}] +data: "000000000033333300000000000000000000000000000000003333330000000000000000000000000000004400330033004400000000003300000044000000440033003300440000000000330000004400000000003333330000000044440000000000000000000000333333000000004444000000000000000000000000000000003300000000004444000000000000000000000000330000000000444400000044000000004400000000004400000044000000004400000000440000000000440000004400000000000033000000000000004444000000000000000000003300000000000000444400000000000000000000000000330000440000000033000000000000000000000033000044000000003300000000000000000000000000444400004400000000000000000000000000000044440000440000000000000000000000334444004444000000000044000000000000000033444400444400000000004400000000004400000044000000000000330000440000000000440000004400000000000033000044000000000000440000000000330000440000000000000033000044000000000033000044000000000000003300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044000000003333330000000033000000000000004400000000333333000000003300000000000000000000440033003300440000000000000000000000000044003300330044000000000000000000000000000000333333000000000000000000000000000000000033333300000000000000" diff --git a/src/client/resources/dota/levels/level005.txt b/src/client/resources/dota/levels/level005.txt new file mode 100644 index 0000000..cf6e40a --- /dev/null +++ b/src/client/resources/dota/levels/level005.txt @@ -0,0 +1,2 @@ +points: [{index: -1, direction: right, team: radiant, x: 19, type: eagle, y: 28}, {index: 0, direction: right, team: radiant, x: 0, type: tank, y: 28}, {index: 1, direction: right, team: radiant, x: 10, type: tank, y: 22}, {index: 2, direction: right, team: radiant, x: 19, type: tank, y: 18}, {index: 3, direction: right, team: radiant, x: 28, type: tank, y: 22}, {index: 4, direction: right, team: radiant, x: 38, type: tank, y: 28}, {index: -1, direction: right, team: dire, x: 19, type: eagle, y: 0}, {index: 0, direction: left, team: dire, x: 0, type: tank, y: 0}, {index: 1, direction: left, team: dire, x: 10, type: tank, y: 6}, {index: 2, direction: left, team: dire, x: 19, type: tank, y: 10}, {index: 3, direction: left, team: dire, x: 28, type: tank, y: 6}, {index: 4, direction: left, team: dire, x: 38, type: tank, y: 0}] +data: "000000000000440000000000004400000000000000000000000044000000000000440000000000004400000000000000000440000000000000000044440000000000000000044000000000000000004400000000005555555555555555555500000000000000000000555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000550000000000000000000000000000000000000055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000440000000000000000440000000000000000000044000000005555555544333333333553333333334455555555555555554433333333355333333333445555555500000000440000000000000000000044000000000000000044000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000550000000000000000000000000000000000000055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055555555555555555555000000000000000000005555555555555555555500000000004400000000000000000440000000000000000044440000000000000000044000000000000000004400000000000044000000000000440000000000000000000000004400000000000044000000000000" diff --git a/src/client/resources/dota/levels/level006.txt b/src/client/resources/dota/levels/level006.txt new file mode 100644 index 0000000..94f2e52 --- /dev/null +++ b/src/client/resources/dota/levels/level006.txt @@ -0,0 +1,2 @@ +points: [{index: -1, direction: right, team: radiant, x: 19, type: eagle, y: 28}, {index: 0, direction: right, team: radiant, x: 2, type: tank, y: 22}, {index: 1, direction: right, team: radiant, x: 9, type: tank, y: 20}, {index: 2, direction: right, team: radiant, x: 19, type: tank, y: 24}, {index: 3, direction: right, team: radiant, x: 29, type: tank, y: 20}, {index: 4, direction: right, team: radiant, x: 36, type: tank, y: 22}, {index: -1, direction: right, team: dire, x: 19, type: eagle, y: 0}, {index: 0, direction: left, team: dire, x: 2, type: tank, y: 6}, {index: 1, direction: left, team: dire, x: 9, type: tank, y: 8}, {index: 2, direction: left, team: dire, x: 19, type: tank, y: 4}, {index: 3, direction: left, team: dire, x: 29, type: tank, y: 8}, {index: 4, direction: left, team: dire, x: 36, type: tank, y: 6}] +data: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005555555544444455555555000000000000000000555555554444445555555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005500000000000000550000000000000000000000550000000000000055000000000000000000000055000000000000005500000000000000000000005500000000000000550000000000000000000000000044000000440000000000000000000000000000004400000044000000000000000333333333333333445500004433333333333333333333333333333344550000443333333333333333333333333333334400440044333333333333333333333333333333440044004433333333333333333333333333333344000055443333333333333333333333333333334400005544333333333333333000000000000000440000004400000000000000000000000000000044000000440000000000000000000000000055000000000000005500000000000000000000005500000000000000550000000000000000000000550000000000000055000000000000000000000055000000000000005500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005555555544444455555555000000000000000000555555554444445555555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" diff --git a/src/common/haxe/ru/m/tankz/bot/BotControl.hx b/src/common/haxe/ru/m/tankz/bot/BotControl.hx index af929e6..ffdc1ec 100644 --- a/src/common/haxe/ru/m/tankz/bot/BotControl.hx +++ b/src/common/haxe/ru/m/tankz/bot/BotControl.hx @@ -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 { + 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]; } }