User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Game Development section within the Software Development category of DaniWeb, a massive community of 374,006 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,848 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Game Development advertiser:
Views: 508 | Replies: 3
Reply
Join Date: Mar 2008
Posts: 4
Reputation: Saaddani is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Saaddani Saaddani is offline Offline
Newbie Poster

Posted in the wrong thread (Sorry!) - Game Artificial Intelligence help

  #1  
Apr 28th, 2008
I posted my code along with the assignment issue here: http://www.daniweb.com/forums/thread121468.html

I apologize I overlooked the Game Dev section.

In short, the assignment is:

Implement a Goal Oriented AI system. The system should include C++ objects that implement Goals, Actions and Tools. Use the programming example for Chapter 3 as a model and framework.

Implement the following scenario:

Goal 1 - Obtain food.
Goal 2 - Obtain coins.
Goal 3 – Obtain metal detector.
Goal 4 – Obtain rifle.

Action 1 – Search for coins. Requires metal detector.
Action 2 – Hunt rabbit. Requires rifle.
Action 3 – Pick up metal detector.
Action 4 – Pick up rifle.

Tool 1 – Metal detector.
Tool 2 – Rifle.

I am looking for a simpler way to approach the assignment. I figure each goal could be split into a function, then each action could go with the appropriate function, but how do I use the tools to reach each goal?

Also, some goals require you to search for the nearest item, how can I do that if I do not have a pathfinding algorithm to use to find the items?

The book I am using for the class is "Game Development Essentials: Game Artificial Intelligence" by John B ahlquist Jr. and it does not state any information about how to plot items on a map. Anyone know anything about this?

I am not looking for someone to tweak my code as I think I will just start from sratch. However, any help to the questions above is much appreciated.

Thanks,
Danny
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 5
Solved Threads: 46
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Posted in the wrong thread (Sorry!) - Game Artificial Intelligence help

  #2  
Apr 29th, 2008
Stick with 'standard' goal-oriented action planning techniques; the method you're starting to write ( based on your other thread ) won't scale well to finding a general solution to a general problem.

Do you even need to consider locality of objects ( i.e. actually moving between them ) or just provide the action sequence necessary in order to fulfil the top-level goal? By that I mean, a valid response from one goal planner could be:

kill rabbit := pick up rifle -> shoot rabbit

and from another, different planner, it could be:

kill rabbit := move 1,0 -> move 0,1 -> pick up rifle -> move 0,-1 -> rotate 90 -> fire rifle.

in the first case, the planner spits out abstract commands and expects some other layer to solve the task itself; in the second case, the planner does everything including actuate movement itself.

I guess, the question is, how 'useful', or how complete do you want the output to be?

To make it more complete, you need a more complete specification of the pre-requisite/post-requisite/action set, and you need a somewhat complex symbol-based planner. ( See STRIPS for example, papers for the STRIPs solver implementation are easy to find, and it's not that difficult to implement ).

For a less complete solution, you can almost do without a specialized planner atall ( you can represent the problem as a directed/undirected graph, and use a tree-search/graph-search to get the shortest path between start node and goal node, by equivalence, this represents the optimum action path ).
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Mar 2008
Posts: 4
Reputation: Saaddani is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Saaddani Saaddani is offline Offline
Newbie Poster

Re: Posted in the wrong thread (Sorry!) - Game Artificial Intelligence help

  #3  
Apr 29th, 2008
So far, with what I have, a two dimensional array displays a playing field and my player along with coins, rifle, etc. displayed using using numbers. Problem is, when trying to hunt for a rabbit with the HuntForRabbit() function, the program displays a map for every run through the loop but it does not update any of the values. Can someone hint me in the right direction of updating the values so that the player moves to the object (number to number)? Also, I would like to know how to update the map in place rather then displaying a new map each time the program makes a pass through the loops in the HuntForRabbit() function. I hope this makes sense. Thanks in advance.

  1. //Final Project - Option 1
  2.  
  3. #include <iostream>
  4. #include <ctime>
  5.  
  6.  
  7. using std::cin;
  8. using std::cout;
  9. using std::endl;
  10.  
  11. void DrawMap();
  12. void HuntForRabbit(int &, int &, int &, int &);
  13.  
  14.  
  15.  
  16. int mapArray[25][25] = {0};
  17.  
  18.  
  19. int main()
  20. {
  21.  
  22. //key
  23. cout << "------------------------------------------\nKey\n------------------------------------------\n1.Rabbit = 2\n2.Coin = 3\n3.Rifle = 4\n4.Metal Decector = 5\n5.Player = 9\n------------------------------------------" << endl << endl << endl;
  24. //map
  25. cout << "Level 1: " << endl;
  26.  
  27. for (int x = 0; x < 25; x ++)
  28. {
  29. mapArray[0][x] = 1;
  30. mapArray[24][x] = 1;
  31. } //end for
  32. for (int x = 1; x < 24; x ++)
  33. {
  34. mapArray[x][0] = 1;
  35. mapArray[x][24] = 1;
  36. } //end for
  37.  
  38.  
  39. //starting point of charecter
  40. srand(static_cast<int>(time(0)));
  41. int charecter = 9;
  42. int charecterX = 1 + rand() % (23 - 1 + 1);
  43. int charecterY = 1 + rand() % (23 - 1 + 1);
  44. mapArray[charecterX][charecterY] = charecter;
  45.  
  46. //inset rabbit
  47. int rabbit = 2;
  48. int rabbitX = 1 + rand() % (23 - 1 + 1);
  49. int rabbitY = 1 + rand() % (23 - 1 + 1);
  50. mapArray[rabbitX][rabbitY] = rabbit;
  51. //inset coins
  52. int coin = 3;
  53. int coinX = 1 + rand() % (23 - 1 + 1);
  54. int coinY = 1 + rand() % (23 - 1 + 1);
  55. mapArray[coinX][coinY] = coin;
  56. //insert rifle
  57. int rifle = 4;
  58. int rifleX = 1 + rand() % (23 - 1 + 1);
  59. int rifleY = 1 + rand() % (23 - 1 + 1);
  60. mapArray[rifleX][rifleY] = rifle ;
  61. //insert metal detector
  62. int metaldet = 5;
  63. int metaldetX = 1 + rand() % (23 - 1 + 1);
  64. int metaldetY = 1 + rand() % (23 - 1 + 1);
  65. mapArray[metaldetX][metaldetY] = metaldet ;
  66.  
  67.  
  68.  
  69. //draw map
  70. DrawMap();
  71.  
  72. //menu
  73. char choice = ' ';
  74. cout << endl << endl << endl;
  75. cout << "Please choose from the following options:\n------------------------------------------\nA - Hunt for wabbit.\nB - Hunt for coins.\nC - Look for rifle.\nD - Look for metal detector.\n------------------------------------------" << endl;
  76. cin >> choice;
  77. choice = toupper(choice);
  78. cout << "------------------------------------------" << endl;
  79.  
  80. switch (choice)
  81. {
  82. case 'A':
  83. cout << "You selected: Hunt for wabbit." << endl;
  84. HuntForRabbit(charecterX, charecterY, rabbitX, rabbitY);
  85. break;
  86. case 'B':
  87. cout << "You selected: Hunt for coins." << endl;
  88. break;
  89. case 'C':
  90. cout << "You selected: Look for rifle." << endl;
  91. break;
  92. case 'D':
  93. cout << "You selected: Look for metal detector." << endl;
  94. break;
  95. default:
  96. cout << "You selected: Invalid menu option" << endl;
  97. } //end switch
  98.  
  99. cout << "------------------------------------------" << endl;
  100.  
  101.  
  102.  
  103.  
  104. } //end of main function
  105. // ****** function definitions *******
  106. void DrawMap()
  107. {
  108. //draw map
  109. for (int r = 0; r < 25; r ++)
  110. {
  111. for (int c = 0; c < 25; c++)
  112. {
  113. cout << mapArray[r][c];
  114. }
  115. cout << endl;
  116. } //end for
  117. } //end DrawMap
  118. void HuntForRabbit(int &charecterX, int &charecterY, int &rabbitX, int &rabbitY)
  119. {
  120. do
  121. {
  122. if (charecterX > rabbitX)
  123. {
  124. charecterX--;
  125. }
  126. if (charecterX < rabbitX)
  127. {
  128. charecterX++;
  129. }
  130. if (charecterY > rabbitY)
  131. {
  132. charecterY--;
  133. }
  134. if (charecterY < rabbitY)
  135. {
  136. charecterY++;
  137. }
  138. DrawMap();
  139. }
  140. while (mapArray[charecterX][charecterY] != mapArray[rabbitX][rabbitY]);
  141.  
  142. } //end of HuntForRabbit function
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,182
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 34
Solved Threads: 822
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Posted in the wrong thread (Sorry!) - Game Artificial Intelligence help

  #4  
May 1st, 2008
since you reposted your code I deleted the post on the c++ board.
'Politics' is made up of two words, 'poli,' which is Greek for 'many,' and 'tics,' which are blood-sucking insects.
- Gore Vidal
Being ignorant is not so much a shame as being unwilling to learn. - Benjamin Franklin
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Game Development Marketplace
Thread Tools Display Modes

Other Threads in the Game Development Forum

All times are GMT -4. The time now is 10:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC