[CSS_ACM_General_List] How to ditch Visual Studio (and write Starcraft AI in Vim)

Damien Radtke damienradtke at gmail.com
Sat Mar 27 02:09:36 CST 2010


*How to write Starcraft AI in Vim*

First, download BWSAL_0.9.7.zip (google "bwsal", first hit) and extract the
folder. It should contain:

*BasicAIModule
Chaoslauncher
include
lib
Starcraft
WINDOWS
COPYING
README*


*Set up the folder hierarchy (your workspace)*

This folder setup will make the process of working on AI less confusing,
getting rid of folders unnecessary for actual development. Create a new
folder wherever, and inside that folder paste the BasicAIModule, include,
and lib folders from BWSAL. I also recommend renaming the BasicAIModule
folder to 'src', as it also contains a subfolder called BasicAIModule, and
having different names makes things less confusing. Plus, the build command
will assume this folder is named 'src', so your workspace directory should
contain the folders include, lib, and src.


*Install the Project plugin for Vim*

My Vim setup requires the Project plugin, which will make navigating source
much easier and makes it possible to set up the necessary environment for
using Visual Studio's build tools. The plugin can be found here (
http://www.vim.org/scripts/script.php?script_id=69). This howto will assume
you have a basic working knowledge of Vim.


*Create the project in Vim*

Open up the Project plugin (command :Project), make sure the cursor is in
the left-hand window, and press \C. Enter a name for the project, enter the
directory of your workspace, enter '.' (a single dot, no quotes) for the CD
parameter, and use '*.cpp *.h' for the file filter (again, no quotes).
Scroll to the src/BasicAIModule directory and open up any file to make sure
Vim cd's to the project's root folder.

There is one property you'll need to manually set for the project, and
that's the in-script, a vimscript file that is run by Vim whenever you open
your project. Your project should start with a line similar to:

starcraft="C:\Documents and Settings\Administrator\Desktop\starcraft-dev"
CD=. filter="*.cpp *.h" {

At the end of this set the property "in" to "in.vim", so the line will now
look like this:

starcraft="C:\Documents and Settings\Administrator\Desktop\starcraft-dev"
CD=. filter="*.cpp *.h" in=in.vim {

Now we'll need to actually create the in-script. Create the file (:e in.vim),
and inside that file put these contents:


" Set up msbuild
let $PATH = 'C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio
9.0\VC\BIN;C:\Program Files\Microsoft Visual Studio
9.0\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program
Files\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program Files\Microsoft
SDKs\Windows\v6.0A\bin;C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio
9.0\VC\BIN;C:\Program Files\Microsoft Visual Studio
9.0\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program
Files\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program Files\Microsoft
SDKs\Windows\v6.0A\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\bin;C:\Program
Files\Java\jdk1.6.0_18\bin;C:\bin\ctags58;'

let $INCLUDE = '..\include;C:\Program Files\Microsoft Visual Studio
9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0a\include;'

let $LIB = 'C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;C:\Program
Files\Microsoft SDKs\Windows\v6.0a\lib;'

" Set F12 to build the module, Shift+F12 to clean it
nmap <silent> <F12> :! title Building StarCraft AI... && cd src && msbuild
/p:"VCBuildAdditionalOptions=/useenv" /p:Configuration=Release /v:detailed
&& copy /y Release\* "C:\Program Files\StarCraft\bwapi-data\AI"<cr>

nmap <silent> <S-F12> :! title Clean && msbuild /p:Configuration=Release
/v:detailed /target:clean<cr>


The paths listed here work on my system, but they may be configured
differently on yours. To make sure you have the right values for $PATH,
$INCLUDE, and $LIB, open up "Visual Studio 2008 Command Prompt" (I have
Visual Studio 2008 C++ Express installed, so the link is Start -> All
Programs -> Microsoft Visual Studio 2008 Express Edition -> Visual Studio
Tools -> Visual Studio 2008 Command Prompt). It should open up a command
prompt window with the message "Setting environment for using Microsoft
Visual Studio 2008 x86 tools." To check your correct values for those
variables use these commands:

>echo %path%
>echo %include%
>echo %lib%

To make it easier to copy and paste those values to your in.vim script,
re-direct standard output:

>echo %path% > C:\some\path
>echo %include% > C:\some\path
>echo %lib% > C:\some\path

NOTE: The line right underneath the comment "Set F12 to build the module,
..." ends with "copy /y Release\* ..." Make sure the copy target is
consistent with your StarCraft install directory. If it's not, adjust it.

That should be about it, but you must either restart Vim or source in.vim
directly. You can use the Vim project plugin to access your files, and press
F12 at any time to build the project and automatically copy the resulting
files to the Starcraft directory. Make sure that Chaoslauncher is configured
to use your AI, too.

There is one big feature missing from Vim, however, that Visual Studio has,
and that's code completion. Luckily, that's available too. =)

*Code Completion*

To use code completion (or IntelliSense) in Vim, you'll need two things: the
OmniCppComplete plugin and Ctags. Exuberant Ctags can be downloaded online
(google "ctags", and it's the first link). Download the Ctags 5.8 binary for
Windows. Extract that folder to some location (I have it in C:\bin\ctags58)
and make sure that folder is on your system's path (if it's not included in
the path set in your in.vim file, make sure you add it there too). Make sure
that typing "ctags --help" prints a long message about how it works.
OmniCppComplete can be downloaded from vim.org, but there is a slightly
patched version I recommend using at
http://www.github.com/MasterKey/OmniCppComplete (there's a "Download Source"
link near the top right).

A short tutorial on how to use the plugin is listed on the vim wikia website
(http://vim.wikia.com/wiki/C%2B%2B_code_completion). I recommend creating
two tag files, one for include and one for src, which means you'll need to
manually re-name and add the include tag file. I have this added to my
in.vim file:

set tags+=./include-tags;
nmap <silent> <F11> :! ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
src<cr>


This adds the include tags file (which should only need to be created once)
to the search list and creates a shortcut to make re-generating the tags in
my src directory very easy (just hit F11).

IMPORTANT: There is a bug in ctags (or maybe it's not intended to be a
feature? Seems like a bug to me) where extern variables defined in
namespaces aren't picked up. Because of this, you will be unable to access
unit types defined in BWAPI::UnitTypes or races defined in BWAPI::Races. To
get around this, in BWAPI/UnitType.h and BWAPI/Race.h (both in the include
directory), delete the word "extern" from in front of each declaration that
has it, save, then re-create the include tags (be sure to use a command
similar to the one I have listed above). After that you'll need to put them
back, otherwise your AI may crash after the next build. Remember, you should
only need to do this once, since all your work will be done in src.

So there you have it. How to ditch Visual Studio and use Vim to write
StarCraft AI. Good luck everybody. You'll need it. ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.depaul.edu/pipermail/css_acm_general_list/attachments/20100327/822c4626/attachment.htm


More information about the CSS_ACM_General_List mailing list