The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

89 lines
4.0 KiB

2 months ago
  1. mdp
  2. const int WIDTH = 5;
  3. const int HEIGHT = 5;
  4. const int XINIT = 3;
  5. const int YINIT = 1;
  6. const int GOLD_TO_COLLECT; // Set to 0 to avoid unfolding
  7. const int GEM_TO_COLLECT; // Set to 0 to avoid unfolding
  8. const int B;
  9. const double pAttack = 1/10;
  10. formula left_of_gold = x=2 & y=5;
  11. formula right_of_gold = x=4 & y=5;
  12. formula below_of_gold = (x=3 & y=4);
  13. formula above_of_gold = false;
  14. formula left_of_gem = (x=4 & y=4);
  15. formula right_of_gem = false;
  16. formula below_of_gem = (x=5 & y=3);
  17. formula above_of_gem = (x=5 & y=5);
  18. formula left_of_home = x=2 & y=1;
  19. formula right_of_home = x=4 & y=1;
  20. formula above_of_home = x=3 & y=2;
  21. formula below_of_home = false;
  22. formula left_of_enemy = (x=3 & y=5) | (x=2 & y=4);
  23. formula right_of_enemy = (x=5 & y=5) | (x=4 & y=4);
  24. formula above_of_enemy = x=3 & y=5;
  25. formula below_of_enemy = (x=3 & y=3) | (x=4 & y=4);
  26. module robot
  27. gold : bool init false;
  28. gem : bool init false;
  29. attacked : bool init false;
  30. x : [1..WIDTH] init XINIT;
  31. y : [1..HEIGHT] init YINIT;
  32. [right] !left_of_enemy & x<WIDTH -> (attacked'=false) & (x'=x+1) & (gold' = (gold & !left_of_home) | left_of_gold) & (gem' = (gem & !left_of_home) | left_of_gem);
  33. [left] !right_of_enemy & x>1 -> (attacked'=false) & (x'=x-1) & (gold' = (gold & !right_of_home) | right_of_gold) & (gem' = (gem & !right_of_home) | right_of_gem);
  34. [top] !below_of_enemy & y<HEIGHT -> (attacked'=false) & (y'=y+1) & (gold' = (gold & !below_of_home) | below_of_gold) & (gem' = (gem & !below_of_home) | below_of_gem);
  35. [down] !above_of_enemy & y>1 -> (attacked'=false) & (y'=y-1) & (gold' = (gold & !above_of_home) | above_of_gold) & (gem' = (gem & !above_of_home) | above_of_gem);
  36. [right] left_of_enemy & x<WIDTH -> pAttack : (attacked'=true) & (x'=XINIT) & (y'=YINIT) & (gold'=false) & (gem'=false) + (1-pAttack) : (attacked'=false) & (x'=x+1) & (gold' = (gold & !left_of_home) | left_of_gold) & (gem' = (gem & !left_of_home) | left_of_gem);
  37. [left] right_of_enemy & x>1 -> pAttack : (attacked'=true) & (x'=XINIT) & (y'=YINIT) & (gold'=false) & (gem'=false) + (1-pAttack) : (attacked'=false) & (x'=x-1) & (gold' = (gold & !right_of_home) | right_of_gold) & (gem' = (gem & !right_of_home) | right_of_gem);
  38. [top] below_of_enemy & y<HEIGHT -> pAttack : (attacked'=true) & (x'=XINIT) & (y'=YINIT) & (gold'=false) & (gem'=false) + (1-pAttack) : (attacked'=false) & (y'=y+1) & (gold' = (gold & !below_of_home) | below_of_gold) & (gem' = (gem & !below_of_home) | below_of_gem);
  39. [down] above_of_enemy & y>1 -> pAttack : (attacked'=true) & (x'=XINIT) & (y'=YINIT) & (gold'=false) & (gem'=false) + (1-pAttack) : (attacked'=false) & (y'=y-1) & (gold' = (gold & !above_of_home) | above_of_gold) & (gem' = (gem & !above_of_home) | above_of_gem);
  40. endmodule
  41. rewards "attacks"
  42. attacked : 1;
  43. endrewards
  44. rewards "rew_gold"
  45. [right] left_of_home & gold : 1;
  46. [left] right_of_home & gold : 1;
  47. [top] below_of_home & gold : 1;
  48. [down] above_of_home & gold : 1;
  49. endrewards
  50. rewards "rew_gem"
  51. [right] left_of_home & gem : 1;
  52. [left] right_of_home & gem : 1;
  53. [top] below_of_home & gem : 1;
  54. [down] above_of_home & gem: 1;
  55. endrewards
  56. module goldcounter
  57. required_gold : [0..GOLD_TO_COLLECT] init GOLD_TO_COLLECT;
  58. [right] true -> (required_gold'=max(0, required_gold - (left_of_home & gold ? 1: 0)));
  59. [left] true -> (required_gold'=max(0, required_gold - (right_of_home & gold ? 1 : 0)));
  60. [top] true -> (required_gold'=max(0, required_gold - (below_of_home & gold ? 1 : 0)));
  61. [down] true -> (required_gold'=max(0, required_gold - (above_of_home & gold ? 1 : 0)));
  62. endmodule
  63. module gemcounter
  64. required_gem : [0..GEM_TO_COLLECT] init GEM_TO_COLLECT;
  65. [right] true -> (required_gem'=max(0, required_gem - (left_of_home & gem ? 1: 0)));
  66. [left] true -> (required_gem'=max(0, required_gem - (right_of_home & gem ? 1 : 0)));
  67. [top] true -> (required_gem'=max(0, required_gem - (below_of_home & gem ? 1 : 0)));
  68. [down] true -> (required_gem'=max(0, required_gem - (above_of_home & gem ? 1 : 0)));
  69. endmodule
  70. label "success" = required_gold=0 & required_gem=0;