예제 #1
0
파일: aglab.py 프로젝트: fullkawa/aglab
 def get_value_reshaped(self,
                        context=None, component=None, field=None,
                        key=None, cindex=None, propname=None, fkey=None, findex=None, scope=None, 
                        column='value', 
                        return_list=False):
     """二次元配列で値を取得する
     """
     values = self.get_value(context=context, component=component, field=field,
                             key=key, cindex=cindex, propname=propname, fkey=fkey, findex=findex, scope=scope,
                             column=column,
                             return_list=return_list)
     #print 'len(values):', len(values) #DEBUG
     
     num_components = len(self.components)
     #print 'num_components:', num_components #DEBUG
     if (key is not None) and (cindex is None):
         key = self._conv_key(key)
         num_components = len(util.dict_search(self.components, ('key', key)))
         #print ' ->', num_components #DEBUG
     
     size_fields = len(self.fields)
     #print 'size_fields:', size_fields #DEBUG
     if (fkey is not None) and (findex is None):
         fkey = self._conv_key(fkey)
         size_fields = len(util.dict_search(self.fields, ('key', fkey)))
         #print ' ->', size_fields #DEBUG
     
     return values.reshape(num_components, size_fields)
예제 #2
0
파일: aglab.py 프로젝트: fullkawa/aglab
 def _conv_key(self, key):
     """keyが短縮形(shorten)だったとき、それを通常のキーに変換する
     """
     if len(util.dict_search(self.fields, ('key', key))) == 0:
         ref = util.dict_search(self.fields, ('shorten', key))
         if (len(ref) > 0) and ('key' in ref[0]):
             return ref[0]['key']
     return key
예제 #3
0
파일: aglab.py 프로젝트: fullkawa/aglab
 def _step_command(self):
     """コマンド実行の前処理
     * 簡易入力形式の変換
     * 定義不要コマンド(set, move, end)の実装
     を含む。
     """
     cmds = string.split(self.command)
     assert cmds is not None
     assert len(cmds) > 0
     
     if (len(cmds) > 1) and (cmds[1] == '>'):
         cmds[1] = cmds[0]
         cmds[0] = 'move'
     proc = util.dict_search(self.on_play, ('command', cmds[0]))
     #print 'proc:', proc #DEBUG
     if len(proc) > 0:
         if len(cmds) > 1:
             proc[0]['args'] = cmds[1:]
         self._process(proc[0], reward=self.reward, report=self.report)
     elif 'move' == cmds[0]:
         assert len(cmds) == 3
         self.state.move_component(cmds[1], cmds[2])
     elif 'set' == cmds[0]:
         assert len(cmds) == 3
         self.state.set_component(cmds[1], cmds[2])
     elif 'end' == cmds[0]:
         self.done = True
     else:
         print 'No command;', cmds
예제 #4
0
파일: aglab.py 프로젝트: fullkawa/aglab
 def output_components(self, fkey):
     """指定されたフィールドにセットされているコンポーネントの出力形式をまとめて取得する
     """
     output = []
     fields = util.dict_search(self.fields, ('key', fkey))
     for field in fields:
         _output = self.output_component(fkey=fkey, findex=field['index'])
         output.append(_output)
     return output