当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.purgelines方法代码示例

本文整理汇总了Python中config.Configuration.purgelines方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.purgelines方法的具体用法?Python Configuration.purgelines怎么用?Python Configuration.purgelines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.Configuration的用法示例。


在下文中一共展示了Configuration.purgelines方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import purgelines [as 别名]
    def __init__(self, *pars, **kpars):
        AnchorLayout.__init__(self, *pars, **kpars)
        self.cur_dir = dirname(abspath('file'))
        config = Configuration()
        config.purgelines()
        config.initialize()

        # do not use '-' or other chars in the name!
        self.username = ''

        self.turnables = config.getParam('turnable')
        self.cards_unturnable = bool(int(config.getParam('cards_unturnable')))

        # enables the automatic player agent, playing as NK as default. 
        self.rp = None  # Rule Parser
        self.auto_player = bool(int(config.getParam('auto_player')))
        if self.auto_player:
            self.rp = RuleParser()
            self.rp.load_rules()

        self.format = config.getParam('format')
        self.help_file = config.getParam('help_file')
        self.shoe_file = config.getParam('shoe_file')

        self.srv = config.getParam('server')
        self.srv_port = config.getParam('server_port')

        if self.format == 'circular':
            self.turnable = dict(zip(TTTGame.CIRCULAR_CARD_LAYOUT, [bool(int(x)) for x in self.turnables.split(',')]))
        else:
            self.turnable = dict(zip(TTTGame.LINEAR_CARD_LAYOUT, [bool(int(x)) for x in self.turnables.split(',')]))

        self.timer_start = int(config.getParam('timer_start'))

        # load default shoe_file:
        self.shoe_config = Configuration(config_file=self.shoe_file)
        self.shoe_config.purgelines()

        # self.turn = ''  # current player turn
        self.current_target_card = ''  # the target card stated in the shoe_file ("2H" usually)

        print self.shoe_config.content

        self.hands = []  # store all hands
        # file names are in the form: output-<dmY>-<HM>.txt
        # Here we just create a reference. The actual obj is made when the login popup is dismissed
        self.fout_handle = None
        self.fout_time_handle = None

        self.timeHistory = []  # list holding the strings: <move> <time>\n
        self.stopwatch = StopWatch()

        self.nk_history_q = deque([], 2)  # nk history of the last 2 hands. Required for automatic agent
        self.ck_history_q = deque([], 2)  # ck history of the last 2 hands. Required for automatic agent
开发者ID:jpg75,项目名称:TTT-kivy,代码行数:56,代码来源:tttgame.py

示例2: build

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import purgelines [as 别名]
 def build(self):
     server = LogServer()
     cfg = Configuration(config_file='server-config.txt')
     cfg.purgelines()
     cfg.initialize()
     
     try:
         reactor.listenTCP(LogServerApp.port, LogProtocolFactory(self,
                     server_shoe_file='data/' + cfg.getParam('shoe_file'), 
                     users_shoe_file='data/' + cfg.getParam('users_shoe_file')))
         
         LogServerApp.service_p = TTTMulticastDiscoveryCI(TTTMulticastDiscoveryCI.MODES['server'], LogServerApp.port)
         reactor.listenMulticast(TTTMulticastDiscoveryCI.PORT, LogServerApp.service_p, listenMultiple=True)
     except Exception as e:
         print e
         pass
     
     LogServerApp.s = server
     return server
开发者ID:jpg75,项目名称:TTT-kivy,代码行数:21,代码来源:logserver.py

示例3: TTTGameApp

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import purgelines [as 别名]
class TTTGameApp(App):
    connection = None
    g = None

    def build(self):
        global g 
        self.nr = 0
        self.config = Configuration()
        self.config.purgelines()
        self.config.initialize()
        game = TTTGame()
        self.g = game
                
        self.mp = TTTMulticastDiscoveryCI(TTTMulticastDiscoveryCI.MODES['client'])
            
        reactor.listenMulticast(TTTMulticastDiscoveryCI.PORT, self.mp, listenMultiple=True)
        
        Clock.schedule_once(lambda dt: game.post_init())
        Clock.schedule_once(lambda dt: self.discover_server(), 1)
        return game

    def connect_to_server(self, host, port):
        reactor.connectTCP(host, port, LogClientFactory(self))
        # reactor.connectTCP(host, port, EchoClientFactory(self))
    
    def on_connection(self, connection):
        self.connection = connection
        print 'Connected to server!'
        self.g.console.text += 'Connected to server %s\n' % connection.transport.getPeer()
        
        self.g.connection_popup.quit()
        self.login()
    
    def login(self):
        self.g.show_login_popup()
        
    def on_connection_failed(self, reason):
        self.g.connection_popup.update_label(' Connection FAILED')
        
    def send_message(self, data):
        """Send the whole data content to the connection handle.
        """
        if data and self.connection:
            self.connection.sendLine(str(data))

    def discover_server(self):
        if self.nr < 3: 
            if len(self.mp.servers) == 0:
                print "No servers yet"
                self.mp.query()
                Clock.schedule_once(lambda dt: self.discover_server(), 5)
                self.nr += 1
            else:
                ips = self.mp.servers.keys()
                # print 'Discovered server: %s at port %d\n' % (ips[0], self.mp.servers[ips[0]])
                self.g.console.text += 'Discovered server: %s @ port %d\n' % (ips[0], self.mp.servers[ips[0]])
                self.connect_to_server(ips[0], self.mp.servers[ips[0]])
        else:
            print "Multicast failed, trying direct connection..."
            self.connect_to_server(self.config.getParam('server'), int(self.config.getParam('server_port')))
            
        
    def receive(self, msg):
        if msg.startswith('ask_reply'):
            lines = msg.split('\n')
            lines = [x for x in lines if x != '' and not x.startswith('#') and 
                     not x.startswith('//') ]
            print lines[1:]
            self.g.shoe_config.content = lines[1:]
            self.g.total_runs = len(self.g.shoe_config.content) # updates counter in GUI
            # g.console.text += msg + '\n'
            
    def log(self, msg, log='MOVES',):
        self.send_message('log:' + log)
        self.send_message(msg)
开发者ID:jpg75,项目名称:TTT-kivy,代码行数:77,代码来源:bensim.py

示例4: TTTGame

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import purgelines [as 别名]
class TTTGame(AnchorLayout):
    bottom_bar = ObjectProperty(None)
    game_table = ObjectProperty(None)
    side_bar = ObjectProperty(None)
    console = ObjectProperty(None)
    timer = ObjectProperty(None)
    hand = ListProperty()

    total_moves = NumericProperty(0)
    moves = NumericProperty(0)
    current_player = StringProperty('ck')  # instead of self.turn!
    run = NumericProperty(1)
    total_runs = NumericProperty()

    history_record = {'move': '', 'hand': '', 'up': '', 'target': ''}

    game_card_file = StringProperty('data/card_back_blue.jpeg')

    """ Default covered cards for each position on table"""
    TTT_COVERED_CARDS_ZONES = {"Up Position": False, "DownC Position": True,
                               "DownN Position": True, "Target Position": False,
                               "Color Position": False, "Number Position": False}

    """'linear' card layout. See 'format' parameter in config file."""
    LINEAR_CARD_LAYOUT = ["DownC Position",
                          "Color Position", "Up Position", "Target Position",
                          "DownN Position", "Number Position"]

    """'circular' card layout. This is the default format. See 'format'
    parameter in config file."""
    CIRCULAR_CARD_LAYOUT = ["Number Position",
                            "DownN Position", "Up Position", "DownC Position",
                            "Color Position", "Target Position"]

    """file names for each card. The file holds the corresponding card picture.
    It follows the order in HOME_CARDS_COORDINATES"""
    cards_files = ["h2red.jpeg", "h3red.jpeg",
                   "h4red.jpeg", "c2black.jpeg", "c3black.jpeg", "c4black.jpeg"]

    """card names, they corresponds to the card agent names"""
    cards_names = ["2H", "3H", "4H", "2C", "3C", "4C"]

    """zones names here follow the order in HOME_CARDS_COORDINATES array"""
    cards_zones_names = ["Color Position", "Target Position", "Number Position",
                         "DownC Position", "Up Position", "DownN Position"]

    """Allowed zones in which players can exchange/move cards. The 'Target' zone
    is subjected to extra restrictions."""
    allowed_moving_zones = ["Up Position", "Target Position", "DownC Position",
                            "DownN Position"]

    """map zones -> moves"""
    ZONES_MOVES = {"Up Position": "U", "DownC Position": "C",
                   "DownN Position": "N", "Target Position": "T", "Pass": "P"}
    
    """map card name -> card picture file"""
    cards_names_files = {"2H": "h2red.jpeg", "3H": "h3red.jpeg", "4H": "h4red.jpeg",
                         "2C": "c2black.jpeg", "3C": "c3black.jpeg", "4C": "c4black.jpeg"}

    """map card name -> color """
    cards_colors = {"2H": "red", "3H": "red", "4H": "red",
                    "2C": "black", "3C": "black", "4C": "black"}

    """map card name -> number """
    cards_numbers = {"2H": 2, "3H": 3, "4H": 4,
                     "2C": 2, "3C": 3, "4C": 4}

    """Map zone name -> card name. Tracks the zone in which a card is located.
    It is updated according to the game moves."""
    zones_cards = dict()

    help_txt = open('data/help_eng.txt', 'r').read()

    hand_history = []  # history related to the current hand

    def __init__(self, *pars, **kpars):
        AnchorLayout.__init__(self, *pars, **kpars)
        self.cur_dir = dirname(abspath('file'))
        config = Configuration()
        config.purgelines()
        config.initialize()

        # do not use '-' or other chars in the name!
        self.username = ''

        self.turnables = config.getParam('turnable')
        self.cards_unturnable = bool(int(config.getParam('cards_unturnable')))

        # enables the automatic player agent, playing as NK as default. 
        self.rp = None  # Rule Parser
        self.auto_player = bool(int(config.getParam('auto_player')))
        if self.auto_player:
            self.rp = RuleParser()
            self.rp.load_rules()

        self.format = config.getParam('format')
        self.help_file = config.getParam('help_file')
        self.shoe_file = config.getParam('shoe_file')

        self.srv = config.getParam('server')
#.........这里部分代码省略.........
开发者ID:jpg75,项目名称:TTT-kivy,代码行数:103,代码来源:tttgame.py


注:本文中的config.Configuration.purgelines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。