Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Trade Solver/AI

Author
Message
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 16th Dec 2006 03:31 Edited at: 16th Dec 2006 03:42
This is my first attempt at a trade solver/AI. The solver gets a list of possible trades it can make, such as "Buy a Starship for 250 Credits" and "Make 300 Credits by selling 1 Starship" and the solver will use this to try to achieve some defined goal.

Here's the code snippet. In this snippet the example has many possible trades, and the solver is told to get a battlecruiser by linking together trades that eventually reach that goal. If you copy&paste the code, execute, and press the spacebar, it will give you the list of trades that must be done in order to get the battlecruiser.



It would be interesting to expand this to work with other things, like locations and distances, such as "buying" 1 lightyear of travel for 10 quarts of hyperdrive fuel, and adding movement costs that way, thereby discouraging the solver from making lots of trades from opposite ends of the galaxy.

Edit:
This solver could also be adapted to work with a goal directed reasoning system. Like if for example the overall goal given to the system was to "get to the 20th floor of building xyz", the solver could be given a pool of possible subgoals, such as: "find elevator by looking around in building", "look around in building by being in building", "find building by using map", "go to floor x by going to elevator", "go to elevator by finding elevator", and the solver would find a way to string the subgoals together in an order that worked and acheived the overall goal.
sp3ng
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 21st Dec 2006 11:21
this is the EXACT way that monolith created their AI in FEAR, they give it a goal, some actions to acheive the goal and the cost of each action.

i have just finished reading about it and i wanted to know if it could be implemented into dbpro (now i know)

can u please post the way u went about doing it (im still a newb and i am having trouble with the concepts of ai

p.s. if anyone wants the FEAR ai document here it is

i have a dream of perfect tactical realism in games
have a question about military tactics?
ask me at this post http://forum.thegamecreators.com/?m=forum_view&t=94634&b=1

Attachments

Login to view attachments
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 21st Dec 2006 21:58 Edited at: 21st Dec 2006 22:18
I'm not sure how I went about writing it. After programming as much as I have, writing code feels as natural as speaking. But I can tell you how the snippet works. Each trade has a name, a list of things that you must give, a list of things that you recieve, and a list of things that you must have. (This must-have attribute is not explored in the code snippet, but you could have a trade where someone gives you their uber_confibulator if you simple show them your fbi_badge, without actually giving or receiving an fbi_badge. ) All this data is stored in these arrays: trade(), trade_have(),trade_give(),trade_receive(). Another array, currently_have() keeps track of what you currently have.
The last four arrays temp_have(), temp_trade_have(), temp_trade_give(), and temp_trade_receive() store information about trades as the solver temporarily tries various trades.

Before talking about the chain_trade() function, the meet_requirements_for_trade() function checks currently_have() array to see if you currently have everything you need to perform the trade (You must have the items that the trade demands you give and the items the trade demands you have).

Finally, chain_trade() is the solver. It is a recursive function, and the last parameter, count, keeps track of how many further recursions it is willing to search. In the get() function, you see chain_trade() is called with a count of 12: chain_trade(name$,amount,12). This means it searches a maximum of 12 levels deep.

Once chain_trade() is called, it sees if it has reached the goal with this loop:

If it doesn't exit the function then and there, it hasn't reached the goal yet, so it finds the first trade that it meets the requirements for. After it has found a trade it can perform, it saves the trade and what it currently has to a slot in the temp arrays with this loop:

Once everything is saved to the temp arrays, it performs the trade with this bit of code:


It then records that the trade took place in the solution string, which will eventually hold the solution if it finds one. It then calls the following: chain_trade(name$,amount,count-1), which calls itself, recursively, with count-1 this time, meaning that in later recursions count will eventually reach 0, at which point it will stop searching for a solution.

Next, after the recursive call, it restores the trade and the currently_have arrays with this:

And if a solution has been found, it exits the function, else it removes that trade from the solution string and continues its search.


Another thing that could be based on the same system is like a Detective AI. If the detective ai/solver had a set of beliefs (and perhaps could have the ability to learn new beliefs in real-time), and was told to solve a mystery given little or no information it could ask questions that it thinks could either confirm or deny possibilities.

For example, if the mystery was "who killed bob?", the solver could believe that usually the murder knows the person he killed to ask "who knew bob?" to form a list of suspects, say "andrew, george, and matt". Then the detective AI could use the belief that both people had to have been in the same place for the murder to occur to ask "where was bob on the night of the murder?" and then ask andrew "where were you on the night of the murder?" and see if anybody says they were in the same place as bob, and if not, ask matt if he knew where andrew was on the night of the murder, etc.
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 22nd Dec 2006 09:50
Quote: "After programming as much as I have, writing code feels as natural as speaking."

Lol! Same here!

sp3ng
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 22nd Dec 2006 11:48
i have worked out planning ai tonight (as far as i know, it chooses the way to, in this example become less hungry, i just give it the means of doing so)

if ur wondering, it is out of the alma example on the FEAR ai document

user input:


automated:



i have a dream of perfect tactical realism in games
have a question about military tactics?
ask me at this post http://forum.thegamecreators.com/?m=forum_view&t=94634&b=1

Login to post a reply

Server time is: 2024-11-22 23:23:29
Your offset time is: 2024-11-22 23:23:29