-
Notifications
You must be signed in to change notification settings - Fork 332
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
base: master
Are you sure you want to change the base?
Feat/caspar ai #6820
Conversation
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…s cleaner and simpler
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
…time, need to change it so it just fails if value is higher than a certain percent
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
megamek/unittests/megamek/ai/neuralnetwork/NeuralNetworkTest.java
Outdated
Show resolved
Hide resolved
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. |
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. |
…data for testing, I want it all to be self contained
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
@Scoppio Failing checks
|
There was a problem hiding this 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;
megamek/src/megamek/ai/neuralnetwork/FeatureNormalizationParameters.java
Outdated
Show resolved
Hide resolved
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
Adds basic stuff needed for Caspar, and updates the games action log.