Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

I'm not sure what exactly I'm trying to ask. I want to be able to make some code that can easily take an initial and final state and some rules, and determine paths/choices to get there.

So think, for example, in a game like Starcraft. To build a factory I need to have a barracks and a command center already built. So if I have nothing and I want a factory I might say ->Command Center->Barracks->Factory. Each thing takes time and resources, and that should be noted and considered in the path. If I want my factory at 5 minutes there are fewer options then if I want it at 10.

Also, the engine should be able to calculate available resources and utilize them effectively. Those three buildings might cost 600 total minerals but the engine should plan the Command Center when it would have 200 (or w/e it costs).

This would ultimately have requirements similar to 10 marines at 5 minutes, infantry weapons upgrade at 6:30, 30 marines at 10 minutes, Factory @ 11, etc...

So, how do I go about doing something like this? My first thought was to use some procedural language and make all the decisions from the ground up. I could simulate the system and branching and making different choices. Ultimately, some choices are going quickly make it impossible to reach goals later (If I build 20 Supply Depots I'm prob not going to make that factory on time.)

So then I thought weren't functional languages designed for this? I tried to write some prolog but I've been having trouble with stuff like time and distance calculations. And I'm not sure the best way to return the "plan".

I was thinking I could write:

depends_on(factory, barracks)

depends_on(barracks, command_center)

builds_from(marine, barracks)

build_time(command_center, 60)

build_time(barracks, 45)

build_time(factory, 30)

minerals(command_center, 400)

...

build(X) :- 

  depends_on(X, Y),

  build_time(X, T),

  minerals(X, M),

...

Here's where I get confused. I'm not sure how to construct this function and a query to get anything even close to what I want. I would have to somehow account for the rate at which minerals are gathered during the time spent building and other possible paths with extra gold. If I only want 1 marine in 10 minutes I would want the engine to generate lots of plans because there are lots of ways to end with 1 marine at 10 minutes (maybe cut it off after so many, not sure how you do that in prolog).

I'm looking for advice on how to continue down this path or advice about other options. I haven't been able to find anything more useful than towers of Hanoi and ancestry examples for AI so even some good articles explaining how to use prolog to DO REAL THINGS would be amazing. And if I somehow can get these rules set up in a useful way how to I get the "plans" prolog came up with (ways to solve the query) other than writing to stdout like all the towers of Hanoi examples do? Or is that the preferred way?

My other question is, my main code is in ruby (and potentially other languages) and the options to communicate with prolog are calling my prolog program from within ruby, accessing a virtual file system from within prolog, or some kind of database structure (unlikely). I'm using SWI-Prolog atm, would I be better off doing this procedurally in Ruby or would constructing this in a functional language like prolog or Haskell be worth the extra effort integrating?

I'm sorry if this is unclear, I appreciate any attempt to help, and I'll re-word things that are unclear.

1 Answer

0 votes
by (108k points)

As a general technique, one can apply shortest path algorithms to a problem of reaching the desired state. In some cases working backward from the desired state to a known starting point is more efficient than the "forward" search. On the language integration side, there are many Prolog or Prolog-like implementations in Ruby.  see here for a recently updated program.

If you want to learn Ruby Documentation, interactive ruby and customizing IRB then visit this Ruby On Rails course.

Browse Categories

...