Skip to content
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

Starting properties float or int #33

Open
taldim opened this issue Aug 15, 2024 · 2 comments
Open

Starting properties float or int #33

taldim opened this issue Aug 15, 2024 · 2 comments

Comments

@taldim
Copy link

taldim commented Aug 15, 2024

I've updated to the latest version of the main branch, and the agent has stopped working.

When debbuging, I came to the realization that my float value, when set to "0", was treated as int.
To clarify, I initialized a starting propery:
b.addStartingStateProperty("key1",0f);
where I the values of "key1" are supposed to be float.
and added an arithmeticPostconditions to my action, that added a float number to "key1".

In the class ActionGraph, in the function
internal IEnumerable Neighbors(ActionNode node)
When executing "newNode.Action?.ApplyEffects(newNode.State);", the effects were not applied.
When debbuging this function, I realized that the value of "key1" was "0", which was "int", even though I initialized it float.

To clarify, in the ApplyEffects function,
state[kvp.Key] was 0, and therefor
"state[kvp.Key] is float stateFloat" was false
"state[kvp.Key] is int stateInt" was true
yet kvp.Value was 15.1f, since I want to add a float value, and
"kvp.Value is float conditionFloat" was true
"kvp.Value is int conditionInt" was false

and therefor the ApplyEffects function didn't apply.

I'm not sure why my value is set to an integer 0 and not keep it's "float" value

Thank you!

@taldim
Copy link
Author

taldim commented Aug 15, 2024

I created this bypass in the ApplyEffects, after the last "else if" (I don't recommed this fix of course, I just wanted to make sure I was correct, and this fixed my bug and the agent works fine):
else{
bool foundState = false, foundCondition = false;
float stateValue=0, conditionValue=0;
if (state[kvp.Key] is int stateInt2) {
stateValue = stateInt2;
foundState = true;
}
else if (state[kvp.Key] is float stateFloat2) {
stateValue = stateFloat2;
foundState = true;
}
else if (state[kvp.Key] is double stateDouble2) {
stateValue = Convert.ToSingle(stateDouble2);
foundState = true;
}
else if (state[kvp.Key] is long stateLong2) {
stateValue = Convert.ToSingle(stateLong2);
foundState = true;
}
else if (state[kvp.Key] is decimal stateDecimal2) {
stateValue = Convert.ToSingle(stateDecimal2);
foundState = true;
}
if(kvp.Value is int conditionInt2) {
conditionValue = conditionInt2;
foundCondition = true;
}
else if (kvp.Value is float conditionFloat2) {
conditionValue = conditionFloat2;
foundCondition = true;
}
else if (kvp.Value is double conditionDouble2) {
conditionValue = Convert.ToSingle(conditionDouble2);
foundCondition = true;
}
else if (kvp.Value is long conditionLong2) {
conditionValue = Convert.ToSingle(conditionLong2);
foundCondition = true;
}
else if (kvp.Value is decimal conditionDecimal2) {
conditionValue = Convert.ToSingle(conditionDecimal2);
foundCondition = true;
}
if(foundState && foundCondition){
state[kvp.Key] = stateValue + conditionValue;
}
}

@caesuric
Copy link
Owner

Interesting, I'll look into this. Thank you for bringing it to my attention!

I'm not sure I actually tested arithmeticPostconditions with floats, which is my bad. I'll make a test case for them and make sure I get them working.

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

No branches or pull requests

2 participants