glmcdona / LuxPythonEnvGym

Matching python environment code for Lux AI 2021 Kaggle competition, and a gym interface for RL models.
MIT License
73 stars 38 forks source link

Simulation of replays, adding more pytests, bug fixes #81

Closed nosound2 closed 2 years ago

nosound2 commented 2 years ago

Hello, @glmcdona , @royerk , @StoneT2000 please take a look at this pull request, it includes the following changes (in order of appearance in the compare).

In summary, it allows replaying episodes downloaded from Kaggle leaderboard, and checks that the states are the same. Added the corresponding pytest for 7 replays. And fixed some bugs encountered along the way.

  1. Adding a replay argument to class Agent which is a full episode replay as can be downloaded from https://www.kaggle.com/robga/simulations-episode-scraper-match-downloader If a replay is present, this default agent will answer with the actions from the replay.
  2. Adding replay_validate argument to class LuxEnvironment and class MatchController. In run_to_next_observation method after each turn it will validate that the game state is exactly identical to the state provided in the replay. This is the main thing in this pull request, it allows strong testing of the engine.
  3. Adding method run_no_learn to class LuxEnvironment which will run an episode, but it only works in case there are no learning agents. It is needed to run two replay agents as a simulation.
  4. A small bugfix in constants.py
  5. In class Game cutting out a new process_updates function, which now can not only assign updates but also validate updates. This list of updates is what we get in the replays, and process_updates is where we check that the map state is exactly the same.
  6. Cosmetic changes in action_from_command. Needed to call it with different arguments, and some more minor changes there.
  7. Changed default argument {"wood": 0, "uranium": 0, "coal": 0} to None. It is a bugfix, in some cases the same cargo dictionary was shared between couple of units. Remember, not a good idea to use lists and dictionaries as default arguments.
  8. In spawn_city_tile changed city_ids_found from set to a list. This was a nasty bug which produces randomness in tests, because sets are not guaranteed to keep order.
  9. In class Cart method turn removed a duplicated cooldown subtraction.
  10. Added 7 replays for tests in folder replays_for_tests.
  11. Added new pytests family in function test_run_replay.

Let me know if something looks wrong!

StoneT2000 commented 2 years ago

lll take a look when i can

nosound2 commented 2 years ago

Points 7 and 9 influence the training.

Point 9 is a significant bug in carts, which makes them move much slower.

Point 7 is even more serious, it makes the first two initial units (from the two teams) to share the cargo. This is a major bug. I think the next units are already created with their own separate cargos.

royerk commented 2 years ago

Could you add attrs to setup.py please? (for some reason I had to pip install pytest even though it's in the setup) The other tests are based on unittest, running pytest in the directory will trigger all tests :-)

Tests look good :rocket: !

nosound2 commented 2 years ago

Could you add attrs to setup.py please? (for some reason I had to pip install pytest even though it's in the setup) The other tests are based on unittest, running pytest in the directory will trigger all tests :-)

Tests look good 🚀 !

What is attrs? Can't find it in the code.

royerk commented 2 years ago

Hm, my bad I think it's installed by pytest automatically. Sorry about that :sweat_smile: