Skip to content

Commit

Permalink
Merge branch 'release/1.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed May 15, 2022
2 parents 1a4c98c + 0573806 commit 513c519
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. mac/linux/windows]
- Version [e.g. 1.3.6]
- Version [e.g. 1.3.7]

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.3.6)
project(Griddly VERSION 1.3.7)

set(BINARY ${CMAKE_PROJECT_NAME})

Expand Down
2 changes: 1 addition & 1 deletion bindings/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace griddly {

PYBIND11_MODULE(python_griddly, m) {
m.doc() = "Griddly python bindings";
m.attr("version") = "1.3.6";
m.attr("version") = "1.3.7";

#ifndef NDEBUG
spdlog::set_level(spdlog::level::debug);
Expand Down
13 changes: 11 additions & 2 deletions bindings/wrapper/GameWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,21 @@ class Py_GameWrapper {
bool terminated = false;
py::dict info{};

for (int p = 0; p < playerSize; p++) {
std::vector<uint32_t> playerIdx;

for (uint32_t p = 0; p < playerSize; p++) {
playerIdx.push_back(p);
}

std::shuffle(playerIdx.begin(), playerIdx.end(), gameProcess_->getGrid()->getRandomGenerator()->getEngine());

for (int i = 0; i < playerSize; i++) {
auto p = playerIdx[i];
std::string actionName;
std::vector<int32_t> actionArray;
auto pStr = (int32_t*)stepArrayInfo.ptr + p * playerStride;

bool lastPlayer = p == (playerSize - 1);
bool lastPlayer = i == (playerSize - 1);

switch (actionSize) {
case 1:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Chris Bamford'

# The full version, including alpha/beta/rc tags
release = '1.3.6'
release = '1.3.7'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion js/jiddly-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jiddly-app",
"version": "1.3.6",
"version": "1.3.7",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'):

setup(
name='griddly',
version="1.3.6",
version="1.3.7",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
37 changes: 37 additions & 0 deletions python/tests/gdy/simultaneous_player_actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Version: "0.1"
Environment:
Name: test
Observers:
Vector:
IncludePlayerId: true
Block2D:
TileSize: [10,10]
Player:
AvatarObject: avatar
Count: 2
Levels:
- |
. . . . .
. . . . .
. . . . .
. a1 . a2 .
. . . . .
. . . . .
Actions:
- Name: move
Behaviours:
- Src:
Object: avatar
Commands:
- mov: _dest
Dst:
Object: _empty

Objects:
- Name: avatar
MapCharacter: a
Observers:
Block2D:
- Shape: square

46 changes: 46 additions & 0 deletions python/tests/player_simultaneous_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
import gym
from griddly import GymWrapperFactory, gd

from collections import Counter


@pytest.fixture
def test_name(request):
return request.node.name


def build_test_env(test_name, yaml_file, **kwargs):
wrapper_factory = GymWrapperFactory()

wrapper_factory.build_gym_from_yaml(
test_name,
yaml_file,
**kwargs,
)

env = gym.make(f"GDY-{test_name}-v0")
env.reset()
return env


def test_simultaneous_actions_stochasticity(test_name):
"""
Using observers in 0.1 version of GDY
"""
env = build_test_env(test_name, "tests/gdy/simultaneous_player_actions.yaml", global_observer_type=gd.ObserverType.VECTOR,
player_observer_type=gd.ObserverType.VECTOR)

possible_obs_hashes = Counter()

for i in range(100):
obs, reward, done, info = env.step([3, 1])
obs_hash_player_1 = hash(tuple(obs[0].flatten()))
obs_hash_player_2 = hash(tuple(obs[1].flatten()))
possible_obs_hashes[obs_hash_player_1] += 1
possible_obs_hashes[obs_hash_player_2] += 1
env.reset()

assert len(possible_obs_hashes) == 4


3 changes: 3 additions & 0 deletions src/Griddly/Core/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ std::unordered_map<uint32_t, int32_t> Grid::performActions(uint32_t playerId, st

spdlog::trace("Tick {0}", *gameTicks_);

// Have to add some non-determinism here for multi-agent games so player 1 doesn't always benefit
std::shuffle(std::begin(actions), std::end(actions), randomGenerator_->getEngine());

for (const auto& action : actions) {
// Check if action is delayed or durative
if (action->getDelay() > 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/Griddly/Core/Util/RandomGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ const float RandomGenerator::sampleFloat(float min, float max) {
return dist(randomGenerator_);
}

std::mt19937& RandomGenerator::getEngine() {
return randomGenerator_;
}


} // namespace griddly
2 changes: 2 additions & 0 deletions src/Griddly/Core/Util/RandomGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class RandomGenerator {

virtual const float sampleFloat(float min, float max);

virtual std::mt19937& getEngine();

private:
// Random number generator for the grid and associated objects
std::mt19937 randomGenerator_ = std::mt19937();
Expand Down

0 comments on commit 513c519

Please sign in to comment.