def pretty_string(self, indent_=0): ind = indent(indent_, s=" ") s = f"{ind}Game Result: {self.points}\n" s += f"{ind}Number of Rounds: {len(self.rounds)}\n" s += "----------- Rounds -----------------\n" rind = indent_ + 4 rind_str = indent(rind, s=" ") for k, round_ in enumerate(self.rounds): s += f"{rind_str}----------- Round {k} -----------------\n" s += round_.pretty_string(rind) s += "\n" return s
def min_value(state, alpha, beta, depth): # logging.debug("-min: {}".format(pretty_print_gs(state))) if is_terminal(state, depth): # logging.debug("-min is terminal") return eval_state(state) asts = list(action_state_transisions(state)) logging.debug("min({}){}> fanout:{}".format(depth, indent(depth), len(asts))) v = float("inf") for (a, s) in asts: logging.debug("min({}){}> looking at:{}".format(depth, indent(depth), a)) v = min(v, max_value(s, alpha, beta, depth+1)) if v <= alpha: logging.debug("min({}){}> prune".format(depth, indent(depth))) return v beta = min(beta, v) return v
def pretty_string(self, indent_=0): ind = indent(indent_, s=" ") s = f"{ind}Round Result: {self.points}\n" s += f"{ind}Game Points after Round: {self.final_points}\n" s += f"{ind}ranking: {self.ranking}\n" s += f"{ind}grand tichus: {list(self.announced_grand_tichus)}\n" s += f"{ind}tichus: {list(self.announced_tichus)}\n" s += f"{ind}Number of Tricks: {len(self.tricks)}\n" s += f"{ind}Handcards: \n" s += self.complete_hands.pretty_string(indent_=indent_ + 4) + "\n" ind4 = indent(indent_ + 4, s=' ') s += f"{ind4}---------- Tricks ----------\n" for k, trick in enumerate(self.tricks): s += trick.pretty_string(indent_ + 4) s += "\n" s += f"{ind4}---------- Events ----------\n" s += ind4 s += ("\n" + ind4).join(ev.pretty_string() for ev in self.events) return s
def min_value(self, state, alpha, beta, depth, playerpos): if state in self._mincache: self._hits += 1 # return self._mincache[state] # logging.debug("-min: {}".format(pretty_print_gs(state))) if self.is_terminal(state, depth, playerpos): # logging.debug("-min is terminal") return self.eval_state(state, playerpos) asts = list(self.action_state_transisions(state)) logging.debug("min({}){}> fanout:{}".format(depth, indent(depth), len(asts))) v = float("inf") for (a, s) in asts: logging.debug("min({}){}> looking at:{}".format(depth, indent(depth), a)) v = min(v, self.max_value(s, alpha, beta, depth + 1, playerpos)) if v <= alpha: logging.debug("min({}){}> prune".format(depth, indent(depth))) self._mincache[state] = v return v beta = min(beta, v) self._mincache[state] = v return v
def pretty_string(self, indent_: int = 0) -> str: ind = indent(indent_, s=" ") s = f"{ind}0:{self.handcards0.pretty_string()}\n{ind}1:{self.handcards1.pretty_string()}\n{ind}2:{self.handcards2.pretty_string()}\n{ind}3:{self.handcards3.pretty_string()}" return s
def pretty_string(self, indent_=0): ind_str = indent(indent_, s=" ") if self.is_empty(): return f"{self.__class__.__name__}(empty)" else: return f"{ind_str}{self.__class__.__name__}[{self[-1].player_pos}]: {' -> '.join([comb.pretty_string() for comb in self])}"