aboutsummaryrefslogtreecommitdiffstats
path: root/src/textDisplay.py
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2021-11-07 14:34:08 -0600
committerNeil Kollack <nkollack@gmail.com>2021-11-07 14:34:08 -0600
commit5b27e9d273c43fd59905a7f126ddf8edfab7fae7 (patch)
tree489011e86a50a7d7bd4fd0c1c7be09d634d1de45 /src/textDisplay.py
parent90d43312138b00ddbe547aef667869915fd10a0a (diff)
initial commit
Diffstat (limited to 'src/textDisplay.py')
-rw-r--r--src/textDisplay.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/textDisplay.py b/src/textDisplay.py
new file mode 100644
index 0000000..e920ad4
--- /dev/null
+++ b/src/textDisplay.py
@@ -0,0 +1,81 @@
+# textDisplay.py
+# --------------
+# Licensing Information: You are free to use or extend these projects for
+# educational purposes provided that (1) you do not distribute or publish
+# solutions, (2) you retain this notice, and (3) you provide clear
+# attribution to UC Berkeley, including a link to http://ai.berkeley.edu.
+#
+# Attribution Information: The Pacman AI projects were developed at UC Berkeley.
+# The core projects and autograders were primarily created by John DeNero
+# (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu).
+# Student side autograding was added by Brad Miller, Nick Hay, and
+# Pieter Abbeel (pabbeel@cs.berkeley.edu).
+
+
+import time
+try:
+ import pacman
+except:
+ pass
+
+DRAW_EVERY = 1
+SLEEP_TIME = 0 # This can be overwritten by __init__
+DISPLAY_MOVES = False
+QUIET = False # Supresses output
+
+class NullGraphics:
+ def initialize(self, state, isBlue = False):
+ pass
+
+ def update(self, state):
+ pass
+
+ def checkNullDisplay(self):
+ return True
+
+ def pause(self):
+ time.sleep(SLEEP_TIME)
+
+ def draw(self, state):
+ print state
+
+ def updateDistributions(self, dist):
+ pass
+
+ def finish(self):
+ pass
+
+class PacmanGraphics:
+ def __init__(self, speed=None):
+ if speed != None:
+ global SLEEP_TIME
+ SLEEP_TIME = speed
+
+ def initialize(self, state, isBlue = False):
+ self.draw(state)
+ self.pause()
+ self.turn = 0
+ self.agentCounter = 0
+
+ def update(self, state):
+ numAgents = len(state.agentStates)
+ self.agentCounter = (self.agentCounter + 1) % numAgents
+ if self.agentCounter == 0:
+ self.turn += 1
+ if DISPLAY_MOVES:
+ ghosts = [pacman.nearestPoint(state.getGhostPosition(i)) for i in range(1, numAgents)]
+ print "%4d) P: %-8s" % (self.turn, str(pacman.nearestPoint(state.getPacmanPosition()))),'| Score: %-5d' % state.score,'| Ghosts:', ghosts
+ if self.turn % DRAW_EVERY == 0:
+ self.draw(state)
+ self.pause()
+ if state._win or state._lose:
+ self.draw(state)
+
+ def pause(self):
+ time.sleep(SLEEP_TIME)
+
+ def draw(self, state):
+ print state
+
+ def finish(self):
+ pass