def result(self, alpha=None, beta=None): map_ = self.getMap().copy() map_.playerx = self.getStat("xPlayer", "ACT") >= 2 map_.scored = len(map_) - self.time map_.const = (map_.x - 1) / 2 result = None if self.value is not None: result = -(map_.scored + 1) // 2 else: # We have to check if we are one turn away from victory token = "x" if map_.playerx else "o" for x in range(map_.x): y = udebs_config.BOTTOM(map_, x) if y is not None: if udebs_config.win(map_, token, (x, y)) >= self.win_cond: result = (map_.scored + 1) // 2 break if result: if alpha and result < alpha: return alpha elif beta and result > beta: return beta return result if not beta: beta = (map_.scored - 1) // 2 if not alpha: alpha = -beta return self.negamax(alpha, beta, map_)
def result(self, alpha=-1, beta=1): if self.value is not None: return -abs(self.value) map_ = self.getMap() player = "xPlayer" if self.getStat("xPlayer", "ACT") >= 2 else "oPlayer" token = "x" if player == "xPlayer" else "o" for x in range(map_.x): y = udebs_config.BOTTOM(map_, x) if y is not None: if udebs_config.win(map_, token, (x, y)) >= self.win_cond: return 1 return self.negamax(alpha, beta)
def legalMoves(self): map_ = self.map["map"] player = "xPlayer" if self.getStat("xPlayer", "ACT") >= 2 else "oPlayer" other = self.getStat("oPlayer" if player == "xPlayer" else "xPlayer", "token") token = self.getStat(player, "token") options = [] forced = None backup = None for x in range(map_.x): y = udebs_config.BOTTOM(map_, x) if y is not None: loc = (x, y) if udebs_config.win(map_, other, loc) >= self.win_cond: if forced is not None: yield 1 return forced = loc if y > 0: if udebs_config.win(map_, other, (x, y - 1)) >= self.win_cond: # We cannot play here unless it is our only option backup = 1 if forced == loc: yield 1 return continue # finally these are our only good options if forced is None: options.append(loc) if forced: yield player, forced, "drop" elif len(options) > 0: const = (map_.x - 1) / 2 huristic = lambda x: abs(const - x[0]) for loc in sorted(options, key=huristic): yield player, loc, "drop" else: yield backup if backup else 0
def result(self, alpha=-1, beta=1): if self.value is not None: return -abs(self.value) map_ = self.getMap().copy() map_.playerx = self.getStat("xPlayer", "ACT") >= 2 map_.const = (map_.x - 1) / 2 token = "x" if map_.playerx else "o" for x in range(map_.x): y = udebs_config.BOTTOM(map_, x) if y is not None: if udebs_config.win(map_, token, (x,y)) >= self.win_cond: return 1 return self.negamax(alpha, beta, map_)