-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiprocess.py
43 lines (38 loc) · 1.5 KB
/
multiprocess.py
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
from multiprocessing import Pool
from typing import Tuple
import numpy
"""Resources:
https://stackoverflow.com/questions/20190668/multiprocessing-a-for-loop
https://cuyu.github.io/python/2016/08/15/Terminate-multiprocess-in-Python-correctly-and-gracefully
"""
class CoilSolver:
# test the alg starting level 1
# url = "http://www.hacker.org/coil/index.php?"
boardX: int # number of columns
boardY: int # number of rows
board: numpy.ndarray # this is a 2d array representing the board -- 1 for block, else 0s
level: int # the current level
def solve_board(self) -> None:
"""Applies some algorithm to <board> and attempts to solve it.
"""
succ_path: str = ""
succ_x: int = 0
succ_y: int = 0
for y in range(self.boardY):
for x in range(self.boardX):
if self.board[y][x] == 0:
thing = self.solve_board_recursion(self.board, x, y, "")
# whether or not a successful path has been found
if thing[0]:
# the actual path
succ_path = thing[1]
succ_x = x
succ_y = y
break
if succ_path != "":
break
def solve_board_recursion(self, tempboard: numpy.ndarray, x: int, y: int, path: str) -> Tuple[bool, str]:
if x == 3 and y == 5:
return Tuple[True, "RLDU"]
else:
return Tuple[False, ""]