Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

textDisplay.py 2.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  1. # textDisplay.py
  2. # --------------
  3. # Licensing Information: Please do not distribute or publish solutions to this
  4. # project. You are free to use and extend these projects for educational
  5. # purposes. The Pacman AI projects were developed at UC Berkeley, primarily by
  6. # John DeNero (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu).
  7. # For more info, see http://inst.eecs.berkeley.edu/~cs188/sp09/pacman.html
  8. import pacman, time
  9. DRAW_EVERY = 1
  10. SLEEP_TIME = 0 # This can be overwritten by __init__
  11. DISPLAY_MOVES = False
  12. QUIET = False # Supresses output
  13. class NullGraphics:
  14. def initialize(self, state, isBlue=False):
  15. pass
  16. def update(self, state):
  17. pass
  18. def pause(self):
  19. time.sleep(SLEEP_TIME)
  20. def draw(self, state):
  21. print(state)
  22. def finish(self):
  23. pass
  24. class PacmanGraphics:
  25. def __init__(self, speed=None):
  26. if speed != None:
  27. global SLEEP_TIME
  28. SLEEP_TIME = speed
  29. def initialize(self, state, isBlue=False):
  30. self.draw(state)
  31. self.pause()
  32. self.turn = 0
  33. self.agentCounter = 0
  34. def update(self, state):
  35. numAgents = len(state.agentStates)
  36. self.agentCounter = (self.agentCounter + 1) % numAgents
  37. if self.agentCounter == 0:
  38. self.turn += 1
  39. if DISPLAY_MOVES:
  40. ghosts = [pacman.nearestPoint(state.getGhostPosition(i)) for i in
  41. range(1, numAgents)]
  42. print("%4d) P: %-8s" % (
  43. self.turn, str(pacman.nearestPoint(state.getPacmanPosition()))),
  44. '| Score: %-5d' % state.score, '| Ghosts:', ghosts)
  45. if self.turn % DRAW_EVERY == 0:
  46. self.draw(state)
  47. self.pause()
  48. if state._win or state._lose:
  49. self.draw(state)
  50. def pause(self):
  51. time.sleep(SLEEP_TIME)
  52. def draw(self, state):
  53. print(state)
  54. def finish(self):
  55. pass
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...