Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minigame PR #121

Merged
merged 102 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
bc5b1a0
fix npc combat bug
kywch Sep 27, 2023
d132d2b
removed legacy logger, websocket, constraint sample
kywch Oct 16, 2023
47d1283
edited spawn, replay helper packet
kywch Oct 16, 2023
248e08b
added config reset, changes in tile, realm tick update
kywch Oct 16, 2023
92e99d7
WIP: added game pack, the default should match 2.0
kywch Oct 18, 2023
052d19b
quick fixes on ds limits
kywch Oct 18, 2023
f84f7a7
limited to python 3.10 due to pytest bug
kywch Oct 18, 2023
eec3875
fixed pylint
kywch Oct 18, 2023
81f2776
added config for npc attack each other, fixed map gen
kywch Oct 19, 2023
2805983
fixed npc spawn bug
kywch Oct 22, 2023
fa42f98
Merge branch 'clean-up' into game-pack
kywch Oct 22, 2023
c611c53
cfg matched to 2.0
kywch Oct 22, 2023
fc5811b
tweaked game api, added race to center
kywch Oct 26, 2023
e016fbe
fixed done, action validation bugs
kywch Oct 26, 2023
9987801
used task tags
kywch Oct 26, 2023
2971e86
refactored mapgen from fractal, deterministic
kywch Oct 27, 2023
db62da3
added scatter extra resource, fixed fractal save
kywch Oct 30, 2023
eb4885b
allowed flexible team spawn, adaptive difficulty for center race
kywch Oct 31, 2023
10f7875
added unfair fight, tweaked horizon, game_api
kywch Nov 1, 2023
c766b09
refactored mini game tests
kywch Nov 1, 2023
d732815
tweaked game api
kywch Nov 2, 2023
cd0a034
fixed unfair fight difficulty adj, added grass map cfg
kywch Nov 3, 2023
f2e1032
added seize tile, king of the hill, tweaks
kywch Nov 3, 2023
1419a85
fixed pylint error
kywch Nov 3, 2023
bdb7691
tweaked king of hill
kywch Nov 4, 2023
daf6a07
fixed king hill bug
kywch Nov 4, 2023
3646a91
tweaked minigames
kywch Nov 5, 2023
b4a9ade
tweaked unfair fight
kywch Nov 5, 2023
e15fad3
tweaked unfair fight score
kywch Nov 5, 2023
0b75657
tweaked unfair fight
kywch Nov 5, 2023
7dc4df0
tweaked unfair fight
kywch Nov 5, 2023
ea6b419
tweaked unfair fight
kywch Nov 5, 2023
a3a24e8
refactored npc system
kywch Nov 6, 2023
27697ac
bug fix
kywch Nov 6, 2023
b543301
Merge branch 'game-pack' into npc-refactor
kywch Nov 6, 2023
6cc8459
tweaked unfair fight
kywch Nov 6, 2023
30a935d
added quad centers, seize tiles to base predicates, tweaked unfair fight
kywch Nov 7, 2023
2e81fa5
refactored seize target related parts
kywch Nov 7, 2023
03dda70
made dead reward flexible
kywch Nov 7, 2023
1041c63
prep npc for custom spawn
kywch Nov 8, 2023
818ef6d
refactored npc system, added sandwich
kywch Nov 10, 2023
01fac0b
tweaked sandwich
kywch Nov 10, 2023
b5519ba
updated sandwich
kywch Nov 11, 2023
f30076f
tweaked game api, set config
kywch Nov 11, 2023
3454799
config updates
kywch Nov 15, 2023
46b5fdb
added tile seize event log
kywch Nov 15, 2023
f18b1f7
test tile occupy
kywch Nov 15, 2023
852bf0d
test tile occupied
kywch Nov 15, 2023
7a88ed0
finalized tile occupy
kywch Nov 15, 2023
72fe83b
fixed fog safe area
kywch Nov 15, 2023
08f4a99
added observer status
kywch Nov 15, 2023
cbb2820
Merge pull request #3 from kywch/swch-up
kywch Nov 15, 2023
4fd56be
tune game win scores
kywch Nov 16, 2023
cd77c22
tweaked sandwich
kywch Nov 16, 2023
4c0129a
fixed and refactored spawn concurrent
kywch Nov 16, 2023
eb0238e
added team obs, comm together minigame
kywch Nov 17, 2023
0f5532c
tweaked comm together
kywch Nov 19, 2023
d7a03bd
tweaked comm together
kywch Nov 19, 2023
08c5bd9
tweaked comm together
kywch Nov 19, 2023
f5fe8e7
tweaked comm together
kywch Nov 19, 2023
5f078b5
tweaked comm together
kywch Nov 19, 2023
ddf495e
fixed item exchange destroy bug, tweaked grouping eval
kywch Nov 19, 2023
2a5b2e1
added COMM to team battles
kywch Nov 20, 2023
0f6c66f
tweaked ocmm together
kywch Nov 20, 2023
cff9666
tweaked comm together
kywch Nov 20, 2023
994e40e
tweaked comm together
kywch Nov 20, 2023
9ebef60
added radio raid, tweaked game api, optimized obs tile
kywch Nov 21, 2023
5db4943
made comm together larger
kywch Nov 21, 2023
190cb86
tweaked comm config
kywch Nov 21, 2023
d1adf5a
tweaked comm obs n
kywch Nov 22, 2023
42e3e55
tweaked comm together, radio raid
kywch Nov 22, 2023
f4e1dd8
added config system states
kywch Nov 22, 2023
2517596
tweaked radio raid, comm together
kywch Nov 22, 2023
854b455
tweaked resurrect, added test
kywch Nov 23, 2023
90024a9
removed redundunt tile obs compuation
kywch Nov 23, 2023
94c33e4
refectored observation to reuse gym obs, action targets, cythonized f…
kywch Nov 25, 2023
3951ffb
made gym obs immutable
kywch Nov 25, 2023
11eb31f
bug fix, optimized action target clear, get comm obs
kywch Nov 26, 2023
84dab99
put all minigames eval in base_predicates
kywch Nov 27, 2023
2150612
changed immortal npc type to -1, mini game tweaks
kywch Nov 29, 2023
b7cb0d4
tweaked comm together
kywch Nov 29, 2023
34aad7e
tweaked comm together
kywch Nov 29, 2023
4b087ea
allowed int player health inc, tweaked mini games
kywch Nov 30, 2023
f9cf7ad
few tweaks
kywch Nov 30, 2023
cd39846
tweaked radio raid
kywch Dec 1, 2023
8f7444b
tamed hash embedding
kywch Dec 1, 2023
e720089
fixed task hash embedding
kywch Dec 2, 2023
4dbb118
bump up pettingzoo, gymnasium and conform to the new apis
kywch Feb 26, 2024
cc92058
changed test python ver
kywch Feb 26, 2024
e1d1929
add back py for pytest benchmark
kywch Feb 26, 2024
1ee9539
test python 3.8
kywch Feb 26, 2024
6d54bc3
removed unnecessary comments
kywch Feb 27, 2024
6530bc2
made reset faster, fixed pettingzoo error
kywch Feb 28, 2024
47bee74
gained some speed
kywch Feb 28, 2024
f64a156
api clean up
kywch Feb 28, 2024
430521a
quick fixes
kywch Feb 28, 2024
d1153fb
quick changes
kywch Mar 1, 2024
c554cdf
paused testing in 3.11
kywch Mar 1, 2024
6016352
made spawn_dangers FIFO
kywch Mar 4, 2024
a79a375
game balacing tweaks
kywch Mar 6, 2024
7cfd740
got rid of mapping proxy obs
kywch Mar 8, 2024
2f1fc7b
incorporated feedback
kywch Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pylint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# Randomly hitting TypeError: object int can't be used in 'await' expression in 3.11
# So, excluding 3.11 for now
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
Expand All @@ -16,8 +18,9 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade pip setuptools wheel cython
pip install .
python setup.py build_ext --inplace
- name: Running unit tests
run: pytest
- name: Analysing the code with pylint
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
# C extensions, cython
*.so
*.c

# Distribution / packaging
.Python
Expand Down Expand Up @@ -126,13 +127,14 @@ celerybeat.pid

# Environments
.env
.venv
.*venv
env/
venv/
ENV/
env.bak/
venv.bak/


# Spyder project settings
.spyderproject
.spyproject
Expand Down
59 changes: 29 additions & 30 deletions nmmo/core/action.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# CHECK ME: Should these be fixed as well?
# pylint: disable=no-method-argument,unused-argument,no-self-argument,no-member

from enum import Enum, auto
import numpy as np
from nmmo.core.observation import Observation

from nmmo.lib import utils
from nmmo.lib.utils import staticproperty
from nmmo.systems.item import Stack
from nmmo.lib.log import EventCode
from nmmo.lib.event_code import EventCode


class NodeType(Enum):
Expand Down Expand Up @@ -48,7 +45,7 @@ def leaf():
def N(cls, config):
return len(cls.edges)

def deserialize(realm, entity, index, obs: Observation):
def deserialize(realm, entity, index: int, obs):
return index

class Fixed:
Expand Down Expand Up @@ -76,7 +73,7 @@ def hook(config):
action.init(config)
for args in action.edges: # pylint: disable=not-an-iterable
args.init(config)
if not 'edges' in args.__dict__:
if not "edges" in args.__dict__:
continue
for arg in args.edges:
arguments.append(arg)
Expand All @@ -92,7 +89,7 @@ def n():
# pylint: disable=invalid-overridden-method
@classmethod
def edges(cls, config):
'''List of valid actions'''
"""List of valid actions"""
edges = [Move]
if config.COMBAT_SYSTEM_ENABLED:
edges.append(Attack)
Expand Down Expand Up @@ -124,12 +121,15 @@ def call(realm, entity, direction):
realm.map.tiles[r_new, c_new].impassible:
return

if entity.status.freeze > 0:
# ALLOW_MOVE_INTO_OCCUPIED_TILE only applies to players, NOT npcs
if entity.is_player and not realm.config.ALLOW_MOVE_INTO_OCCUPIED_TILE and \
realm.map.tiles[r_new, c_new].occupied:
return

entity.row.update(r_new)
entity.col.update(c_new)
if entity.status.freeze > 0:
return

entity.set_pos(r_new, c_new)
realm.map.tiles[r, c].remove_entity(ent_id)
realm.map.tiles[r_new, c_new].add_entity(entity)

Expand Down Expand Up @@ -165,7 +165,7 @@ class Direction(Node):
def edges():
return [North, South, East, West, Stay]

def deserialize(realm, entity, index, obs: Observation):
def deserialize(realm, entity, index: int, obs):
return deserialize_fixed_arg(Direction, index)

# a quick helper function
Expand All @@ -176,7 +176,7 @@ def deserialize_fixed_arg(arg, index):
val = min(index, len(arg.edges)-1)
return arg.edges[val]

# if index is not int, it's probably already deserialized
# if index is not int, it"s probably already deserialized
if index not in arg.edges:
return None # so that the action will be discarded
return index
Expand Down Expand Up @@ -243,26 +243,26 @@ def call(realm, entity, style, target):
target.history.time_alive < immunity:
return None

#Check if self targeted
if entity.ent_id == target.ent_id:
#Check if self targeted or target already dead
if entity.ent_id == target.ent_id or not target.alive:
return None

#Can't attack out of range
#Can"t attack out of range
if utils.linf_single(entity.pos, target.pos) > style.attack_range(config):
return None

#Execute attack
entity.history.attack = {}
entity.history.attack['target'] = target.ent_id
entity.history.attack['style'] = style.__name__
entity.history.attack["target"] = target.ent_id
entity.history.attack["style"] = style.__name__
target.attacker = entity
target.attacker_id.update(entity.ent_id)

from nmmo.systems import combat
dmg = combat.attack(realm, entity, target, style.skill)

if style.freeze and dmg > 0:
target.status.freeze.update(config.COMBAT_FREEZE_TIME)
# if style.freeze and dmg > 0:
# target.status.freeze.update(config.COMBAT_FREEZE_TIME)

# record the combat tick for both entities
# players and npcs both have latest_combat_tick in EntityState
Expand All @@ -277,7 +277,7 @@ class Style(Node):
def edges():
return [Melee, Range, Mage]

def deserialize(realm, entity, index, obs: Observation):
def deserialize(realm, entity, index: int, obs):
return deserialize_fixed_arg(Style, index)

class Target(Node):
Expand All @@ -287,7 +287,7 @@ class Target(Node):
def N(cls, config):
return config.PLAYER_N_OBS + cls.noop_action

def deserialize(realm, entity, index: int, obs: Observation):
def deserialize(realm, entity, index: int, obs):
if index >= len(obs.entities.ids):
return None
return realm.entity_or_none(obs.entities.ids[index])
Expand Down Expand Up @@ -329,7 +329,7 @@ class InventoryItem(Node):
def N(cls, config):
return config.INVENTORY_N_OBS + cls.noop_action

def deserialize(realm, entity, index: int, obs: Observation):
def deserialize(realm, entity, index: int, obs):
if index >= len(obs.inventory.ids):
return None
return realm.items.get(obs.inventory.ids[index])
Expand Down Expand Up @@ -508,10 +508,9 @@ class MarketItem(Node):
def N(cls, config):
return config.MARKET_N_OBS + cls.noop_action

def deserialize(realm, entity, index: int, obs: Observation):
def deserialize(realm, entity, index: int, obs):
if index >= len(obs.market.ids):
return None

return realm.items.get(obs.market.ids[index])

class Buy(Node):
Expand All @@ -532,7 +531,7 @@ def call(realm, entity, item):
assert entity.alive, "Dead entity cannot act"
assert entity.is_player, "Npcs cannot buy an item"
assert item.quantity.val > 0, "Item quantity cannot be 0" # indicates item leak
assert item.equipped.val == 0, 'Listed item must not be equipped'
assert item.equipped.val == 0, "Listed item must not be equipped"

if not realm.config.EXCHANGE_SYSTEM_ENABLED:
return
Expand Down Expand Up @@ -601,8 +600,8 @@ def call(realm, entity, item, price):
def init_discrete(values):
classes = []
for i in values:
name = f'Discrete_{i}'
cls = type(name, (object,), {'val': i})
name = f"Discrete_{i}"
cls = type(name, (object,), {"val": i})
classes.append(cls)

return classes
Expand All @@ -628,21 +627,21 @@ def index(cls, price):
def edges():
return Price.classes

def deserialize(realm, entity, index, obs: Observation):
def deserialize(realm, entity, index: int, obs):
return deserialize_fixed_arg(Price, index)

class Token(Node):
argType = Fixed

@classmethod
def init(cls, config):
Token.classes = init_discrete(range(config.COMMUNICATION_NUM_TOKENS))
Token.classes = init_discrete(range(1, config.COMMUNICATION_NUM_TOKENS+1))

@staticproperty
def edges():
return Token.classes

def deserialize(realm, entity, index, obs: Observation):
def deserialize(realm, entity, index: int, obs):
return deserialize_fixed_arg(Token, index)

class Comm(Node):
Expand Down
Loading
Loading