Skip to content

Feat/caspar ai #6820

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Feat/caspar ai #6820

wants to merge 24 commits into from

Conversation

Scoppio
Copy link
Collaborator

@Scoppio Scoppio commented Apr 3, 2025

Adds basic stuff needed for Caspar, and updates the games action log.

@Scoppio Scoppio self-assigned this Apr 3, 2025
@@ -33,7 +33,7 @@ private MathUtility() {
* maximum. Otherwise, this will return the rounded integer between the
* two points
*/
public static int lerp(final int min, final int max, final double f) {
public static int lerp(int min, int max, double f) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final is useless in arguments, so I just removed it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually not useless. It prevents the programmer from re-assigning a value to them.

Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 56.20915% with 67 lines in your changes missing coverage. Please review.

Project coverage is 30.24%. Comparing base (d056ccd) to head (5b009af).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
megamek/src/megamek/common/CubeCoords.java 5.00% 38 Missing ⚠️
megamek/src/megamek/ai/neuralnetwork/Brain.java 83.67% 7 Missing and 1 partial ⚠️
...amek/client/bot/caspar/MovementClassification.java 60.00% 5 Missing and 1 partial ⚠️
.../neuralnetwork/FeatureNormalizationParameters.java 83.33% 3 Missing and 1 partial ⚠️
...megamek/client/bot/caspar/ClassificationScore.java 69.23% 4 Missing ⚠️
...egamek/client/bot/princess/SwarmCenterManager.java 0.00% 3 Missing ⚠️
.../src/megamek/client/bot/princess/SwarmContext.java 0.00% 3 Missing ⚠️
megamek/src/megamek/codeUtilities/MathUtility.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             master    #6820    +/-   ##
==========================================
  Coverage     30.24%   30.24%            
- Complexity    15811    15831    +20     
==========================================
  Files          2885     2890     +5     
  Lines        283286   283427   +141     
  Branches      49335    49345    +10     
==========================================
+ Hits          85667    85720    +53     
- Misses       192013   192105    +92     
+ Partials       5606     5602     -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…time, need to change it so it just fails if value is higher than a certain percent
Copy link
Collaborator

@rjhancock rjhancock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often will the binary files change?

Other than a few comments and a few classes could use (not required) some top level JavaDocs, it looks good for the initial PR.

@@ -33,7 +33,7 @@ private MathUtility() {
* maximum. Otherwise, this will return the rounded integer between the
* two points
*/
public static int lerp(final int min, final int max, final double f) {
public static int lerp(int min, int max, double f) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually not useless. It prevents the programmer from re-assigning a value to them.

@Scoppio
Copy link
Collaborator Author

Scoppio commented Apr 3, 2025

How often will the binary files change?

Other than a few comments and a few classes could use (not required) some top level JavaDocs, it looks good for the initial PR.

It depends... Ideally I want to create at least 5 AI models (Beginer, easy, normal, hard, hardcore), and maybe two or three "flavors" for each of those too would be interesting (if viable).

I may try to make them read directly from zip files, or at least tar all the model files into one thing instead? Need to check Tensorflow's API. But the models sohuld not change alot once done, unless someone is doing anything with them, like adding new stuff or tuning, in any way, its usually just a file replace.

@rjhancock
Copy link
Collaborator

Alright. The speed of change was my concern as the way Git handles binary is it just re-adds the entire file. Not changing often, not really an issue.

@Scoppio Scoppio added the For New Dev Cycle This PR should be merged at the beginning of a dev cycle label Apr 5, 2025
@Scoppio Scoppio requested a review from Copilot April 6, 2025 22:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 25 out of 29 changed files in this pull request and generated 1 comment.

Files not reviewed (4)
  • megamek/build.gradle: Language not supported
  • megamek/data/ai/brains/default/fingerprint.pb: Language not supported
  • megamek/data/ai/brains/default/keras_metadata.pb: Language not supported
  • megamek/data/ai/brains/default/min_max_feature_normalization.csv: Language not supported
Comments suppressed due to low confidence (1)

megamek/src/megamek/ai/neuralnetwork/Brain.java:128

  • [nitpick] The error message for a failed prediction is unclear and may be confusing. Consider revising the message to something more informative like 'Prediction failed due to an unexpected error' for improved clarity.
logger.error("Prediction failed, there is no recourse from this", e);

* @return The value clamped
*/
public static float clamp01(float value) {
return clamp(value, 0f, 1f);
Copy link
Preview

Copilot AI Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clamp01 methods are calling a clamp method with float/double arguments, but the existing clamp method appears to operate on long values. Consider adding overloads of clamp for float and double types or casting the arguments appropriately to ensure type consistency.

Copilot uses AI. Check for mistakes.

rjhancock
rjhancock previously approved these changes Apr 25, 2025
@HammerGS HammerGS removed the For New Dev Cycle This PR should be merged at the beginning of a dev cycle label Apr 26, 2025
@HammerGS
Copy link
Member

@Scoppio Failing checks

The job fails due to multiple compilation errors in /src/megamek/ai/dataset/UnitPath.java. The issue is that the UnitAction class is missing the methods being called, such as currentCubePosition(), finalCubePosition(), currentPosition(), finalPosition() and others.

@Scoppio Scoppio requested a review from Copilot April 27, 2025 14:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces foundational changes for the Caspar AI feature while updating multiple related components including unit tests for the neural network, interface definitions for movement pathing, and TensorFlow model integration. Key updates include:

  • Adding a new set of unit tests for the neural network under the AI module.
  • Defining and implementing the Pathing interface in MovePath and updating CubeCoords to use record syntax.
  • Extending Configuration and MathUtility with AI‐related methods and integrating TensorFlow model loading in the Brain class.

Reviewed Changes

Copilot reviewed 20 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
megamek/unittests/megamek/ai/neuralnetwork/BrainTest.java Introduces tests for brain loading and neural network predictions.
megamek/src/megamek/common/Pathing.java Defines the new Pathing interface for movement-related operations.
megamek/src/megamek/common/MovePath.java Implements the Pathing interface and adds necessary method overrides.
megamek/src/megamek/common/CubeCoords.java Refactors CubeCoords as a record with additional helper methods.
megamek/src/megamek/common/Configuration.java Adds methods for retrieving AI brain directories and normalization files.
megamek/src/megamek/codeUtilities/MathUtility.java Introduces clamp01 methods for clamping float/double values.
megamek/src/megamek/client/bot/princess/SwarmContext.java
megamek/src/megamek/client/bot/princess/SwarmCenterManager.java
Updates usage of CubeCoords record accessors.
megamek/src/megamek/client/bot/caspar/MovementClassification.java
ClassificationScore.java
Adds new AI-related movement classification support.
megamek/src/megamek/ai/neuralnetwork/** Adds FeatureNormalizationParameters, BrainRegistry, and Brain classes to support TensorFlow integration for AI.
megamek/src/megamek/ai/dataset/** Minor updates to serializer and dataset handling classes.
Files not reviewed (4)
  • megamek/build.gradle: Language not supported
  • megamek/data/ai/brains/default/fingerprint.pb: Language not supported
  • megamek/data/ai/brains/default/keras_metadata.pb: Language not supported
  • megamek/data/ai/brains/default/min_max_feature_normalization.csv: Language not supported
Comments suppressed due to low confidence (1)

megamek/unittests/megamek/ai/neuralnetwork/BrainTest.java:56

  • [nitpick] Consider renaming 'BRAIN' to follow standard naming conventions (e.g., using camelCase such as 'brain') since it is not a constant.
private static Brain BRAIN;

@Scoppio Scoppio marked this pull request as draft April 27, 2025 21:10
try {
return SavedModelBundle.load(Configuration.aiBrainFolderPath(brainRegistry.name()).toString());
} catch (TensorFlowException e) {
logger.error(e, "Failed to load TensorFlow model: {}", e.getMessage());

Check warning

Code scanning / CodeQL

Unused format argument Warning

This format call refers to 0 argument(s) but supplies 1 argument(s).
@Scoppio Scoppio marked this pull request as ready for review April 28, 2025 03:29
@Scoppio Scoppio requested a review from a team as a code owner April 28, 2025 03:29
@Scoppio Scoppio added For New Dev Cycle This PR should be merged at the beginning of a dev cycle Princess/AI Issues or PR that relate to the current Bot AI PACAR Any Issues related to the PACAR (Princess Abstract Combat Auto Resolve) System labels Apr 28, 2025
@Scoppio Scoppio requested a review from a team as a code owner May 10, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For New Dev Cycle This PR should be merged at the beginning of a dev cycle PACAR Any Issues related to the PACAR (Princess Abstract Combat Auto Resolve) System Princess/AI Issues or PR that relate to the current Bot AI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants