Skip to content

Commit

Permalink
Print probability values in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
Prajwal-Prathiksh committed Mar 9, 2023
1 parent 3327e09 commit 2d02a25
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions dreamsweeper-sdl-old.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,6 @@ def hint(self):
x, y = min(items, key=self._hint_score)[0]
self.set_value(x, y, CLEAR_Q)
return True

total = sum(probabilities.itervalues())

if total == 0:
return False

choice = random.randint(1, total)

cumsum = 0
for x, y in probabilities:
cumsum += probabilities[x, y]
if cumsum >= choice:
self.clear_space(x, y)
return True

def maybe_hint(self):
solver = self.get_solver()
Expand All @@ -302,6 +288,12 @@ def draw_board(board, switches):

if '/p' in switches:
probabilities, total = board.get_mine_probabilities()
# Clear terminal
print('\x1b[2J', end='')
print('Total:', total)
print('Probabilities:')
for i in probabilities:
print(i, probabilities[i]/total)

for x in range(board.width):
for y in range(board.height):
Expand All @@ -314,6 +306,11 @@ def draw_board(board, switches):
if (x, y) in board.solver.solved_spaces:
g = board.solver.solved_spaces[x, y] * 255
border = 1
if g == 255:
txt = " --> (mine)"
else:
txt = " --> (clear)"
print('Solved Spaces: ', [x, y], txt)
elif (x, y) in probabilities:
g = int(probabilities[x, y] * 255 // total)
border = 2
Expand Down

0 comments on commit 2d02a25

Please sign in to comment.