Skip to content

Commit

Permalink
Changes to board detection
Browse files Browse the repository at this point in the history
  • Loading branch information
the-cybersapien committed Apr 14, 2017
1 parent 5edff67 commit 1874618
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
8 changes: 4 additions & 4 deletions SciKit-Play-GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def combo_chosen_2(self):
global c2
global c3
global c4
c1 = int(494)
c2 = int(154)
c3 = int(1135)
c4 = int(717)
c1 = int(436)
c2 = int(55)
c3 = int(1010)
c4 = int(563)

def statistic(self):
url_1 = QtCore.QUrl('utilities\stat_1.pyw')
Expand Down
2 changes: 2 additions & 0 deletions back_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def __init__(self):
def _load(self, path, target_value):
training_imgs = os.listdir(path)
for f in training_imgs:
if f.endswith('.db'):
continue
img = Image.open(path + '/' + f)
img = img.resize(self.down_res, Image.BILINEAR)
self.trainingData.append(np.array(img.getdata()).flatten())
Expand Down
16 changes: 6 additions & 10 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ def __init__(self, board_coords):
self.mover = move_maker.MoveMaker()

self.prev_board = None
# self.background_img = Image.open('background.bmp')
# self.background_img = self.background_img.resize(
# (self.background_img.size[0] / 4, self.background_img.size[1] / 4), Image.NEAREST)
# self.img_end_game = Image.open('end_screen.bmp')
# self.img_end_game = self.img_end_game.resize((self.img_end_game.size[0] / 4, self.img_end_game.size[1] / 4), Image.NEAREST)

def play(self):
moves = []
Expand All @@ -56,15 +51,14 @@ def play(self):
print 'Ending yo!'
break
else:
self.grab_board()
score, mover = self.mover.solve_board(self.game_board, moves)
self.do_move(mover)
time.sleep(0.4) # wait for the cells to finish moving

# It takes the screenshot of the board and then crops each cell using a nested loop
def grab_board(self):
global game_board
img = ImageGrab.grab()

img = img.crop(self.board_box)
for y in range(0, 9):
for x in range(0, 9):
Expand All @@ -84,10 +78,12 @@ def get_board(self):

def checkDiff(self, prev_board):
currentBoard = self.get_board()
if self.compare_images(currentBoard, prev_board, 50) < 30:
return False
else:
if self.compare_images(currentBoard, prev_board, 50) > 30:
print 'They\'re different!!'
return True
else:
print 'They\'re the same!'
return False

# checks if the board is in moving state (It is in moving state after the candies have been exploded)
def board_is_moving(self):
Expand Down
6 changes: 3 additions & 3 deletions move_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ def solve_board(self, board, moves):
for d in possible_directions:
score, move, b = self.check_direction((i, j), d)
if score >= max_score:
# if moves.count(move) is 0 and moves.count([move[1], move[0]]) is 0:
max_score = score
chosen_move = move
if moves.count(move) is 0 or moves.count([move[1], move[0]]) is 0:
max_score = score
chosen_move = move

# if(chosen_move[0][0] == chosen_move[1][0]):
# print 1
Expand Down
1 change: 0 additions & 1 deletion utilities/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
move: 'move\n',
scoreboard: 'scoreboard\n',
shop: 'shop\n',
static: 'static\n'
}

i = 1
Expand Down

0 comments on commit 1874618

Please sign in to comment.