16 Commits

Author SHA1 Message Date
fc9f98aa3d feat(backend): integrate dual AI strategies with conditional switching and A* pathfinding
- Add imports for server0 and server1 modules
- Modify start_game, plan_next_actions, and game_over to invoke both strategies
- Implement dynamic strategy selection based on player prison counts
- Add A* pathfinding with danger weights for attacking players, including safe/dangerous position calculations and opponent avoidance
- Update traditional pathfinding for defenders and flag carriers in enemy territory
- Include binary updates to .DS_Store files (likely system artifacts)
2025-12-28 13:39:06 +08:00
6cae6a2ad8 fix(backend): handle None destination in plan_next_actions to prevent errors
Previously, the code assumed dest was always a valid tuple, potentially causing errors if dest was None. Added a check to guide to current position when dest is None, ensuring safe fallback behavior.
2025-12-28 12:37:39 +08:00
033979c663 feat: enhance AI planning logic and add unit tests for Map class
- Modified plan_next_actions in server.py to remove selected positions from regard_list, preventing reuse in subsequent planning steps for better AI decision-making
- Added comprehensive unit tests in test_map.py for enemy_to_walls and choose_enemy functions to ensure correct behavior and distance calculations in the game map
2025-12-28 12:32:53 +08:00
5e76bb2452 feat(ai): add Map class for pathfinding and speed up world updates
- Remove unused `random` import and introduce `collections` for BFS queue.
- Decrease `GameMap` update interval from 1000 ms to 1 ms and lower `update_threshold` from 100 to 1 for near‑real‑time world state.
- Add thread‑safe lock, timestamp tracking, and rename `player_to_flag_assignments` to `player_to_flag_assign`.
- Introduce `my_side_is_left` flag to differentiate safe‑zone logic.
- Implement new `Map` class:
  * Stores grid, edges, and safe‑zone status.
  * Updates grid with walls, allies, enemies, and safe‑zone handling.
  * Computes adjacency edges respecting obstacles.
  * Provides `guideance` (BFS) to obtain the first movement direction towards a target.
- Overall refactor improves AI flag‑picking speed and decision accuracy.
2025-12-28 11:38:50 +08:00
bcca96e73f refactor(server): tighten flag thresholds, add movement log
Adjusted range checks for flag handling:
- Changed `lentime<=5` to `lentime<6`.
- Updated `lentime<=10` to `lentime<12`.
- Modified `lentime<8` to `lentime<6`.

These tweaks refine the decision logic for flag acquisition, ensuring more consistent behavior at boundary values.

Added a debug print statement to log each player's current position and target destination, aiding in troubleshooting movement decisions.
2025-12-28 10:08:09 +08:00
e84aa30202 feat: refine map update logic and add side‑aware path helpers
- Decrease `GameMap` update interval from 10 ms to 1 ms and lower `update_threshold` to 1 for more responsive state syncing.
- Remove unused `random` import.
- Adjust safe‑zone detection to offset player position based on team side.
- Restrict enemy marking to opponent side, preventing incorrect obstacle placement.
- Update edge generation logic to correctly handle safe‑zone and opponent cells.
- Add `closest` and `closest_in_range` helper methods that compute nearest positions while respecting team side boundaries.
- Introduce global `my_side_is_left` handling within `Map.update` for side‑dependent calculations.

These changes improve map accuracy, AI pathfinding, and overall game performance.
2025-12-28 09:48:31 +08:00
99fc0158b0 feat: add fallback to pretend_list in plan_next_actions logic
Extend the decision flow in `plan_next_actions` to consider the `pretend_list` when no suitable
target is found in `regard_list` within the 10‑unit time threshold. The new fallback selects a
destination from `pretend_list` if its travel time is under 8 units, improving target
selection robustness.
2025-12-28 09:39:20 +08:00
942bb1580d feat(map): add side‑aware closest_in_range and refine enemy marking logic
- Removed leftover debug `print` statement.
- Updated enemy marking to consider team side, preventing marking of opponents on the opposite side.
- Introduced `closest_in_range` method to find the nearest position while respecting map side boundaries.
- Integrated the new method into `plan_next_actions` to select destinations based on distance thresholds for flag carriers and assigned players.
- Added handling for `my_targets` via a dedicated `targets_list`.
2025-12-28 09:35:05 +08:00
99ab005021 feat(ctf): increase map update frequency and enhance path planning
- Reduce `show_gap_in_msec` from 10 ms to 1 ms and `update_threshold` from 10 to 1 for faster game state updates.
- Use `global my_side_is_left` in `Map.update` and adjust safe‑zone calculation with a one‑cell offset, fixing zone detection.
- Correct edge generation logic to properly handle safe and unsafe zones.
- Add tracking of enemy players without flags (`pretend_list`) and own flags (`protect_list`) to broaden target options.
- Implement fallback destination selection: prioritize enemy flags, then enemy players, then own flags.
- Clean up stray debug prints and minor formatting issues.
2025-12-27 23:30:22 +08:00
b038e5ac29 refactor(game): add Map.closest and improve flag assignment logic
- Introduced `Map.closest` to encapsulate nearest‑position search and replaced duplicated distance loops in flag targeting.
- Updated flag assignment to consider enemy players carrying flags and to use the new helper for both ally and enemy flag selection.
- Cleaned up unused imports and renamed `mypolicy` to `mypolicy.py` for clarity.
- Adjusted frontend `game_config.json` to use new team identifiers, increase players to 3, raise flag count to 9, and enable random flag placement.
2025-12-27 22:10:46 +08:00
8ef3f65ce9 modified: CTF/backend/mypolicy 2025-12-27 20:54:43 +08:00
2593d31346 feat(ctf): add backend policy module with pathfinding logic
Introduce a new `CTF/backend/mypolicy` Python module that implements a comprehensive game policy for the capture‑the‑flag bot. The file defines a global world model, thread‑safe state handling, and a `Map` class that builds a grid representation of the game map, generates traversable edges, and provides BFS‑based `guideance` and `length` methods for pathfinding and distance calculation. This policy enables the bot to make informed movement decisions based on safe zones, walls, allies, and enemies. Additionally, macOS `.DS_Store` placeholder files were added to the repository.
2025-12-27 20:54:40 +08:00
c046cfab54 feat(backend): add Map class with BFS pathfinding and faster updates
- Reduce `GameMap` update interval from 1000 ms to 10 ms for more responsive gameplay.
- Introduce thread lock, update thresholds, and player‑to‑flag tracking variables for safer concurrent access.
- Add `my_side_is_left` flag to determine team orientation.
- Implement new `Map` class:
  * Builds a grid representation of the world, marking walls, enemy flag carriers, and allies.
  * Generates adjacency lists (`edge`) respecting safe‑zone rules.
  * Provides `guideance` method that runs a BFS (unit‑weight Dijkstra) to compute the shortest path and returns the first movement direction via `world.get_direction`.
- Import `collections` for efficient deque usage.
- Include compiled `.pyc` for the new module.

These changes enable the policy to make quick, informed movement decisions based on real‑time map analysis.
2025-12-27 18:10:12 +08:00
86ccecc939 feat(ctf): add Chinese README and initial Python policy implementation
Add a comprehensive Chinese README (README‑cn.md) that explains the Capture‑the‑Flag game rules, setup instructions, and participant tasks.
Introduce a new backend script (backend/mypolicy.py) providing a basic world model, start_game, and plan_next_actions functions with simple flag‑assignment logic, serving as a starter implementation for the CTF challenge. This documentation and starter code help participants understand and begin developing their own algorithms.
2025-12-27 16:06:21 +08:00
d27e376e11 new file: .DS_Store
new file:   CTF/.ipynb_checkpoints/fixed_map_example-checkpoint.png
	new file:   CTF/.ipynb_checkpoints/random_map_example-checkpoint.png
	new file:   CTF/CTF/README.md
	new file:   CTF/CTF/backend/example_init.json
	new file:   CTF/CTF/backend/example_plan_next_actions.json
	new file:   CTF/CTF/backend/lib/game_engine.py
	new file:   CTF/CTF/backend/main.ipynb
	new file:   CTF/CTF/backend/pick_closest_flag.py
	new file:   CTF/CTF/backend/pick_flag_ai.py
	new file:   CTF/CTF/backend/python_tutorial.ipynb
	new file:   CTF/CTF/backend/start.sh
	new file:   CTF/CTF/backend/test_lib.ipynb
	new file:   CTF/CTF/fixed_map_example.png
	new file:   CTF/CTF/frontend/assets/characters.png
	new file:   CTF/CTF/frontend/assets/characters_red_flag.png
	new file:   CTF/CTF/frontend/assets/characters_yellow_flag.png
	new file:   CTF/CTF/frontend/assets/red_flag_16_16.png
	new file:   CTF/CTF/frontend/assets/red_flag_32_32.png
	new file:   CTF/CTF/frontend/assets/tilemap.json
	new file:   CTF/CTF/frontend/assets/tilemap.tmx
	new file:   CTF/CTF/frontend/assets/tiles.png
	new file:   CTF/CTF/frontend/assets/yellow_flag_16_16.png
	new file:   CTF/CTF/frontend/assets/yellow_flag_32_32.png
	new file:   CTF/CTF/frontend/game_config.json
	new file:   CTF/CTF/frontend/index.html
	new file:   CTF/CTF/frontend/phaser.js
	new file:   CTF/CTF/frontend/project.config
	new file:   CTF/CTF/frontend/src/assets.js
	new file:   CTF/CTF/frontend/src/gameObjects/Flag.js
	new file:   CTF/CTF/frontend/src/gameObjects/Player.js
	new file:   CTF/CTF/frontend/src/main.js
	new file:   CTF/CTF/frontend/src/scenes/Boot.js
	new file:   CTF/CTF/frontend/src/scenes/Game.js
	new file:   CTF/CTF/frontend/src/scenes/GameOver.js
	new file:   CTF/CTF/frontend/src/scenes/Preloader.js
	new file:   CTF/CTF/frontend/start.sh
	new file:   CTF/CTF/random_map_example.png
	new file:   CTF/README.md
	new file:   CTF/backend/.ipynb_checkpoints/main-checkpoint.ipynb
	new file:   CTF/backend/.ipynb_checkpoints/pick_closest_flag-checkpoint.py
	new file:   CTF/backend/.ipynb_checkpoints/pick_flag_ai-checkpoint.py
	new file:   CTF/backend/.ipynb_checkpoints/python_tutorial-checkpoint.ipynb
	new file:   CTF/backend/.ipynb_checkpoints/start-checkpoint.sh
	new file:   CTF/backend/.ipynb_checkpoints/test_lib-checkpoint.ipynb
	new file:   CTF/backend/example_init.json
	new file:   CTF/backend/example_plan_next_actions.json
	new file:   CTF/backend/lib/__pycache__/game_engine.cpython-313.pyc
	new file:   CTF/backend/lib/game_engine.py
	new file:   CTF/backend/main.ipynb
	new file:   CTF/backend/pick_closest_flag.py
	new file:   CTF/backend/pick_flag_ai.py
	new file:   CTF/backend/python_tutorial.ipynb
	new file:   CTF/backend/start.sh
	new file:   CTF/backend/test_lib.ipynb
	new file:   CTF/fixed_map_example.png
	new file:   CTF/frontend/.ipynb_checkpoints/game_config-checkpoint.json
	new file:   CTF/frontend/assets/.ipynb_checkpoints/tilemap-checkpoint.json
	new file:   CTF/frontend/assets/characters.png
	new file:   CTF/frontend/assets/characters_red_flag.png
	new file:   CTF/frontend/assets/characters_yellow_flag.png
	new file:   CTF/frontend/assets/red_flag_16_16.png
	new file:   CTF/frontend/assets/red_flag_32_32.png
	new file:   CTF/frontend/assets/tilemap.json
	new file:   CTF/frontend/assets/tilemap.tmx
	new file:   CTF/frontend/assets/tiles.png
	new file:   CTF/frontend/assets/yellow_flag_16_16.png
	new file:   CTF/frontend/assets/yellow_flag_32_32.png
	new file:   CTF/frontend/game_config.json
	new file:   CTF/frontend/index.html
	new file:   CTF/frontend/phaser.js
	new file:   CTF/frontend/project.config
	new file:   CTF/frontend/src/assets.js
	new file:   CTF/frontend/src/gameObjects/Flag.js
	new file:   CTF/frontend/src/gameObjects/Player.js
	new file:   CTF/frontend/src/main.js
	new file:   CTF/frontend/src/scenes/Boot.js
	new file:   CTF/frontend/src/scenes/Game.js
	new file:   CTF/frontend/src/scenes/GameOver.js
	new file:   CTF/frontend/src/scenes/Preloader.js
	new file:   CTF/frontend/start.sh
	new file:   CTF/random_map_example.png
2025-12-27 15:59:21 +08:00
2f845586a2 Initial commit 2025-12-27 07:24:28 +00:00