예제 #1
0
    def update_game(self:Dealer, player:Player, stack_index:Int, stacks:List(List(Tuple(Int, Int))))->\
            Tuple(Int, List(List(Tuple(Int, Int)))):
        """
        update playe's bull points based on chosen stack
        :param stack_index: Int
        :param stacks: [[Tuple...]...] where len(stacks)=4
        :return: Tuple
        """
        top_cards = list(map(lambda stack: stack[-1], stacks))
        discarded_index = player.discard()
        discarded = player.cards.pop(discarded_index)

        if discarded[0] < min(list(map(lambda card: card[0], top_cards))):
            bull_points = sum(
                list(map(lambda card: card[1], stacks[stack_index])))
            new_stacks = self.replace_card(discarded, stack_index, stacks)
            return bull_points, new_stacks

        else:
            my_stack = stacks[stack_index]
            if len(my_stack) == stack_size:
                bull_points = sum(list(map(lambda card: card[1], my_stack)))
                new_stacks = self.replace_card(discarded, stack_index, stacks)
                return (bull_points, new_stacks)
            else:
                new_stacks = deepcopy(stacks)
                new_stacks[stack_index].append(discarded)

                return 0, new_stacks
예제 #2
0
 def create_deck(self, deck_size, bull_points=retic_cast(0.5, Float, Dyn, '\ndealer.py:48: Parameter <_ast.arg object at 0x1022bad30> has a default value %s which does not match specified type Dyn. (code DEFAULT_MISMATCH)'), order=retic_cast(0.5, Float, Dyn, '\ndealer.py:48: Parameter <_ast.arg object at 0x1022bad68> has a default value %s which does not match specified type Dyn. (code DEFAULT_MISMATCH)')):
     retic_cast(seed, Dyn, Function(AnonymousParameters([Dyn]), Dyn), "\ndealer.py:57:8: Expected function of type Function(['Dyn'], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)")(bull_points)
     cards = []
     for i in retic_cast(range, Dyn, Function(AnonymousParameters([Dyn]), Dyn), "\ndealer.py:59:17: Expected function of type Function(['Dyn'], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)")(deck_size):
         cards.append(retic_cast(((i + 1), retic_cast(randrange, Dyn, Function(AnonymousParameters([Int, Int]), Dyn), "\ndealer.py:60:33: Expected function of type Function(['Int', 'Int'], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)")(min_val, max_val)), Tuple(Dyn, Dyn), Dyn, '\ndealer.py:60:12: Expected argument of type Dyn but value %s was provided instead. (code ARG_ERROR)'))
     s = (order or retic_cast(random, Dyn, Function(AnonymousParameters([]), Dyn), '\ndealer.py:61:21: Expected function of type Function([], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)')())
     retic_cast(shuffle, Dyn, Function(AnonymousParameters([List(Dyn), Function(NamedParameters([]), Dyn)]), Dyn), "\ndealer.py:62:8: Expected function of type Function(['List(Dyn)', 'Function([], Dyn)'], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)")(cards, (lambda : s))
     return retic_cast(cards, List(Dyn), Dyn, '\ndealer.py:63:8: A return value of type Dyn was expected but a value %s was returned instead. (code RETURN_ERROR)')
예제 #3
0
def accumulated_s(probabilities: List(Float)) -> List(Float):
    total = sum(probabilities)
    payoffs = probabilities
    result = []
    next = 0
    for element in payoffs:
        next += element
        result = result + [next / total]
    return result
예제 #4
0
def create_nodes(edges: List(Tuple(Int, Int, Int))) -> List(Int):
    all_nodes = set()
    for edge in edges:
        e1 = edge[0]
        e2 = edge[1]
        if e1 not in all_nodes:
            all_nodes.add(e1)
        if e2 not in all_nodes:
            all_nodes.add(e2)
    return list(all_nodes)
예제 #5
0
 def update_trait_counts(self:CardPlay, species_trait_count:List(Int))->List(Int):
     """
     Append the species trait count to the given list
     if this is an ExchangeForSpecies
     :param species_trait_count: All trait counts up to this card play
     :type species_trait_count:[Nat, ...]
     :return: updated list of trait counts
     :rtype: [Nat, ...]
     """
     raise NotImplementedError("Method not yet implemented")
예제 #6
0
def output_result(res: List(Tuple(Int, Int)),
                  edges: List(Tuple(Int, Int))) -> List(String):
    results = []
    for e in edges:
        n1 = e[0]
        n2 = e[1]
        if (n1, n2) in res or (n2, n1) in res:
            results.append("yes")
        else:
            results.append("no")
    return results
예제 #7
0
 def __init__(self: Dealer, players: List(Player), bull_points: List(Int),
              cards_per_game: Int) -> Void:
     """
     :param deck: [Card ...]
     :param players: [Player ...]
     :param bull_points: [Int ...]
     """
     self.deck = self.create_deck(cards_per_game)
     self.players = players
     self.bull_points = bull_points
     self.cards_per_game = cards_per_game
예제 #8
0
 def create_stacks(self: Dealer) -> (List(List(Tuple(Int, Int)))):
     """
     create 4 new stacks each having 1 card from the deck
     at the start of every round
     Initialize all players with that stack
     :return: [[Tuple] ...]
     """
     stacks = []
     for i in range(4):
         stacks.append([self.deck.pop()])
     return stacks
예제 #9
0
def choose_randomly(probabilities: List(Float), speed: Int) -> List(Int):

    s = accumulated_s(probabilities)
    res = []  ### changed here
    for n in range(speed):
        #r = random()
        r = next(rand_num)
        for i in range(len(s)):
            if r < s[i]:
                res = res + [i]  ### and here
                break
    return res  ### and here
예제 #10
0
def simulation_to_lines(data: List(Float)) -> List(Tuple(Int, Float)):
    """
    Turn average payoffs into a list of Cartesian points
    :param data: [Payoffs]
    :return: None
    """
    result = []
    counter = 0
    for payoff in data:
        result = result + [(counter, payoff)]
        counter += 1
    return result
예제 #11
0
 def replace_card(
     self: Dealer, card: Tuple(Int, Int), index: Int,
     stacks: List(List(Tuple(Int, Int)))
 ) -> List(List(Tuple(Int, Int))):
     """
     Replaces stack with card and returns new stack
     :param card: Tuple
     :param index: Int
     :param stacks: [[Tuples ...] ...]
     :return [[Tuple...]...]
     """
     new_stacks = deepcopy(stacks)
     new_stacks[index] = [card]
     return new_stacks
예제 #12
0
    def interact(self: Automaton, other: Automaton, r: Int) -> List(Automaton):
        """
        the sum of pay-offs for the two respective automata over all rounds
        :param other: Automaton
        :param r: rounds
        :return: (Automaton)
        """
        c1 = self.current
        y1 = self.payoff
        t1 = self.table
        c2 = other.current
        y2 = other.payoff
        t2 = other.table

        for i in range(0, r):
            input = c2
            (p1, p2) = self.PAYOFF_TABLE[c1][input]

            c1 = t1[c1][input]
            y1 = y1 + p1
            c2 = t2[c2][c1]
            y2 = y2 + p2
        self.current = c1
        self.payoff = y1
        other.current = c2
        other.payoff = y2
        return [self, other]
예제 #13
0
 def get_card_indices(self:CardPlay)->List(Int):
     """
     Get the indices of the TraitCards used by this CardPlay
     :return: list of the indices used
     :rtype: [Nat, ...]
     """
     return [self.played_card_index]
예제 #14
0
 def output_scores(self):
     res = []
     for i in retic_cast(range, Dyn, Function(AnonymousParameters([Dyn]), Dyn), "\ndealer.py:84:17: Expected function of type Function(['Dyn'], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)")(retic_cast(len, Dyn, Function(AnonymousParameters([Dyn]), Dyn), "\ndealer.py:84:23: Expected function of type Function(['Dyn'], Dyn) at call site but but value %s was provided instead. (code FUNC_ERROR)")(retic_cast(self, Dyn, Object('', {'players': Dyn, }), '\ndealer.py:84:27: Accessing nonexistant object attribute players from value %s. (code WIDTH_DOWNCAST)').players)):
         player_points = retic_cast(self, Dyn, Object('', {'bull_points': Dyn, }), '\ndealer.py:85:28: Accessing nonexistant object attribute bull_points from value %s. (code WIDTH_DOWNCAST)').bull_points[i]
         player_name = retic_cast(retic_cast(self, Dyn, Object('', {'players': Dyn, }), '\ndealer.py:86:26: Accessing nonexistant object attribute players from value %s. (code WIDTH_DOWNCAST)').players[i], Dyn, Object('', {'name': Dyn, }), '\ndealer.py:86:26: Accessing nonexistant object attribute name from value %s. (code WIDTH_DOWNCAST)').name
         res.append(retic_cast((player_name, player_points), Tuple(Dyn, Dyn), Dyn, '\ndealer.py:87:12: Expected argument of type Dyn but value %s was provided instead. (code ARG_ERROR)'))
     return retic_cast(res, List(Dyn), Dyn, '\ndealer.py:88:8: A return value of type Dyn was expected but a value %s was returned instead. (code RETURN_ERROR)')
예제 #15
0
def get_netloc(entry: Tuple(List(String), Dict(String, String)),
               parser: SSHConfig) -> Tuple(String, String):
    hostname = "".join(entry[0])  #bg
    if hostname == "*":
        return ("*", NO_PORT)
    port = parser.lookup(hostname).get('port')
    return (hostname, port)
예제 #16
0
def generate_dealer(players: List(Player), cards_per_game: Int) -> Dealer:
    """
    Instantiates the dealer which will take over the game
    :return: Dealer
    """
    points = [0 for i in range(len(players))]
    return Dealer(players, points, cards_per_game)
예제 #17
0
 def _get_hosts(self:SSHConfig, host:String)->List(String):
     """
     Return a list of host_names from host value.
     """
     try:
         return shlex.split(host)
     except ValueError:
         raise Exception("Unparsable host %s" % host)
예제 #18
0
 def get_minimum_cost_flow(self:PythonFlow, path:List(Int))->Int:
     source = 0
     min = 9999
     for x in path:
         if min > self.residual[source][x]:
             min = self.residual[source][x]
         source = x
     return min
예제 #19
0
 def _allowed(self:SSHConfig, hosts:List(String), hostname:String)->Bool:
     match = False
     for host in hosts:
         if host.startswith('!') and fnmatch.fnmatch(hostname, host[1:]):
             return False
         elif fnmatch.fnmatch(hostname, host):
             match = True
     return match
예제 #20
0
 def get_options(self:PythonFlow, initial_vertex:Int)->List(Int):
     retval = []
     index = 0
     for x in self.graph[initial_vertex]:
         if index != initial_vertex and self.residual[initial_vertex][index] != 0:
             retval.append(index)
         index += 1
     return retval
예제 #21
0
def execute(lines: List(String), template_file: String) -> String:
    netlocs = get_netlocs(lines)

    #bg simplified
    dirpath, filename = os.path.split(template_file)
    template_context = [(hostname, '%s:%s' % (hostname, port))
                        for hostname, port in netlocs.items()]
    return str(sorted(template_context, key=lambda x: x[0]))
예제 #22
0
 def __init__(self:Player, name:Int, cards:List(Tuple(Int,Int)))->Void:
     """
     :param name: Int
     :param cards: [Tuple...]
     :param strat: Function, to be called on face values of cards
     :return: Player
     """
     self.name = name
     self.cards = cards
예제 #23
0
 def apply_path(self:PythonFlow, path:List(Int))->Void:
     cost = self.get_minimum_cost_flow(path)
     #		print "applying cost:",cost
     self.total_flow += cost
     source = 0
     for x in path:
         self.flow[source][x] += cost
         source = x
     self.update_residual()
예제 #24
0
    def verify_self(
        self: ExchangeForSpecies, player_state: PlayerState,
        food_card_index: Int, card_plays_before_this: List(CardPlay)) -> Bool:
        verify_rest = super(ExchangeForSpecies,
                            self).verify_self(player_state, food_card_index,
                                              card_plays_before_this)
        verify_loi = player_state.validate_trait_cards_indicies(self.loi)

        return verify_loi and verify_rest
예제 #25
0
def kruskal(nodes:List(Int), edges:List(Tuple(Int, Int, Int)), edges_to_check:List(Tuple(Int, Int)))\
        ->List(Tuple(Int, Int, Int)):
    sets = UnionFind({})
    mst = []
    for n in nodes:
        sets.add_node(n)

    for e in sorted(edges, key=itemgetter(2)):
        n1 = e[0]
        n2 = e[1]
        l1 = sets.find(n1)
        l2 = sets.find(n2)
        if l1 != l2:
            (e1, e2, w) = e
            if ((e1, e2) in edges_to_check) or (e2, e1) in edges_to_check:
                mst.append(e)
            sets.union(l1, l2)
    return mst
예제 #26
0
 def split(self, line: String) -> List(String):
     """
     Transforms line to list of characters
     :param line: String
     :return: List of characters
     """
     chars = []
     for c in line:
         chars.append(c)
     return chars
예제 #27
0
def generate_players(num_players: Int) -> List(Player):
    """
    instantiates n players with an empty list of cards
    :param num_players: int
    :return: [Players...]
    """
    players = []
    for i in range(num_players):
        players.append(Player(i, []))
    return players
예제 #28
0
 def get_index_of_closest_stack(self:Player, cards:List(Tuple(Int,Int)), card:Tuple(Int,Int))->Int:
     """
     gets index of stack closest to card in value
     :param cards: [Tuple ...]
     :return: Int
     """
     diffs = []
     for c in cards:
         diff = abs(card[0] - c[0])
         diffs.append(diff)
     return diffs.index(min(diffs))
예제 #29
0
 def output_scores(self: Dealer) -> List(Tuple(Int, Int)):
     """
     Outputs the names of the winning and losing players
     :param players: [Player ...]
     :return: (Player, Player)
     """
     res = []
     for i in range(len(self.players)):
         player_points = self.bull_points[i]
         player_name = self.players[i].name
         res.append((player_name, player_points))
     return res
예제 #30
0
    def choose_correct_stack(self:Player, stacks:List(List(Tuple(Int,Int))))->Int:
        """
        Returns the index of the correct stack
        :param stacks: [[Tuple ...]...]
        :return: Int
        """
        top_cards = list(map(lambda stack: stack[-1], stacks))
        discarded_index = self.discard()
        discarded = self.cards[discarded_index]
        if discarded[0] < min(list(map(lambda card: card[0], top_cards))):

            sums = []
            for stack in stacks:
                bull_points = list(map(lambda card: card[1], stack))
                sums.append(sum(bull_points))


            return sums.index(min(sums))

        else:
            return self.get_index_of_closest_stack(top_cards, discarded)