Actions

This module encodes the game action into a ML friendly format

class luafun.game.action.AbilitySlot(value)[source]

Bases: enum.IntEnum

List all the abilities available to a given hero

Item0 = 0
Item1 = 1
Item2 = 2
Item3 = 3
Item4 = 4
Item5 = 5
Backpack1 = 6
Backpack2 = 7
Backpack3 = 8
Stash1 = 9
Stash2 = 10
Stash3 = 11
Stash4 = 12
Stash5 = 13
Stash6 = 14
Item15 = 15
Item16 = 16
Q = 17
W = 18
E = 19
D = 20
F = 21
R = 22
Ablity6 = 23
Ablity7 = 24
Ablity8 = 25
Ablity9 = 26
Ablity10 = 27
Ablity11 = 28
Ablity12 = 29
Ablity13 = 30
Ablity14 = 31
Ablity15 = 32
Talent11 = 33
Talent12 = 34
Talent21 = 35
Talent22 = 36
Talent31 = 37
Talent32 = 38
Talent41 = 39
Talent42 = 40
class luafun.game.action.Action(value)[source]

Bases: enum.IntEnum

List all the actions available to a hero

Stop = 0
MoveToLocation = 1
MoveDirectly = 2
MoveToUnit = 3
AttackUnit = 4
AttackMove = 5
UseAbility = 6
UseAbilityOnEntity = 7
UseAbilityOnLocation = 8
UseAbilityOnTree = 9
PickUpRune = 10
PickUpItem = 11
DropItem = 12
PurchaseItem = 13
SellItem = 14
DisassembleItem = 15
SetItemCombineLock = 16
SwapItems = 17
Buyback = 18
Glyph = 19
LevelAbility = 20
CourierBurst = 21
CourierReturn = 22
CourierSecret = 23
CourierTakeStash = 24
CourierTransfer = 25
NotUsed1 = 26
NotUsed2 = 27
NotUsed3 = 28
NotUsed4 = 29
NotUsed5 = 30
NotUsed6 = 31
class luafun.game.action.DraftAction(value)[source]

Bases: enum.IntEnum

An enumeration.

EnableDraft = 0
SelectHero = 1
BanHero = 2
Lane = 3
class luafun.game.action.ActionArgument(value)[source]

Bases: enum.IntEnum

An enumeration.

action = 0
vLoc = 1
hUnit = 2
nSlot = 3
iTree = 4
nRune = 5
sItem = 6
ix2 = 7
luafun.game.action.ARG

alias of luafun.game.action.ActionArgument

class luafun.game.action.PlayerAction(act: dict)[source]

Bases: object

Player action builder

Methods

AttackMove

AttackUnit

Buyback

CourierBurst

CourierReturn

CourierSecret

CourierTakeStash

CourierTransfer

DisassembleItem

DropItem

Glyph

LevelAbility

MoveDirectly

MoveToLocation

MoveToUnit

PickUpItem

PickUpRune

PurchaseItem

SellItem

SetItemCombineLock

Stop

SwapItems

UseAbility

UseAbilityOnEntity

UseAbilityOnLocation

UseAbilityOnTree

MoveToLocation(vLocation: Tuple[float, float])[source]
MoveDirectly(vLocation: Tuple[float, float])[source]
MoveToUnit(hUnit: int)[source]
AttackUnit(hUnit: int)[source]
AttackMove(vLocation: Tuple[float, float])[source]
UseAbility(hAbility: int)[source]
UseAbilityOnEntity(hAbility: int, hTarget: int)[source]
UseAbilityOnLocation(hAbility: int, vLoc: Tuple[float, float])[source]
UseAbilityOnTree(hAbility: int, iTree: int)[source]
PickUpRune(nRune: int)[source]
PickUpItem(hItem: int)[source]
DropItem(hItem: int, vLocation: Tuple[float, float])[source]
PurchaseItem(sItemName: str)[source]
SellItem(hItem: int)[source]
DisassembleItem(hItem: int)[source]
SetItemCombineLock(hItem)[source]
SwapItems(nslot: int, index2: int)[source]
Buyback()[source]
Stop()[source]
Glyph()[source]
LevelAbility(nSlot: int)[source]
CourierBurst()[source]
CourierReturn()[source]
CourierSecret()[source]
CourierTakeStash()[source]
CourierTransfer()[source]
class luafun.game.action.DraftBuilder(fac: dict)[source]

Bases: object

Drafting action builder

Methods

ban(hero)

Ban does not work for bots, which makes sense in the case of players wanting to practice annoying hero

select(hero, lane)

Select a hero and assign it to a particular lane

select(hero: int, lane: int)[source]

Select a hero and assign it to a particular lane

ban(hero: int)[source]

Ban does not work for bots, which makes sense in the case of players wanting to practice annoying hero

class luafun.game.action.IPCMessageBuilder(game=None)[source]

Bases: object

Helper to help users build action using code. Mainly used for testing purposes

Methods

build()

Returns the resulting action message

hero_selection(faction)

Prepare to draft a hero for a given faction

player(idx)

Prepare to send an action to a given hero

send()

If game was set, send the message to the game

player(idx: int)luafun.game.action.PlayerAction[source]

Prepare to send an action to a given hero

hero_selection(faction: int)luafun.game.action.DraftBuilder[source]

Prepare to draft a hero for a given faction

build()dict[source]

Returns the resulting action message

send()[source]

If game was set, send the message to the game

luafun.game.action.player_space()[source]

Returns the full action space of a Dota2 bot

Examples

>>> s = player_space()
>>> s.seed(0)
>>> for k, v in s.sample().items():
...     print(k, v)
ActionArgument.action 16
ActionArgument.vLoc [-0.8912799  0.9307819]
ActionArgument.nSlot 14
ActionArgument.sItem 112
ActionArgument.ix2 16
luafun.game.action.team_space(s: int)[source]

Returns the full action space of a Dota2 bot team

Examples

>>> s = team_space(0)
 >>> s.seed(0)
>>> for k, v in s.sample().items():
...     print(k, v)
0 OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])
1 OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])
2 OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])
3 OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])
4 OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])
HS OrderedDict([('ban', 112), ('lane', 0), ('select', 112)])
luafun.game.action.action_space()[source]

Returns the full action space of a Dota2 bots for all teams

Examples

>>> s = action_space()
>>> s.seed(0)
>>> for k, v in s.sample().items():
...     print(k, v)
uid 0
2 {0: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 1: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 2: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 3: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 4: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])}
3 {5: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 6: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 7: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 8: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)]), 9: OrderedDict([(<ActionArgument.action: 0>, 16), (<ActionArgument.vLoc: 1>, array([-0.8912799,  0.9307819], dtype=float32)), (<ActionArgument.nSlot: 3>, 14), (<ActionArgument.sItem: 6>, 112), (<ActionArgument.ix2: 7>, 16)])}