Skip to content

2 main things: score counter and game simulator with names and scores #3

Open
Fabbernat wants to merge 57 commits into
DylanHannaScience:mainfrom
Fabbernat:main
Open

2 main things: score counter and game simulator with names and scores #3
Fabbernat wants to merge 57 commits into
DylanHannaScience:mainfrom
Fabbernat:main

Conversation

@Fabbernat

Copy link
Copy Markdown

Refactor Settings and GameMode handling for better consistency and Enum support

  • Converted GameMode to an Enum for consistency with MapSizes and MapTypes, allowing the use of .name attributes.
  • Updated Settings to ensure GAME_MODE and MAP_SIZE are compatible with .name-based access.
  • Enhanced the
    un_game.py script to handle map_settings dynamically using .name for Enum members and raw values where appropriate.
  • Fixed the ModuleNotFoundError by addressing Python package structure and import paths in the polytopia_game module.

This refactor improves readability, robustness, and consistency across game settings.

Fix: Properly initialize and populate players in the game

  • Ensured that the self.players list is properly initialized with player names.
  • Corrected the issue where player_scores was not populated due to an empty self.players list.
  • Added a check to verify that self.players contains valid player names before assigning scores.
  • Ensured that player names are shuffled and linked to the players correctly for dynamic gameplay.
  • Improved the readability and robustness of the run() method by ensuring proper initialization and shuffling logic.

This resolves the issue where player_scores was not populated, leading to empty results in the game run.

Add Pillow dependency and update map_renderer.py imports
Add Pillow dependency and update map_renderer.py imports
---
Index: polytopia_score_counter/rewards.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/polytopia_score_counter/rewards.py b/polytopia_score_counter/rewards.py
--- a/polytopia_score_counter/rewards.py	(revision 76cc9a7)
+++ b/polytopia_score_counter/rewards.py	(date 1736350762769)
@@ -52,4 +52,7 @@
     if action == "discover_fog":
         return 5

+    if action == "park":
+        return 250
+
     return 0  # Default reward for neutral actions
Index: polytopia_score_counter/actions.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/polytopia_score_counter/actions.py b/polytopia_score_counter/actions.py
--- a/polytopia_score_counter/actions.py	(revision 76cc9a7)
+++ b/polytopia_score_counter/actions.py	(date 1736351187218)
@@ -11,5 +11,22 @@
     "gain_territory",
     "lose_territory",
     "research_tech",
-    "discover_fog"
+    "discover_fog",
+    "park",
+]
+
+_2D_ACTIONS = [
+    {"action": "train_unit", "unit_type": "archer"},
+    {"action": "lose_unit", "unit_type": "warrior"},
+    {"action": "upgrade_city", "city_population_gain": 3},
+    {"action": "place_structure", "structure": "monument"},
+    {"action": "capture_city", "city_population_gain": 1},
+    {"action": "lose_city", "city_population_loss": 2},
+    {"action": "gain_territory"},
+    {"action": "lose_territory"},
+    {"action": "research_tech", "tech_tier": 1},
+    {"action": "research_tech", "tech_tier": 2},
+    {"action": "research_tech", "tech_tier": 3},
+    {"action": "discover_fog"},
+    {"action": "park"},
 ]
Index: main.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/main.py b/main.py
--- a/main.py	(revision 76cc9a7)
+++ b/main.py	(date 1736351187218)
@@ -1,18 +1,20 @@
-# main.py
-
 from polytopia_score_counter.rewards import calculate_reward
-from polytopia_score_counter.actions import ACTIONS
+from polytopia_score_counter.actions import _2D_ACTIONS
+

 def main():
-    # Test reward calculations
-    print("Reward for training an archer:", calculate_reward("train_unit", unit_type="archer"))
-    print("Reward for losing a warrior:", calculate_reward("lose_unit", unit_type="warrior"))
-    print("Reward for upgrading a city with 3 population gain:", calculate_reward("upgrade_city", city_population_gain=3))
-    print("Reward for placing a monument:", calculate_reward("place_structure", structure="monument"))
-    print("Reward for researching a tier 2 technology:", calculate_reward("research_tech", tech_tier=2))
-    print("Reward for discovering a fog tile:", calculate_reward("discover_fog"))
-    print("Reward for gaining a territory tile:", calculate_reward("gain_territory"))
-    print("Reward for losing a city with 2 population:", calculate_reward("lose_city", city_population_loss=2))
+    score = 0
+
+    # Loop through each action and calculate the reward
+    for action_info in _2D_ACTIONS:
+        action = action_info["action"]
+        # Call calculate_reward dynamically with the appropriate arguments
+        reward = calculate_reward(action, **{key: value for key, value in action_info.items() if key != "action"})
+        score += reward
+        print(f"Reward for {action}: {reward}")
+
+    print(f'Total score: {score}')
+

 if __name__ == "__main__":
     main()
…um support

- Converted GameMode to an Enum for consistency with MapSizes and MapTypes, allowing the use of .name attributes.
- Updated Settings to ensure GAME_MODE and MAP_SIZE are compatible with .name-based access.
- Enhanced the 
un_game.py script to handle map_settings dynamically using .name for Enum members and raw values where appropriate.
- Fixed the ModuleNotFoundError by addressing Python package structure and import paths in the polytopia_game module.

This refactor improves readability, robustness, and consistency across game settings.
- Ensured that the `self.players` list is properly initialized with player names.
- Corrected the issue where `player_scores` was not populated due to an empty `self.players` list.
- Added a check to verify that `self.players` contains valid player names before assigning scores.
- Ensured that player names are shuffled and linked to the players correctly for dynamic gameplay.
- Improved the readability and robustness of the `run()` method by ensuring proper initialization and shuffling logic.

This resolves the issue where `player_scores` was not populated, leading to empty results in the game run.
@DylanHannaScience

Copy link
Copy Markdown
Owner

Hello!
Thanks so much for this amazing MR, I can see you've put a lot of thought into it 😁
As you can probably tell, I'm not really maintaining this code (I actually thought this was a private repo 😅), so I'm more than happy to hand the repo over to you if you want to take it and become the owner.

It's really cool to see that you saw some value in this project and wanted to contribute 😄

Fabbernat and others added 24 commits January 11, 2025 12:59
…Where to put the Views, models, controllers? WHeret to put static files like css and img? Is there a wwwroot or static or templates folder?
- Set up a Flask app to serve web pages.
- Added routes for:
  - Home (`/`)
  - Privacy (`/privacy`)
  - Dashboard (`/dashboard`)
  - About (`/about`)
  - Settings (`/settings`)
  - Hall of Fame (`/hall_of_fame`)
  - Throne Room (`/throne_room`)
- Created navigation between pages to enable smooth browsing.
- Implemented basic HTML responses to test routing functionality.

This commit lays the foundation for serving dynamic content and creating a user-friendly web interface.
- Add `vegallapot(n)`: Checks if the game has reached a terminal state.
- Add `hasznossag(n)`: Evaluates game states based on city and unit count.
- Add `n_szomszedai(n)`: Generates possible next states for the current player.
- Basic mechanics include unit training and attacking.
- Lays groundwork for reinforcement learning integration.
…xt, no errors or exeptions thrown in this version
Updated README to reflect changes in contributions and added information about the Java console app.
fabbernatvasvari and others added 28 commits January 21, 2026 16:48
…spawn. It does not always work, but it gives decent results when succeeds
…e loop, fix that. Then, add shallow water, ruins and valid village spawns
…WW runs into infinite loop, fix that. Then, add shallow water, ruins and valid village spawns
…n any more on ocean. Mountains do. This patch increased forest spawn rate.
…flow now seamlessly integrates with the console app. Both apps can be controlled from console now. Also extracted a lot of repetitive code into methods. So overall the code quality is much better too.
Big improvements on the desktop app. The desktop app's control flow now seamlessly integrates with the console app. Both apps can be controlled from console now. Also extracted a lot of repetitive code into methods. So overall the code quality is much better too.
Updated links to point to the correct frontend repository.
…s, Lakes, Continents, and Archipelagos.

Added images and descriptions for various map types including Drylands, Lakes, Continents, and Archipelagos. Updated contributions section with details on terrain generation and score counter modules.
Updated README.md with additional map types and contributions.
Updated descriptions for various map types and added insights.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants