本文整理汇总了Python中board.Board.get方法的典型用法代码示例。如果您正苦于以下问题:Python Board.get方法的具体用法?Python Board.get怎么用?Python Board.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board.Board
的用法示例。
在下文中一共展示了Board.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pieces_are_placed_and_restored
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
def test_pieces_are_placed_and_restored(self):
width = 4000
height = 4000
board = Board(width, height)
pieces = [(random.randint(0, width), random.randint(0, height), { "i" : random.randint(0, 5000)}) for x in range(0, random.randint(0, 57000))]
for piece in pieces:
board.place(piece[0], piece[1], piece[2])
self.assertEquals(board.get(piece[0], piece[1])["i"], piece[2])
self.assertEquals(len(board.contents()), len(pieces))
示例2: TestQuartoBoard
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
class TestQuartoBoard(unittest.TestCase):
def setUp(self):
self.b1 = Board()
def test_place(self):
self.b1.place(Piece(), 0, 0)
with self.assertRaises(PlaceTakenError):
self.b1.place(Piece(), 0, 0)
def test_get(self):
self.assertEqual(None, self.b1.get(0, 0))
self.b1.place(Piece(), 0, 0)
self.assertEqual(Piece(), self.b1.get(0, 0))
self.b1.place(Piece(False), 0, 1)
self.assertEqual(self.b1.get(0, 0), self.b1.get(0, 1))
self.b1.place(Piece(True, False, False, False), 0, 2)
self.assertNotEqual(self.b1.get(0, 1), self.b1.get(0, 2))
def test_col_victory(self):
self.assertIsNone(self.b1.check_victory((0, 0)), None)
self.b1.place(Piece(), 0, 0)
self.b1.place(Piece(), 0, 1)
self.b1.place(Piece(), 0, 2)
for i in range(4):
self.assertIsNone(self.b1.check_victory((0, i)))
self.b1.place(Piece(), 0, 3)
for i in range(4):
self.assertIsNotNone(self.b1.check_victory((0, i)))
def test_row_victory(self):
self.assertIsNone(self.b1.check_victory((0, 0)), None)
self.b1.place(Piece(), 0, 0)
self.b1.place(Piece(), 1, 0)
self.b1.place(Piece(), 2, 0)
for i in range(4):
self.assertIsNone(self.b1.check_victory((i, 0)))
self.b1.place(Piece(), 3, 0)
for i in range(4):
self.assertIsNotNone(self.b1.check_victory((i, 0)))
def test_cross_victory(self):
self.assertIsNone(self.b1.check_victory((0, 0)), None)
self.b1.place(Piece(), 0, 0)
self.b1.place(Piece(), 1, 1)
self.b1.place(Piece(), 2, 2)
self.b1.place(Piece(), 0, 3)
for i in range(4):
self.assertIsNone(self.b1.check_victory((i, i)))
self.assertIsNone(self.b1.check_victory((i, 3 - i)))
self.b1.place(Piece(), 3, 3)
for i in range(4):
self.assertIsNotNone(self.b1.check_victory((i, i)))
self.assertIsNone(self.b1.check_victory((i, 3 - i)))
示例3: testUse
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
def testUse(self):
val = "x"
b = Board(2, 2)
b.set(1, 1, val)
self.assertEqual(b.get(1, 1), val)
示例4: run
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
def run(self):
self.source.start()
while True:
frame_raw = self.source.read()
if frame_raw is None:
print 'No frame received; terminating.'
return
if self.killed:
print "Vision terminating"
return
reload(configs)
element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (configs.ERODE_RAD,configs.ERODE_RAD))
element2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (configs.DILATE_RAD,configs.DILATE_RAD))
#BEGIN PROCESSING
try:
if configs.VFLIP:
frame = cv2.flip(frame_raw, flipCode=-1)
else:
frame = frame_raw
if configs.DEBUG:
POST("RAW", frame)
luv = cv2.split(cv2.cvtColor(frame, cv2.COLOR_RGB2LUV))
v_chan = luv[2]
if configs.DEBUG:
POST("V", v_chan)
blur = cv2.GaussianBlur(v_chan, (configs.BLUR_RAD,configs.BLUR_RAD), 0)
if configs.DEBUG:
POST("blur", blur)
thresh = cv2.adaptiveThreshold(blur, 255, 0, 1, configs.BOARD_THRESH_PARAM, configs.BOARD_BLOCK_SIZE)
if configs.DEBUG:
POST("thresh", thresh)
erode = cv2.erode(thresh, element)
erode = cv2.dilate(erode, element2)
if configs.DEBUG:
POST("erode", erode)
erode_draw = frame.copy()
contours,hierarchy = cv2.findContours(erode, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
possible_corners = []
#Find large contour closest to center of image
for cnt in contours:
sz = cv2.contourArea(cnt)
if sz>75 and sz < 650:
ellipse = cv2.fitEllipse(cnt)
((x,y), (w,h), r) = ellipse
ar = w / h if w > h else h / w
if ar > 1.8:
continue
pf = (w * h * 0.75) / sz
if pf > 1.5:
continue
cv2.ellipse(erode_draw,ellipse,(0,255,0),2)
possible_corners.append((x,y))
def get_closest_corner(point):
dst = float("inf")
crnr = None
for pc in possible_corners:
d = distance(point, pc)
if d < dst:
dst = d
crnr = pc
if crnr is None:
if configs.DEBUG:
print "Unable to find any corners"
raise IterSkip()
return crnr
img_height, img_width, _ = frame_raw.shape
tl = get_closest_corner((0,0))
br = get_closest_corner((img_width, img_height))
tl = (tl[0] + configs.TL_X, tl[1] + configs.TL_Y)
br = (br[0] + configs.BR_X, br[1] + configs.BR_Y)
tr = get_closest_corner((img_width, 0))
bl = get_closest_corner((0, img_height))
#Check lengths to ensure valid board layout
top_len = distance(tl, tr)
left_len = distance(tl, bl)
#.........这里部分代码省略.........
示例5: run
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
def run(self):
vc = cv2.VideoCapture(-1)
if vc.isOpened(): # try to get the first frame
rval, frame_raw = vc.read()
else:
rval = False
while rval:
if self.killed:
print "Vision terminating"
return
reload(configs)
element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (configs.ERODE_RAD,configs.ERODE_RAD))
element2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (configs.DILATE_RAD,configs.DILATE_RAD))
#BEGIN PROCESSING
try:
frame = cv2.flip(frame_raw, flipCode=-1)
POST("RAW", frame)
luv = cv2.split(cv2.cvtColor(frame, cv2.COLOR_RGB2LUV))
v_chan = luv[2]
#POST("V", v_chan)
blur = cv2.GaussianBlur(v_chan, (configs.BLUR_RAD,configs.BLUR_RAD), 0)
#POST("blur", blur)
thresh = cv2.adaptiveThreshold(blur, 255, 0, 1, configs.BOARD_THRESH_PARAM, configs.BOARD_BLOCK_SIZE)
#POST("thresh", thresh)
erode = cv2.erode(thresh, element)
erode = cv2.dilate(erode, element2)
POST("erode", erode)
erode_draw = frame.copy()
contours,hierarchy = cv2.findContours(erode, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
possible_corners = []
#Find large contour closest to center of image
for cnt in contours:
sz = cv2.contourArea(cnt)
if sz>75 and sz < 650:
ellipse = cv2.fitEllipse(cnt)
((x,y), (w,h), r) = ellipse
ar = w / h if w > h else h / w
if ar > 1.8:
continue
pf = (w * h * 0.75) / sz
if pf > 1.5:
continue
cv2.ellipse(erode_draw,ellipse,(0,255,0),2)
possible_corners.append((x,y))
"""
lines = cv2.HoughLinesP(erode, 1, 3.14/180, 300, minLineLength=200, maxLineGap=100)[0]
m,n = erode.shape
goodlines = lines[:40]
#Calculate intersection points
points = set()
CLUSTER_RAD = 50
clusters = []
for x in goodlines:
for y in goodlines:
i = intersect(x,y)
if i is not None:
added = False
for (ctr, st) in clusters:
if distance(i, ctr) < CLUSTER_RAD:
st.add(i)
added = True
break
if not added:
clusters.append((i,set()))
clustered_points = []
for (_,c) in clusters:
x = 0
y = 0
for p in c:
x += p[0]
y += p[1]
clustered_points.append((len(c), (x / len(c), y / len(c))))
clustered_points.sort(reverse=True)
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
class Game:
cascade = True
def __init__(self, width, height, mines):
self.width = width
self.height = height
self.mines = mines
self.board = Board(width, height)
self.mine_array = MineArray(width, height, mines)
def randomize_mines(self):
self.mine_array.randomize()
def start(self):
self.board.clear()
def new_game(self):
self.randomize_mines()
self.start()
def neighbour_count(self, row, col):
neighbours = self.mine_array.neighbours(row, col)
return sum(self.mine_array.get(*coord) for coord in neighbours)
def on_board(self, row, col):
return (0 <= row < self.height) and (0 <= col < self.width)
def click(self, row, col):
if not self.on_board(row, col):
raise RuntimeError("({}, {}) is not within the bounds of the board.".format(row, col))
if self.mine_array.is_mine(row, col):
for index, val in enumerate(self.mine_array.array):
if val:
self.board.array[index] = Tile.MINE
self.board.set(row, col, Tile.BLAST)
else:
if self.cascade:
self.cascade_open(row, col)
else:
num = self.neighbour_count(row, col)
self.board.set(row, col, Tile.num(num))
def cascade_open(self, row, col):
to_do = [(row, col)]
board = self.board
while to_do:
row, col = to_do.pop()
n_count = self.neighbour_count(row, col)
board.set(row, col, Tile.num(n_count))
if n_count == 0:
for (i, j) in self.mine_array.neighbours(row, col):
if self.board.get(i, j).is_num():
continue
if (i, j) in to_do:
continue
to_do.append((i, j))
def is_solved(self):
for row in range(self.height):
for col in range(self.width):
mine = self.mine_array.get(row, col)
if mine == 0:
if not self.board.get(row, col).is_num():
return False
return True
def __str__(self):
return str(self.board)
示例7: test_piece_placed
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import get [as 别名]
def test_piece_placed(self):
b = Board(2,3)
b.place(2,1,"Foo")
self.assertEquals(b.get(2,1), "Foo")