Advertisement
pro-themes

proj 3 unfinished

Nov 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1.  
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <iostream>
  5. #include "bot.h"
  6.  
  7. using namespace std;
  8.  
  9. const int MAX_ROWS = 40;
  10. const int MAX_COLS = 40;
  11. const int MAX_NUM = 10;
  12.  
  13. int ROWS; // global variables
  14. int COLS;
  15. int NUM;
  16.  
  17. /* onStart:
  18. An Initialization procedure called at the start of the game.
  19. You can use it to initialize certain global variables, or do
  20. something else before the actual simulation starts.
  21. Parameters:
  22. rows: number of rows
  23. cols: number of columns
  24. num: number of dwarfs
  25. log: a cout-like log */
  26.  
  27. void onStart(int rows, int cols, int num, std::ostream &log) {
  28. log << "Start!" << endl; // Print a greeting message
  29.  
  30. ROWS = rows; // Save values in global variables
  31. COLS = cols;
  32. NUM = num;
  33. }
  34.  
  35. /* onAction:
  36. A procedure called each time an idle dwarf is choosing
  37. their next action.
  38. Parameters:
  39. dwarf: dwarf choosing an action
  40. day: day (1+)
  41. hours: number of hours in 24-hour format (0-23)
  42. minutes: number of minutes (0-59)
  43. log: a cout-like log */
  44.  
  45. void onAction(Dwarf &dwarf, int day, int hours, int minutes, ostream &log) {
  46. // Get current position of the dwarf
  47. int r = dwarf.row();
  48. int c = dwarf.col();
  49.  
  50. // Look if there is a tree on the right from the dwarf
  51. if (dwarf.look(r, c+1) == PINE_TREE || dwarf.look(r, c+1) == APPLE_TREE) {
  52. log << "Found a tree -- chop" << endl;
  53. dwarf.start_chop(EAST);
  54. return;
  55. }
  56. else if (dwarf.look(r, c-1) == PINE_TREE || dwarf.look(r, c-1) == APPLE_TREE) {
  57. log << "Found a tree -- chop" << endl;
  58. dwarf.start_chop(WEST);
  59. return;
  60. }
  61. else if (dwarf.look(r+1, c) == PINE_TREE || dwarf.look(r+1, c) == APPLE_TREE) {
  62. log << "Found a tree -- chop" << endl;
  63. dwarf.start_chop(SOUTH);
  64. return;
  65. }
  66. else if (dwarf.look(r-1, c) == PINE_TREE || dwarf.look(r-1, c) == APPLE_TREE) {
  67. log << "Found a tree -- chop" << endl;
  68. dwarf.start_chop(NORTH);
  69. return;
  70. }
  71.  
  72. /**else if (dwarf.look(r, c+2) == PINE_TREE || dwarf.look(r, c+2) == APPLE_TREE) {
  73. log << "Found a tree -- chop" << endl;
  74. dwarf.start_chop(EAST);
  75. return;
  76. }
  77. else if (dwarf.look(r, c-2) == PINE_TREE || dwarf.look(r, c-2) == APPLE_TREE) {
  78. log << "Found a tree -- chop" << endl;
  79. dwarf.start_chop(WEST);
  80. return;
  81. }
  82. else if (dwarf.look(r+2, c) == PINE_TREE || dwarf.look(r+2, c) == APPLE_TREE) {
  83. log << "Found a tree -- chop" << endl;
  84. dwarf.start_chop(SOUTH);
  85. return;
  86. }
  87. else if (dwarf.look(r-2, c) == PINE_TREE || dwarf.look(r-2, c) == APPLE_TREE) {
  88. log << "Found a tree -- chop" << endl;
  89. dwarf.start_chop(NORTH);
  90. return;
  91. }**/
  92.  
  93. else {
  94. // Otherwise, move to a random location
  95. int rr = rand() % ROWS;
  96. int cc = rand() % COLS;
  97. log << "Walk to " << rr << " " << cc << endl;
  98. dwarf.start_walk(rr, cc);
  99. return;
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement