def is_capturable(victim): "brute-force check of at least one possibility to capture the victim group, limited to groups under 10 liberties." victim = min(victim.group) if victim.color is None or len(victim.group.liberties)>10: return (False, None) exp = victim.grid.fork() colO = victim.color colP = colO is WHITE and BLACK or WHITE def status(): if victim.color is None or len(victim.group.liberties)==0: return True if len(victim.group.liberties)>10: return False return explorer.CONTINUE evP = status evO = status def msP(): return victim.group.liberties def msO(): ret = group_union(victim.grid, (n.liberties for n in victim.group.neighbours if n.color not in (None, victim.color) and len(n.group.liberties)<2)) ret.update(victim.group.liberties) return ret combP = lambda l: reduce(lambda a, b: a or b, l, False) combO = lambda l: reduce(lambda a, b: a and b, l, True) ret = explorer(victim.grid).explore(colP, colO, msP, msO, combP, combO, evP, evO) #victim.grid.delete_position(exp) return ret, exp
def status(A, color=None, maxdepth=10): if color is None: return { BLACK:status(A, BLACK), WHITE:status(A, WHITE) } G = A.grid exp = G.fork() colP = color colO = color is BLACK and WHITE or BLACK player = lambda: group(G, (G.context_by_group[s.group] for s in A if s.color is colP)) opponent = lambda: group(G, (G.context_by_group[s.group] for s in A if s.color is colO)) aji = shape_tree() aji.from_strings(('f!',), None) aji.from_strings(('s!.',), None) aji.from_strings(('s!',' .'), None) def ms(col): #print "ms", col if col is None: return [] #return filter(lambda x: i_can_play_there(x, col), A) return set((b for a,b,c in aji.match_all(ga)[col])) msP = lambda: ms(colP) msO = lambda: ms(colO) def evP(): # return (player_is_alive, opponent_is_alive) #G.dump(A) pia = None oia = None p = player() pm = msP() if not (p and pm): pia = False pe = p.eyes pia = pia or len(pe)>=2 o = opponent() om = msO() if not (o and om): oia = False po = o.eyes oia = oia or len(po)>=2 if pia or oia: return (pia, oia) return explorer.CONTINUE #return (len(pe)>=2 or len(o)==0 or len(opponent().liberties)==1) and True or explorer.CONTINUE combP = lambda l: reduce(lambda a, b: a and b, l, True) combO = lambda l: reduce(lambda a, b: a or b, l, False) ret = explorer(G, maxdepth=maxdepth).explore(colP, colO, msP, msO, combP, combO, evP, evP) #victim.grid.delete_position(exp) return ret, exp