def findInnerQi(self): """找到内部的、且不可能被对手占据的气""" board_innnerQi = np.zeros((9,9),int) for r in range(9): for c in range(9): # 判定是否为eye if is_koish(self.board_selfNow,(r,c)) != self.color: continue # 是否可能被占据 J = [[r-1,c-1], [r-1,c+1], [r+1,c+1], [r+1,c-1]] is_side = False A = 0 for j in J: if j[0] >= 0 and j[0] <=8 and j[1] >= 0 and j[1] <= 8: if self.board_selfNow[j[0],j[1]] != self.color and is_koish(self.board_selfNow,(j[0],j[1])) != self.color: A += 1 else: is_side = True if A >= 2 or (is_side and A): continue board_innnerQi[r,c] = 1 return board_innnerQi
def test_is_koish(self): self.assertEqual( go.is_koish(utils_test.BOARD_SIZE, TEST_BOARD, coords.from_kgs(utils_test.BOARD_SIZE, 'A9')), BLACK) self.assertEqual( go.is_koish(utils_test.BOARD_SIZE, TEST_BOARD, coords.from_kgs(utils_test.BOARD_SIZE, 'B8')), None) self.assertEqual( go.is_koish(utils_test.BOARD_SIZE, TEST_BOARD, coords.from_kgs(utils_test.BOARD_SIZE, 'B9')), None) self.assertEqual( go.is_koish(utils_test.BOARD_SIZE, TEST_BOARD, coords.from_kgs(utils_test.BOARD_SIZE, 'E5')), None)
def test_is_koish(self): self.assertEqual(go.is_koish(TEST_BOARD, pc('A9')), BLACK) self.assertEqual(go.is_koish(TEST_BOARD, pc('B8')), None) self.assertEqual(go.is_koish(TEST_BOARD, pc('B9')), None) self.assertEqual(go.is_koish(TEST_BOARD, pc('E5')), None)
def test_is_koish(self): self.assertEqual(go.is_koish(TEST_BOARD, coords.from_gtp('A9')), BLACK) self.assertEqual(go.is_koish(TEST_BOARD, coords.from_gtp('B8')), None) self.assertEqual(go.is_koish(TEST_BOARD, coords.from_gtp('B9')), None) self.assertEqual(go.is_koish(TEST_BOARD, coords.from_gtp('E5')), None)
def test_is_koish(self): self.assertEqual(go.is_koish( TEST_BOARD, coords.from_kgs('A9')), BLACK) self.assertEqual(go.is_koish(TEST_BOARD, coords.from_kgs('B8')), None) self.assertEqual(go.is_koish(TEST_BOARD, coords.from_kgs('B9')), None) self.assertEqual(go.is_koish(TEST_BOARD, coords.from_kgs('E5')), None)