def __init__(self, probA, probB):
     self.playerA = Player(probA)
     self.playerB = Player(probB)
     self.server = self.playerA
     self.setsA = 0
     self.setsB = 0
     self.winsA = 0
     self.winsB = 0
class TennisMatch:
    def __init__(self, probA, probB):
        self.playerA = Player(probA)
        self.playerB = Player(probB)
        self.server = self.playerA
        self.acceptor = self.playerB

    def play(self):
        if self.server.scorePoint():
            if self.server.grabScore()== 40 and self.acceptor.grabScore() == 40:
                if self.server.hasAdvantage():
                    self.server.gameVictory()
                    if self.server.games >= 6 and self.server.games - self.acceptor.games >= 2:
                        self.server.setVictory()
                        self.acceptor.resetScore()
                        self.server.changeServer()
                elif self.acceptor.hasAdvantage():
                    self.acceptor.noAdvantage()
                else:
                    self.server.advantage()
                    

            elif self.server.grabScore() == 40 and self.acceptor.grabScore() < 40:
                self.server.gameVictory()
                if self.server.games >= 6 and self.server.games - self.acceptor.games >= 2:
                    self.server.setVictory()
                self.acceptor.resetScore()
                self.server.resetScore()
                self.server.changeServer()
            else:
                self.server.incScore()

        else:
            self.acceptor.incScore()
            if self.acceptor.grabScore() == 40 and self.server.grabScore() < 40:
                self.acceptor.gameVictory()
                if self.acceptor.games >= 6 and self.acceptor.games - self.server.games >= 2:
                    self.acceptor.setVictory()
                self.server.resetScore()
                self.acceptor.resetScore()
                self.server.changeServer()
            

    def grabScores(self):
        return self.playerA.grabScore(), self.playerB.grabScore()

    def isOver(self):
        if self.playerA.getSets() == 3 or self.playerB.getSets() == 3:
            return True
            
    
    def changeServer(self):
        if self.server == self.playerA:
            self.server = self.playerB
            self.acceptor = self.playerA
        else:
            self.server = self.playerA
            self.acceptor = self.playerB
class TGame:
    def __init__(self, probA, probB):
        self.playerA = Player(probA)
        self.playerB = Player(probB)
        self.server = self.playerA
        self.setsA = 0
        self.setsB = 0
        self.winsA = 0
        self.winsB = 0

    def gamePlay(self):
        while not self.gameIsOver():
            if self.server.winsServe():
                self.server.incScore()
#instead of switching servers, the other player gets the point
            else:
                self.changeServer()
                self.server.incScore()
                self.changeServer()

    def changeServer(self):
        if self.server == self.playerA:
            self.server = self.playerB
        else:
            self.server = self.playerA
            
    def getScores(self):
        return self.playerA.getScore(), self.playerB.getScore()
   
    def gameIsOver(self):
        #changed for individual tennis games within a set
        return self.playerA.getScore() >40 or self.playerB.getScore() >40 \
            or (self.playerA.getScore() == 40 and self.playerB.getScore() >60) \
            or (self.playerB.getScore() >60 and self.playerA.getScore() == 40)

    def gameToSet(self):
        #modified from simstats update
        a, b  = self.playerA.getScore(), self.playerB.getScore()
        if a > b + 2:
            self.setsA = self.setsA + 1
            if a==6 and b == 5:
                pass
                #a would need one more set and b would need two
        else:
            self.setsB = self.setsB + 1
            if a ==5 and b == 6:
                pass
                #b would need one more set to win, a would need two
                
    def matchOver(self):
        return self.setsA == 3 or self.sets == 3
    
    def setToWin(self):
        while not matchOver():
            if self.setsA > self.setsB:
                self.winsA = self.winsA + 1
            else:
                self.winsB = self.winsB + 1
Exemple #4
0
    def __init__(self, probA, probB):

        self.playerA = Player(probA)

        self.playerB = Player(probB)

        self.server = self.playerA

        self.aWon = 0

        self.bWon = 0
class Game:
    def __init__(self, probA, probB):
        self.playerA = Player(probA)
        self.playerB = Player(probB)
        self.server = self.playerA
        self.receiver = self.playerB

    def changeServer(self):
        if self.server == self.playerA:
            self.server = self.playerB
            self.receiver = self.playerA
        else:
            self.server = self.playerA
            self.receiver = self.playerB

    def getScores(self):
        return self.playerA.getScore(), self.playerB.getScore()

    def play(self):
        if self.server.winsPoint():
            if self.server.getScore() == 40 and self.receiver.getScore() == 40:
                if self.server.checkadvantage():
                    self.server.winGame() or self.receiver.winGame()
                    if self.server.game >= 6 and self.server.game - self.receiever.game >= 2:
                        self.server.winSet()
                        self.server.resetScore()
                        self.receiver.resetScore()
                        self.changeServer()
                    elif self.receiver.checkadvantage():
                        self.receiver.unsetadvantage()
                    else:
                        self.server.advantage()
            elif self.server.getScore(
            ) == 40 and self.receiver.getScore() < 40:
                self.server.winGame()
                if self.server.game >= 6 and self.server.game - self.receiver.game >= 2:
                    self.server.winSet()
                    self.server.resetScore()
                    self.receiver.resetScore()
                    self.changeServer()
            else:
                self.server.incScore()
        else:
            self.receiver.incScore()
            if self.receiver.getScore() == 40 and self.server.getScore() < 40:
                self.receiver.winGame()
                if self.receiver.game >= 6 and self.receiver.game - self.server.game >= 2:
                    self.receiver.winSet()
                    self.server.resetScore()
                    self.receiver.resetScore()
                    self.changeServer()
def main():

    pl1 = Player(.5)
    pl2 = Player(.6)
    pl1.setStr("Player 1")
    pl2.setStr("Player 2")
    match = Match(pl1, pl2)

    for i in range(50):
        print(match.runMatch())
Exemple #7
0
class RBallGame:
    def __init__(self, probA, probB):
        self.playerA = Player(probA)
        self.playerB = Player(probB)
        self.server = self.playerA
        self.aWon = 0
        self.bWon = 0

    def play(self):
        winner = 0
        while winner < 3:
            self.game()
            winner = winner + 1
            self.aWon, self.bWon = 0, 0

    def game(self):
        while not self.isOver():
            if self.server.winsServe():
                self.server.incScore()
            else:
                self.changeServer()
        if self.playerA.getScore() > self.playerB.getScore():
            self.aWon = self.aWon + 1
        else:
            self.bWon = self.bWon + 1

    def getScores(self):
        return self.playerA.getScore(), self.playerB.getScore()

    def isOver(self):
        return (self.playerA.getScore() >=40 or self.playerB.getScore() >=40) \
            and abs(self.playerA.getScore()-self.playerB.getScore())>=30

    def changeServer(self):
        if self.server == self.playerA:
            self.server = self.playerB
        else:
            self.server = self.playerA
 def __init__(self, probA, probB):
     self.playerA = Player(probA)
     self.playerB = Player(probB)
     self.server = self.playerA
     self.receiver = self.playerB
 def __init__(self, probA, probB):
     self.playerA = Player(probA)
     self.playerB = Player(probB)
     self.server = self.playerA
     self.acceptor = self.playerB
class TennisMatch:
    def __init__(self, probA, probB):
        self.playerA = Player(probA)
        self.playerB = Player(probB)
        self.server = self.playerA

    def play(self):
        while not self.isOver():
            while not self.setOver():
                while not self.gameOver():
                    if self.server.winsServe():
                        self.server.incGScore()
                    else:
                        self.changeServer()
                        self.server.incGScore()
                        self.changeServer()
                self.server.resetGame()
                self.changeServer()
                self.server.resetGame()
            self.detwinner()

    def playDuce(self):
        pA, pB = 0, 0
        while 1 == 1:
            if self.server.winsServe():
                pA += 1
            else:
                pB += 1
            if pA - pB == 2:
                self.server.incSetScore()
                break
            if pB - pA == 2:
                self.changeServer()
                self.server.incSetScore()
                self.changeServer()
                break
        return True

    def tieBreaker(self):
        while not self.gameOver():
            if self.server.winsServe():
                self.server.incGScore()
            else:
                self.changeServer()
                self.server.incGScore()
                self.changeServer()
        self.server.resetGame()
        self.changeServer()
        self.server.resetGame()

    def setadd(self):
        if self.playerA.getGameScore() == 1:
            self.playerA.incSetScore()
        else:
            self.playerB.incSetScore()
        return True

    def getScores(self):
        return self.playerA.getScore(), self.playerB.getScore()

    def detwinner(self):
        if self.playerA.getSetScore() == 6 or self.playerA.getSetScore() == 7:
            self.playerA.incSetWon()
        elif self.playerB.getSetScore() == 6 or self.playerB.getSetScore(
        ) == 7:
            self.playerB.incSetWon()

    def gameOver(self):
        if self.playerA.getGameScore() == 40 and self.playerB.getGameScore(
        ) == 40:
            return self.playDuce()
        elif self.playerA.getGameScore() == 1 or self.playerB.getGameScore(
        ) == 1:
            return self.setadd()
        else:
            return False

    def setOver(self):
        if self.playerA.getSetScore() == 6 and self.playerB.getSetScore() == 6:
            self.tieBreaker()
        elif (self.playerA.getSetScore() == 6 and self.playerB.getSetScore() != 5) \
             or (self.playerB.getSetScore() == 6 and self.playerA.getSetScore() != 5):
            return True
        elif self.playerA.getSetScore() == 7 or self.playerB.getSetScore(
        ) == 7:
            return True
        else:
            return False

    def isOver(self):
        if self.playerA.getSetsWon() == 3:
            self.playerA.incScore()
            return True
        elif self.playerB.getSetsWon() == 3:
            self.playerB.incScore()
            return True
        else:
            return False

    def changeServer(self):
        if self.server == self.playerA:
            self.server = self.playerB
        else:
            self.server = self.playerA
def main():
    m = Match(Player(.6), Player(.5))
    print(m.runMatch())