-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautosolver.py
More file actions
48 lines (36 loc) · 1.18 KB
/
autosolver.py
File metadata and controls
48 lines (36 loc) · 1.18 KB
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
import random
import time
import copy
import curses
from board import Board
def AutoSolver(board, keypad_actions):
time.sleep(0.0)
return MaxSolver(board, keypad_actions)
def BogoSolver(board, keypad_actions):
return (random.choice(keypad_actions))
def MaxSolver(board, keypad_actions):
up_board = copy.deepcopy(board)
up_board.MoveUp()
down_board = copy.deepcopy(board)
down_board.MoveDown()
left_board = copy.deepcopy(board)
left_board.MoveLeft()
right_board = copy.deepcopy(board)
right_board.MoveRight()
board_act_map = {
up_board: keypad_actions[0],
down_board: keypad_actions[1],
left_board: keypad_actions[2],
right_board: keypad_actions[3]}
max_score = max([board.score for board in board_act_map.keys()])
for board in board_act_map.keys():
if max_score == board.score:
return board_act_map[board]
if __name__ == "__main__":
board = Board(4)
keypad_actions = {
curses.KEY_UP: board.MoveUp,
curses.KEY_DOWN: board.MoveDown,
curses.KEY_LEFT: board.MoveLeft,
curses.KEY_RIGHT: board.MoveRight, }
MaxSolver(board, keypad_actions.keys())