archive by month
Skip to content

ground connectivity code to share

Here is Steamhammer's new C++ MapPartitions class, which calculates ground connectivity. This is a donation to the community. Feel free to borrow it for your own bot, if you like. The download is a zip which contains 4 files: MapPartitions.cpp, MapPartitions.h, and 2 license files. The class contains some code derived from UAlbertaBot, so there is a UAlbertaBot license plus Steamhammer’s license. They are both MIT style licenses, which basically make no requirement beyond including the license file. (It’s irritating that the licensing considerations are as complex as the code, but that’s the world we live in.)

I’ll quote the comment describing it:

// Partition the map into connected walkable areas.
// The grain size is the walk tile, 8x8 pixels, the granularity the map provides.
// Unwalkable walk tiles are partition ID 0.
// Walkable partitions get partition IDs 1 and up.

// This class provides two features:
// 1. Walkability for all walk tiles, taking into account the immobile neutral
//    units at the start of the game.
// 2. Ground connectivity: What points are reachable by ground?

// If two walk tiles are in the same partition, it MIGHT be possible for a unit
// to walk between them. To know for sure, you have to find a path and verify
// that it is wide enough at every point for the unit to pass.
// If two walk tiles are not in the same partition, no unit can walk between them.

Concretely, the interface lets you directly test the walkability of a position, find the partition ID of a position, or check whether 2 positions are connected by ground. You can find out the total number of partitions (some maps have hundreds due to small holes), and you can draw partitions on the screen for debugging. There’s not that much to it.

A few notes:

  • There is a separate initialize() method that is not called by the constructor. You have to call it yourself, in or after your main onStart(). Depending on your use case, this is sometimes necessary to avoid making BWAPI calls before BWAPI is initialized itself.
  • Maps often have little side bits attached by a single walk tile. No unit is small enough to walk there, but this class doesn’t know it.
  • The little side bits are not important, at least not in Steamhammer’s play. Units don’t want to go there.
  • The class does not update when neutral units are destroyed, opening paths that used to be closed. But the walkability data structure is designed to be easy to update in that case.
  • This version is slightly different from Steamhammer’s code. I changed the error handling so that I could remove one last dependency and make it completely standalone (except for BWAPI, of course). Only a handful of lines are different.

I’ve suggested before that authors should package up reusable code as libraries. BWEM, BWEB, and FAP are great examples. MapPartitions is more modest. When I’ve looked at breaking out Steamhammer code, until now I’ve always felt that the parts were too integrated with each other, with too many dependencies. MapPartitions is the first exception. I hope some people find it useful.

Trackbacks

No Trackbacks

Comments

MicroDK on :

Thanks! This can make more bots sign up for AIST S1. I posted a link in our Discord group. Your base finder code in Bases.cpp/.h and Base.cpp/.h could be candidates for a self contained library you can release. ;)

Jay Scott on :

Yes, the base placing code could also be broken out—but not yet. The current version still has dependencies on complicated stuff like InformationManager. After I move the InformationManager base tracking stuff to Bases where it belongs, I’ll think about whether it’s a useful thing to do.

Anon on :

Do you guys have a Discord group? Do you to talk about bots, coding, and more technical stuff? I'd be interested to read/study more of that, despite honestly not having the time (or perhaps even knowledge) to contribute...

Antiga / Iruian on :

@Anon , Here's the SSCAIT discord group (but it includes much more than just sscait)

https://discord.gg/w9wRRrF

Jay - could this go on github someday? (it'd be awesome if SH was there too) , I expect this new tool to sorta get lost if it doesn't end up in a repository.

Jay Scott on :

You know, I find it interesting that people trust third-party repositories like github to keep stuff available and visible. For myself, I feel that a third party might go out of business or change its policies at any time. I trust myself to keep my stuff available. Oh well, I’m off topic!

Anon on :

I was also wondering why you never put your code on Github before. It's pretty stable and while I understand your concern about 3rd parties, with GH it's very unlikely that you'll lose your code, access to it, or whatever.

MicroDK on :

Remember what happened to Google Code? It was closed but luckily people had the change to move it to GitHub. What is the bussiness case for GitHub? How do they make money?

Jay Scott on :

The real reason might be am unconscious aversion to making my life more complicated. That is to say, laziness. It’s just another distribution point, and it provides features that people like, so there”s no big downside.

Dan on :

You don't have to trust it as a reliable store; its job is as a distribution and discovery mechanism. And pull requests are a much easier way to propose/accept changes than emailing patches. Here's what starts to happens when, for example, BWEM is removed from the silo of a zip file on SourceForge and put on GitHub: https://github.com/N00byEdge/BWEM-community/pulls?q=is%3Apr+is%3Aclosed

A bot doesn't lend itself to community development in quite the same way as a library; it's much more personal. But I do think you might be pleasantly surprised by the results of having it up there.

Jay Scott on :

Still, point taken. It would be a fine addition.

Antiga / Iruian on :

This game was tooo good! , very interesting / lots of potato on both sides : http://www.openbw.com/replay-viewer/?rep=https%3A%2F%2Fsscaitournament.com%2FReplays%2FSTEAMHAMMER%2F266282-Stea_Mart-ZvT.rep

Jay Scott on :

Argh, that game was so horrible! I was thinking of writing it up as a series of disasters.

MicroDK on :

Yah! Letabot did his "let's freeze in the enemy's base". :)

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options

Submitted comments will be subject to moderation before being displayed.