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

can't find same function in bwapi4j as unit.getplayer() in bwapi #89

Open
RoySRose opened this issue Nov 15, 2018 · 8 comments
Open

can't find same function in bwapi4j as unit.getplayer() in bwapi #89

RoySRose opened this issue Nov 15, 2018 · 8 comments

Comments

@RoySRose
Copy link

RoySRose commented Nov 15, 2018

My team already has a bot with all the dependencies to BWAPI
We are kind of rebooting the project and found your project.
Glad to see the updates for bwapi4.2.

I was trying to convert the code to meet API of BWAPI4J.
I couldn't find any method that does the same thing as Unit.getplayer() in BWAPI.

Am I missing something?

---added---
import bwapi.DefaultBWListener;
import bwapi.Game;
import bwapi.Mirror;

couldn't find any replacements for this too. is there any guide that I can take a look to get started?

@adakitesystems
Copy link
Collaborator

Hi, @RoySRose! If I understand your situation correctly, your team was using BWMirror before? Currently, BWAPI4J's API is very different from BWMirror and converting a BWMirror bot to BWAPI4J could be a lot of work depending on the size of your bot's codebase. BWAPI4J has a lot of typesafe features. For example, the Unit#getPlayer() is marked as protected as seen here...

protected Player getPlayer() {
return player;
}
...but exposed in the subclass PlayerUnit seen here...
public Player getPlayer() {
return super.getPlayer();
}

We don't have a guide to port a bot from BWMirror to BWAPI4J. Lots of functionality has just been divided into separate classes such as a MapDrawer class for all the draw commands, a BWMap class for map-related functionality, etc. These objects are accessible via the BW object's getters such as BW#getMapDrawer, BW#getBWMap, etc. Here's an example:

// Print the map name.
bw.getInteractionHandler()
.printf(
"The map is "
+ bw.getBWMap().mapName()
+ "! Size: "
+ bw.getBWMap().mapWidth()
+ "x"
+ bw.getBWMap().mapHeight());

This approach has received mixed feedback. Some people prefer the typesafe features; others not. Because of this, I have been working on refactoring BWAPI4J so its API is much closer to BWMirror and porting a bot from BWMirror to BWAPI4J should be much easier. However, I don't have an estimated completion date as I am the only one working on it currently.

To summarize, there are a few options:

  1. If you would like help or advice porting your bot to BWAPI4J's typesafe API, you're welcome to join us in our Discord Server: https://discord.gg/QbMdnQJ . Posting here is absolutely fine, too :)
  2. Continue developing your bot using BWMirror and wait for (or help ;) ) the upcoming non-typesafe API.
  3. Fork BWAPI4J and make adjustments such that porting your bot from BWMirror to BWAPI4J is easier.

I hope this helps. Happy coding!

@JasperGeurtz
Copy link

if (unit instanceof PlayerUnit) {
  PlayerUnit playerUnit = (PlayerUnit) unit;
  Player player = playerUnit.getPlayer();
}

@JasperGeurtz
Copy link

For option 3 from @adakitesystems suggestions, you can look at https://github.com/JasperGeurtz/VioletLily/tree/master/src/main/org/openbw/bwapi4j (shameless plug).
However this is based on an older branch, so you'll still need to update some things probably.

@RoySRose
Copy link
Author

Hello, @adakitesystems @JasperGeurtz

Thank you both for kind answer.
Yes. we have used BWMirror. Our bot's code isn't small and has a lot of features in it.

But since

  • we are trying to change the race from Terran to Zerg, we have to take a look at it line by line anyway.
  • Had some speed issues and the advantages of BWAPI4J seemed very tempting to me
  • The last update on BWMirror was about a year ago and doesn't support BWAPI 4.2.0 and after

I'll definitely take a closer look at BWAPI4J this weekend.
Best way to verify will be, I think, try converting our bot from BWMirror to BWAPI4J.

  1. Is there anyone who can tell me the API that replaces below?
import org.openbw.bwapi4j.DefaultBWListener;
import org.openbw.bwapi4j.Game;
import org.openbw.bwapi4j.InteractionHandler;
import org.openbw.bwapi4j.Mirror;
  1. If there is any bot example(bot using BWAPI4j written in Java) that I can take a look, it would be a tremendous help.

  2. does BWAPI4J support BWTA? BWTA2? BWEM?

  3. @JasperGeurtz what do you think of BWEM compared to BWTA? any answer from anyone is also welcome:)

Love to contribute to BWAPI4J too, If we get the chance.

@JasperGeurtz
Copy link

JasperGeurtz commented Nov 18, 2018

1,2) A (terran) good bot written using BWAPI4J is Jabbo's: https://github.com/Jabbo16/Ecgberht
See https://github.com/Jabbo16/Ecgberht/blob/master/src/ecgberht/Ecgberht.java for the entrypoint (main) of the bot
3) BWAPI4J supports BWEM, use

bwem = new BWEM(bw);
bwem.initialize();
bwem.getMap().assignStartingLocationsToSuitableBases();

Regions from BWTA are Area's in BWEM, for the rest they are pretty similar
4) They are pretty similar, but BWEM doesnt require those long startup times that BWTA requires if the map hasnt been analysed yet. BWEM also works on more maps afaik

@RoySRose
Copy link
Author

@JasperGeurtz, Thank you for so much information!

You've saved a lot of my time:)
I'll start the converting process.

@RoySRose
Copy link
Author

RoySRose commented Nov 22, 2018

@adakitesystems @JasperGeurtz

I've started converting.

  1. There are ways to check if Unit is mine or enemy.
    But I can't find if they are neutral.

  2. There is PlayerUnit.getUnitsInRadius() to find the List that are in a certain radius from a Unit.
    But I can't find any method that returns all the List that are in a certain radius from a Position.

  3. There are two classes related to the map.
    public static BWMap bwMap = BW.getBWMap();
    public static Map map = new BWEM(BW).getMap();
    BWMap vs Map What are the differences?

  4. There was Position.Invalid or Position.None or Position.Unknown in BWMirror
    is there anything that corresponds to this? or do I have to use just null?

  5. What is WalkPosition for?

  6. Is there any method that can replace BWTA.getShortestPath in BWEM?

  7. Is there any method that can replace BWTA.isConnected in BWEM?

Any Ideas?

@JasperGeurtz
Copy link

JasperGeurtz commented Nov 22, 2018

  1. if the unit is not an instance of a PlayerUnit it is a "neutral" unit e.g.
if (unit instanceof PlayerUnit) {
  PlayerUnit playerUnit = (PlayerUnit) unit;
  Player player = playerUnit.getPlayer();
}
else {
 //unit is neutral like Mineral, Geyser, Blocking Building etc. 
}
  1. You will have to loop trough your units manually and check the distance or make a Pull Request with support added for this method

  2. BWMap is the map from BWAPI4J e.g. it gives the sizes, the hash and other generic map info
    Map is the map from the BWEM map analyser that tries to split the map up in Areas, Chokepoints and Bases (so more specialised, BWMap will always work because it gives info that StarCraft also gives, but BWEM might crash on very unusual maps, as it divides the map and things that humans see, e.g. Areas etc.)

  3. just null, you can also check the "isValid" methods in the source code (I think there is one in BWEM for Position, WalkPosition and TilePosition)

  4. A WalkPosition is 8x8 pixels (/Positions) big that describes if a unit can walk there or not (so for example a cliff wall is unwalkable but normal terrain is walkable)

  5. check out:

    CPPath getPath(Position a, Position b);

  6. check out:

    boolean isAccessibleFrom(Area area);

I invite you to the BWAPI4J discord: https://discord.gg/QbMdnQJ as Adakite suggested if there are more questions!

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

3 participants