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

Predicates for ambiguous check methods #53

Open
adakitesystems opened this issue Aug 10, 2018 · 3 comments
Open

Predicates for ambiguous check methods #53

adakitesystems opened this issue Aug 10, 2018 · 3 comments

Comments

@adakitesystems
Copy link
Collaborator

adakitesystems commented Aug 10, 2018

@dgant has mentioned how ambiguous can methods can be. Quoting from Discord:

Maybe not buggy necessarily, but "canBuild" can mean a lot of different things and the differences are important
can this SCV build a Barracks at X,Y?
...do you mean now, or when i get the money?
...do you mean if there's no units standing at X, Y?
...do you mean if the SCV has a path to X, Y?
...do you mean once the tech to build it becomes available?

Maybe it would be beneficial to create some type of predicate data structure that can be fed into the method so that the user can choose exactly what he wants to check and when.

Something like:

canBuild(UnitType unitType, Predicates...)

e.g.

BW.canBuild(UnitType.Terran_Siege_Tank, SUFFICIENT_MINERALS, SUFFICIENT_GAS, TECH);

Where it will check if you have the minerals, gas, and the tech to build a siege tank.

It was also mentioned that maybe you want to check if an SCV can build at a certain location without units, so you could feed in the TilePosition and specify to check if anything is blocking the location but would be buildable, etc.

Another benefit of this would be if you want to know if you will have sufficient minerals in N amount of seconds to build a tank, you can feed in an already defined custom predicate that will return true or false for the method to use in its check.

@Bytekeeper
Copy link
Collaborator

Why not invert it and provide utility filters? Either by methods or by java.util.function.Predicates:

Instead of canBuild(myUnitType, SUFFICIENT_...) it'd be:
hasResources.and(hasTech).and(canBuildAt(10,10)).and(canMakeMeASandwich).test(myUnitType)
Since Predicate also has or and negate it should suffice.

@adakitesystems
Copy link
Collaborator Author

Instead of canBuild(myUnitType, SUFFICIENT_...) it'd be:
hasResources.and(hasTech).and(canBuildAt(10,10)).and(canMakeMeASandwich).test(myUnitType)

Yes, that's a good idea, too!

@adakitesystems
Copy link
Collaborator Author

I just implemented roughly 88% of the canMake commands in the raw interface under the name UnitCommandSimulation: https://github.com/OpenBW/BWAPI4J/blob/7345664d647d8f5adbfef798b99da1eeda541755/BWAPI4J/src/main/java/org/openbw/bwapi4j/UnitCommandSimulation.java . This class may be of help with customizing the canMake functions by extending this class and overriding its functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants