Beispiel #1
0
 def new_over(self):
     self.bowling, self.resting = self.resting, self.bowling
     self.fteam.field[0], self.fteam.field[1] = self.fteam.field[
         1], self.fteam.field[0]
     bowl = yield from maybe_gen(
         self.fteam.captain.maybe_choose_bowler(self))
     if bowl != self.bowling:
         bi = self.fteam.field.index(bowl)
         self.fteam.field[0], self.fteam.field[bi] = self.fteam.field[
             bi], self.fteam.field[0]
         self.bowling = bowl
     if self.bowling.keeper:  # Local captains only
         keep = yield from maybe_gen(
             self.fteam.captain.choose_keeper(
                 [p for p in self.fteam if p != self.bowling]))
         self.choose_keeper(keep)
     self.swap_strike()
     self.overs.append(Over(self))
     if self.chasing is None:
         chase = ""
     else:
         chase = " - %d required" % (self.chasing + 1 - self.total)
     print("Over %d; %d/%d.  %s to %s (%s off strike)%s" %
           (len(self.overs), self.total, len(self.fow), self.bowling.name,
            self.striker.name, self.non_striker.name, chase))
     if not self.bowling.first_over:
         self.bowling.first_over = len(self.overs)
Beispiel #2
0
 def roll(cls, bowl, bowler, batsman, field):
     print("Howzat?")
     # Not Out, bowled, caught, stumped, lbw, run out
     if bowl == 1:  # Not Out
         return
     elif bowl == 2:
         return cls("bowled")
     elif bowl == 3:
         # batsman: 2d6 to decide where he hits it.  12 goes to 1
         fielder = field[((yield from maybe_gen(
             batsman.roll_2d6(prompt="Roll 2d6 to pick fielder"))) - 1) %
                         11]
         print("In the air to %s..." % (fielder.name, ))
         # fielder: roll d6 to catch, drop on 1 or 2
         if (yield from maybe_gen(
                 fielder.roll_d6(prompt="Roll to attempt the catch"))) > 2:
             return cls("caught", fielder, fielder == bowler)
         else:
             print("Dropped it!")
             return
     elif bowl == 4:
         # Wicketkeeper is a roll of 7 on the 2d6
         return cls("stumped", field[6])
     elif bowl == 5:
         return cls("lbw")
     elif bowl == 6:
         return cls("run out")
     else:
         raise Exception("This d6 has a %d?" % (bowl, ))
Beispiel #3
0
def toss(TA, TB):
    # captains
    CA = TA.captain
    CB = TB.captain
    # True is Tails
    call = yield from maybe_gen(CA.call_toss())
    print("%s called %s" % (CA.name, "tails" if call else "heads"))
    coin = yield from maybe_gen(CB.flip_coin())
    print("The coin landed %s up" % ("tails" if coin else "heads"))
    if call == coin:
        if (yield from maybe_gen(CA.choose_to_bat())):
            print("%s won the toss and elected to bat" % (TA.name, ))
            return TA, TB
        print("%s won the toss and elected to field" % (TA.name, ))
        return TB, TA
        return
    if (yield from maybe_gen(CB.choose_to_bat())):
        print("%s won the toss and elected to bat" % (TB.name, ))
        return TB, TA
    print("%s won the toss and elected to field" % (TB.name, ))
    return TA, TB
Beispiel #4
0
 def roll(cls, bowler, batsman, field):
     bowl = yield from maybe_gen(
         bowler.roll_d6(prompt="Roll to bowl to " + batsman.name))
     extra = None
     if bowl == 1:
         # possible Extra; roll again
         extra = yield from maybe_gen(
             bowler.roll_d6(prompt="Roll for extras"))
     if extra == EXTRA_W:  # Batsman does not roll
         return cls(bowler, batsman, 0, extra=extra)
     else:
         bat = yield from maybe_gen(
             batsman.roll_d6(prompt="Roll to play the ball"))
         if bat == 5:  # Wicket
             return cls(
                 bowler,
                 batsman,
                 0, (yield from Wicket.roll(bowl, bowler, batsman, field)),
                 extra=extra)
         elif bat == 3:  # No run
             return cls(bowler, batsman, 0, extra=extra)
         else:
             return cls(bowler, batsman, bat, extra=extra)
Beispiel #5
0
 def choose_batsman(self):
     bat = yield from maybe_gen(
         self.bteam.captain.choose_batsman(self.to_bat))
     self.to_bat.remove(bat)
     self.border.append(bat)
     return bat