コード例 #1
0
 def runRoundPlayer(self,player,winner):
     score = 0
     closeType = 1
     if winner == player:
         closeType = readInput("{} close type: ".format(player),int,lambda x: x in [1,2,3,4],"Sorry, invalid Close Type number [1,2,3,4].")
     else:
         score = readInput("{} round score: ".format(player),int,lambda x: x>0,"Sorry, invalid score number.")
     self.addRoundInfo(player,score,{'closeType':closeType})   
コード例 #2
0
ファイル: carcassonneengine.py プロジェクト: trawl/gamelog
 def runStubRoundPlayer(self, player, winner=None):
     score = readInput("{} score: ".format(player), int,
                       lambda x: x > 0, "Sorry, invalid score number.")
     errmsg = "Sorry, invalid kind [{}]".format(
         ",".join(self.match.getEntryKinds()))
     kind = readInput("Kind: ", str,
                      lambda x: x in self.match.getEntryKinds(),
                      errmsg)
     self.addEntry(player, score, {'kind': kind})
コード例 #3
0
 def runStubRoundPlayer(self,player,winner):
     score = 0
     cleared = 1
     if self.getPhasesInOrderFlag():
         try: a_phase = self.getCompletedPhasesFromPlayer(player)[-1] + 1
         except IndexError: a_phase = 1
     else:
         a_phase = readInput("{} aimed phase number: ".format(player),int,lambda x: x > 0 and self.hasPhaseRemaining(player,x),"Sorry, phase not valid or already completed.")
     if not winner == player:
         score = readInput("{} round score: ".format(player),int,lambda x: x>0,"Sorry, invalid score number.")
         if (score>=50):
             cleared = readInput("Did {} complete phase {}?[1/0]: ".format(player,a_phase),int,lambda x: x in [0,1])
     self.addRoundInfo(player,score, {'aimedPhase':a_phase, 'isCompleted':cleared})
コード例 #4
0
 def extraStubConfig(self):
     pio = readInput("Follow phases in order? [1/0]: ",int,lambda x: x in (0,1))
     self.setPhasesInOrderFlag(bool(pio))
コード例 #5
0
    def extraStubConfig(self):
        pio = readInput("Follow phases in order? [1/0]: ",int,lambda x: x in (0,1))
        self.setPhasesInOrderFlag(bool(pio))
        
    def getPhasesInOrderFlag(self): return self.match.getPhasesInOrderFlag()
     
    def setPhasesInOrderFlag(self,flag): self.match.setPhasesInOrderFlag(flag)
        

class Phase10MasterEngine(Phase10Engine):
    def __init__(self):
        super(Phase10MasterEngine,self).__init__()
        self.game = "Phase10Master"

if __name__ == "__main__":
    game = readInput('Game to play (Phase10/Phase10Master): ',str,lambda x: x in ['Phase10','Phase10Master'])
    if game == 'Phase10': pe = Phase10Engine()
    else: pe = Phase10MasterEngine()
    pe.gameStub()        
    
    
class Phase10StatsEngine(StatsEngine):
    _worst_phases="""
        SELECT game, nick, min(pc) AS min_phases from (
            SELECT m.Game_name as game,m.idMatch AS match ,rs.nick AS nick ,count(value) AS pc
            FROM RoundStatistics AS rs,Match AS m 
            WHERE rs.idMatch = m.idMatch
                AND key = "PhaseCompleted"
                AND value <> 0
                AND state = 1
            GROUP BY game, m.idMatch, rs.nick
コード例 #6
0
ファイル: pochaengine.py プロジェクト: trawl/gamelog
 def runRoundPlayer(self, player, winner):
     score = readInput("{} round score: ".format(player),
                       int, lambda x: True, "Sorry, invalid score number.")
     self.addRoundInfo(player, score)
コード例 #7
0
 def extraStubConfig(self):
     top = readInput("Top score: ",int,lambda x: x > 0)
     self.setTop(top)
コード例 #8
0
        for idMatch,match in self.candidates.items():
            cur = db.execute("SELECT nick FROM MatchPlayer WHERE idMatch={}".format(idMatch))
            for row in cur:
                match['players'].append(str(row['nick']))

    def getCandidates(self): return self.candidates
    
    def resume(self,idMatch):
        engine = GameEngineFactory.createMatch(self.game)
        if engine and engine.resume(idMatch): return engine
        return None
        
        
if __name__ == "__main__":
    if not db.isConnected(): db.connectDB("../db/gamelog.db")
    game = readInput('Game to play (Phase10/Phase10Master/Remigio/Ratuki/Carcassone): ',str,lambda x: x in ['Phase10','Phase10Master','Remigio','Ratuki','Carcassone'])
    re = ResumeEngine(game)
    candidates = re.getCandidates()
    if not len(candidates):
        print("No {} matches to restore found".format(game))
        exit()
    else:
        print("Matches to restore:")
        for idMatch,match in candidates.items():
            print("{}) {} player match started at {}. Time played: {}. Players:{}".format(idMatch,len(match['players']),match['started'],match['elapsed'],match['players']))
        print("")
        idMatch = readInput('idMatch to resume: ',int,lambda x: x in candidates.keys())
        print("Restoring match #{}".format(idMatch))
        engine = re.resume(idMatch)
        if not engine:
            print("Could not restore match #{}".format(idMatch))
コード例 #9
0
ファイル: resumeengine.py プロジェクト: trawl/gamelog
    def getCandidates(self): return self.candidates

    def resume(self, idMatch):
        engine = GameEngineFactory.createMatch(self.game)
        if engine and engine.resume(idMatch):
            return engine
        return None


if __name__ == "__main__":
    if not db.isConnected():
        db.connectDB("../db/gamelog.db")
    pmt = 'Game to play (Phase10/Phase10Master/Remigio/Ratuki/Carcassone): '
    game = readInput(pmt, str, lambda x: x in ['Phase10',
                                               'Phase10Master',
                                               'Remigio',
                                               'Ratuki',
                                               'Carcassone'])
    re = ResumeEngine(game)
    candidates = re.getCandidates()
    if not len(candidates):
        print("No {} matches to restore found".format(game))
        exit()
    else:
        print("Matches to restore:")
        for idMatch, match in candidates.items():
            msg = ("{}) {} player match started at {}. "
                   "Time played: {}. Players:{}")
            print(msg.format(idMatch, len(match['players']), match['started'],
                             match['elapsed'], match['players']))
        print("")