Skip to content

Commit

Permalink
Added movement to ML agent
Browse files Browse the repository at this point in the history
  • Loading branch information
MiscellaneousStuff committed Mar 7, 2022
1 parent 0ecbf13 commit b33d34b
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 2 deletions.
Binary file modified GameplayScripts/__pycache__/actor.cpython-39.pyc
Binary file not shown.
96 changes: 95 additions & 1 deletion GameplayScripts/actor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from lview import *

import math
import pandas as pd
import zerorpc

lview_script_info = {
"script": "Actor",
"author": "MiscellaneousStuff",
Expand All @@ -15,5 +19,95 @@ def lview_save_cfg(cfg):
def lview_draw_settings(game, ui):
pass

prev_x = 0
prev_y = 0
prev_z = 0
multiplier = 3.5 # Obs/Sec
limit_rate = 1 / multiplier
counter = -1

def lview_update(game, ui):
pass
global prev_x, prev_y, prev_z, counter, limit_rate

first_minion_spawn = 60 + 5

min_spawn = 30 - ((game.time - first_minion_spawn) % 30) \
if game.time >= first_minion_spawn \
else first_minion_spawn - game.time

cur_counter = math.floor(game.time / limit_rate)
if cur_counter > counter and game.time >= 5.0:
print(game.time, limit_rate, cur_counter)

# Construct obs
obs = [
game.time,
min_spawn,
game.player.health,
game.player.max_health,
game.player.team,
game.player.armour,
game.player.magic_resist,
game.player.movement_speed,
game.player.is_alive,
game.player.pos.x,
game.player.pos.y,
game.player.pos.z,
0, # is_moving
0, # targetable
0, # invulnerable
0, # recallState
game.player.Q.level,
0, # game.player.Q.cd,
game.player.W.level,
0, # game.player.W.cd,
game.player.E.level,
0, # game.player.E.cd,
game.player.R.level,
0, # game.player.R.cd,
game.player.D.level,
0, # game.player.D.cd,
0, # D spell type
game.player.F.level,
0, # game.player.F.cd,
0, # F spell type
game.player.crit,
game.player.crit_multi,
1, # game.player.level,
200, # game.player.mana,
245.0, # max mana
0, # ability haste
0, # ap
0, # lethality
0, # xp
0, # mp regen
0.8, # game.player.hp_regen,
game.player.base_atk_range,
0, # current gold
0, # total gold
prev_x,
prev_y,
prev_z]

# Infer action
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
move = c.infer(obs)

# Calculate player-relative offsets
x_off = (move % 9) - 4
z_off = (move // 9) - 4
print(move, x_off, z_off)

# Move to inferred location
new_pos = game.player.pos
new_pos.x = new_pos.x + (x_off * 100)
new_pos.z = new_pos.z + (z_off * 100)
game.click_at(False, game.world_to_screen(new_pos))

# Set prev positions for next iteration
prev_x = game.player.pos.x
prev_y = game.player.pos.y
prev_z = game.player.pos.z

counter = cur_counter
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions LView/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Auto Spell::enabled=0
Auto Spell::target_jungle=1
Auto Spell::target_minions=1
Auto Spell::targeting_target=1
Actor::enabled=1
Champion Tracker::enabled=0
Champion Tracker::seconds_to_track=15.000000
Drawings::attack_range=1
Expand Down
2 changes: 1 addition & 1 deletion LView/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Size=569,442
Collapsed=0

[Window][LVIEW by leryss]
Pos=1184,126
Pos=1204,124
Size=690,889
Collapsed=1

Expand Down

0 comments on commit b33d34b

Please sign in to comment.