Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. def add_fluents(self, turn):
  2. """ Called once per turn, this adds all 'fluents' for example,
  3. haveArrow[t+1] = haveArrow[t] OR shoot_act[t] """
  4. turn += 1
  5.  
  6. breeze_perc.append(Bool("br_perc_%s" % (turn)))
  7. stench_perc.append(Bool("st_perc_%s" % (turn)))
  8. scream_perc.append(Bool("sc_perc_%s" % (turn)))
  9. glitter_perc.append(Bool("gl_perc_%s" % (turn)))
  10. bump_perc.append(Bool("bu_perc_%s" % (turn)))
  11.  
  12. move_act.append(Bool("m_act_%s" % (turn)))
  13. right_act.append(Bool("r_act_%s" % (turn)))
  14. left_act.append(Bool("l_act_%s" % (turn)))
  15. shoot_act.append(Bool("s_act_%s" % (turn)))
  16.  
  17. north.append(Bool("N_%s" % (turn)))
  18. east.append(Bool("E_%s" % (turn)))
  19. west.append(Bool("W_%s" % (turn)))
  20. south.append(Bool("S_%s" % (turn)))
  21.  
  22. wumpus_alive.append(Bool("WumpusAlive_%s" % (turn)))
  23. have_arrow.append(Bool("HaveArrow_%s" % (turn)))
  24.  
  25. tmp_loc = [[Bool("L_%s_%s_%s" % (turn, i + 1, j + 1)) for j in range(8)] for i in range(8)]
  26. tmp_ok = [[Bool("OK_%s_%s_%s" % (turn, i + 1, j + 1)) for j in range(8)] for i in range(8)]
  27. for thing in [tmp_loc, tmp_ok]:
  28. for row in thing:
  29. row.insert(0, row[1])
  30. row.append(row[-2])
  31. thing.insert(0, thing[1])
  32. thing.append(thing[-2])
  33. locations.append(tmp_loc)
  34. ok.append(tmp_ok)
  35.  
  36. self.s.add(have_arrow[turn] == And(have_arrow[turn - 1], Not(shoot_act[turn - 1])))
  37. self.s.add(wumpus_alive[turn] == And(wumpus_alive[turn-1], Not(scream_perc[turn])))
  38. for x in range(1,9):
  39. for y in range(1,9):
  40. self.s.add(ok[turn][x][y] == And(Not(pits[x][y]), Not(And(wumpuses[x][y], wumpus_alive[turn]))))
  41. self.s.add(Implies(locations[turn][x][y], breeze_perc[turn] == breezes[x][y]))
  42. self.s.add(Implies(locations[turn][x][y], stench_perc[turn] == stenches[x][y]))
  43. # For current location:
  44. self.s.add(locations[turn][x][y] == Or(And(locations[turn-1][x][y], Or(Not(move_act[turn-1]),
  45. bump_perc[turn])),
  46. And(locations[turn-1][x-1][y], east[turn-1], move_act[turn-1],
  47. Not(bump_perc[turn])),
  48. And(locations[turn-1][x+1][y], west[turn-1], move_act[turn-1],
  49. Not(bump_perc[turn])),
  50. And(locations[turn-1][x][y-1], north[turn-1], move_act[turn-1],
  51. Not(bump_perc[turn])),
  52. And(locations[turn-1][x][y+1], south[turn-1], move_act[turn-1],
  53. Not(bump_perc[turn]))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement