Ejemplo n.º 1
0
    def __init__(self, 
                groups = [], 
                title = "", 
                description = "",
                default_color = "black", 
                alphabet = seq.generic_alphabet) :
        """  """
        self.title= title
        self.description = description
        self.default_color = Color.from_string(default_color)
        self.groups = groups
        self.alphabet = alphabet
            
        color = {}

        if alphabet in [seq.codon_dna_alphabet, seq.codon_rna_alphabet]:
            for cg in groups :
                color[cg.symbols] = cg.color
                if cg.symbols not in alphabet :
                    raise KeyError("Colored symbol does not exist in alphabet.")
        else:
            for cg in groups :
                for s in cg.symbols :
                    color[s] = cg.color
                    if s not in alphabet :
                        raise KeyError("Colored symbol does not exist in alphabet.")

        self._color = color
Ejemplo n.º 2
0
    def __init__(self, text, x, y, **kwargs):

        self.text = text
        self.text_color = kwargs.pop('text_color', Color.from_string('blue'))
        self.font_size = kwargs.pop('font_size', 10)
        self.font_name = kwargs.pop('font_name', 'Times New Roman')
        self.bg_color = kwargs.pop('bg_color', Color(255, 255, 255))
        self.v_spacing = kwargs.pop('v_spacing', 2)
        self.h_spacing = kwargs.pop('h_spacing', 2)
        self.x = x
        self.y = y
        self.batch = pyglet.graphics.Batch()

        self.document = pyglet.text.document.UnformattedDocument(text)
        self.font = self.document.get_font()
        height = self.font.ascent - self.font.descent

        self.label = pyglet.text.Label(self.text,
                                       font_name=self.font_name,
                                       font_size=self.font_size,
                                       x=self.x + self.h_spacing,
                                       y=self.y + self.v_spacing)
        width = self.label.content_width + 1
        self.border = Rectangle(self.x, self.y, width + self.h_spacing,
                                height + self.v_spacing)

        self.size = (width, height)
Ejemplo n.º 3
0
 def __init__(self, 
             groups = [], 
             title = "", 
             description = "",
             default_color = "black", 
             alphabet = seq.generic_alphabet) :
     """  """
     self.title= title
     self.description = description
     self.default_color = Color.from_string(default_color)
     self.groups = groups
     self.alphabet = alphabet
         
     color = {}
     for cg in groups :
         for s in cg.symbols :
             color[s] = cg.color
             if s not in alphabet :
                 raise KeyError("Colored symbol does not exist in alphabet.")
     self._color = color
Ejemplo n.º 4
0
 def __init__(self, symbols, color, description=None) :
     self.symbols = symbols              
     self.color =  Color.from_string(color)
     self.description = description
Ejemplo n.º 5
0
 def __init__(self, symbols, color, description=None) :
     self.symbols = symbols              
     self.color =  Color.from_string(color)
     self.description = description
Ejemplo n.º 6
0
 def parse_level(server_messages) -> 'State':
     # We can assume that the level file is conforming to specification, since the server verifies this.
     # Read domain.
     server_messages.readline() # #domain
     server_messages.readline() # hospital
     
     # Read Level name.
     server_messages.readline() # #levelname
     server_messages.readline() # <name>
     
     # Read colors.
     server_messages.readline() # #colors
     agent_colors = [None for _ in range(10)]
     box_colors = [None for _ in range(26)]
     line = server_messages.readline()
     while not line.startswith('#'):
         split = line.split(':')
         color = Color.from_string(split[0].strip())
         entities = [e.strip() for e in split[1].split(',')]
         for e in entities:
             if '0' <= e <= '9':
                 agent_colors[ord(e) - ord('0')] = color
             elif 'A' <= e <= 'Z':
                 box_colors[ord(e) - ord('A')] = color
         line = server_messages.readline()
     
     # Read initial state.
     # line is currently "#initial".
     num_agents = 0
     agent_rows = [None for _ in range(10)]
     agent_cols = [None for _ in range(10)]
     walls = [[False for _ in range(130)] for _ in range(130)]
     boxes = [['' for _ in range(130)] for _ in range(130)]
     line = server_messages.readline()
     row = 0
     while not line.startswith('#'):
         for col, c in enumerate(line):
             if '0' <= c <= '9':
                 agent_rows[ord(c) - ord('0')] = row
                 agent_cols[ord(c) - ord('0')] = col
                 num_agents += 1
             elif 'A' <= c <= 'Z':
                 boxes[row][col] = c
             elif c == '+':
                 walls[row][col] = True
         
         row += 1
         line = server_messages.readline()
     del agent_rows[num_agents:]
     del agent_rows[num_agents:]
     
     # Read goal state.
     # line is currently "#goal".
     goals = [['' for _ in range(130)] for _ in range(130)]
     line = server_messages.readline()
     row = 0
     while not line.startswith('#'):
         for col, c in enumerate(line):
             if '0' <= c <= '9' or 'A' <= c <= 'Z':
                 goals[row][col] = c
         
         row += 1
         line = server_messages.readline()
     
     # End.
     # line is currently "#end".
     
     return State(agent_rows, agent_cols, agent_colors, walls, boxes, box_colors, goals)
Ejemplo n.º 7
0
 def __init__(self, pvalues, color) :
     self.pvalues = pvalues
     self.color =  Color.from_string(color)