def deliverCards( self, roll ): for pos in self.Board.positions: for hex in pos.hexes: if hex.number == roll: if hex.hasRobber == False: if pos.playerId is not None: printv( str(pos.playerId) + ' is getting ' + hex.resource ) self.players[ pos.playerId ].addCard( hex.resource )
def random(self): curCardLen = len(self.players[self.playerId].cards) newCardLen = curCardLen if curCardLen > 7: newCardLen = math.ceil(newCardLen / 2) printv(' ' + str(self.playerId) + ' is discarding ' + str(int(curCardLen - newCardLen)) + ' cards') while curCardLen > newCardLen: ri = randint(0, curCardLen - 1) self.players[self.playerId].cards.pop(ri) curCardLen = len(self.players[self.playerId].cards)
def begin( self ): winner = None whoseTurn = 0; while winner is None and self.fakeTurnLimitCount <= self.fakeTurnLimit: winner = self.turn( whoseTurn ) whoseTurn = ( whoseTurn + 1 ) % len(self.players) self.fakeTurnLimitCount += 1 printv( '' ) printv( '=======Final========' ) self.Board.drawIt() self.allShowCards()
def __init__(self, Board, numOfPlayers): self.Board = Board # Make players for i in xrange(0, numOfPlayers): self.__addPlayer(i) # If we have 3 or 4, begin if len(self.players) in (3, 4): self.begin() else: printv('Game Not Started: You need either 3 or 4 players to play.')
def turn( self, i ): roll = self.rollDice() printv( str(i) + ' rolled a ' + str(roll) ) if roll is 7: self.allPlayersDo( 'discard' ) self.players[i].do( 'rob' ) else: self.deliverCards( roll ) #self.allShowCards() self.players[i].do( 'trade' ) self.players[i].do( 'build' ) if self.players[i].points >= 10: return self.players[i] else: return None
def best(self): printv(' best')
def none(self): printv(' none')
def do(self, do, witha=None): printv(str(self.playerId) + ' ' + do) if do == 'collect': self.collect(witha) else: self.Strategy.play(do)
def drawIt(self): # I'm just going to contrust it line by line as it gets unessecarily complicated using loops h = [] p = [] for hex in self.hexes: h.append(hex.asString()) for pos in self.positions: p.append(pos.asString()) # Note: intermediate whitespace is ignored in strong modulo operation # and is their the maintain the same lengths printv("") printv( " % s % s % s " % (p[1], p[3], p[5])) printv( " % s % s % s % s " % (p[0], p[2], p[4], p[6])) printv( " ") printv( " % s % s % s " % (h[0], h[1], h[2])) printv( " ") printv( " % s % s % s % s " % (p[8], p[10], p[12], p[14])) printv( " % s % s % s % s % s " % (p[7], p[9], p[11], p[13], p[15])) printv( " ") printv( " % s % s % s % s " % (h[3], h[4], h[5], h[6])) printv( " ") printv( " % s % s % s % s % s " % (p[17], p[19], p[21], p[23], p[25])) printv( "% s % s % s % s % s % s" % (p[16], p[18], p[20], p[22], p[24], p[26])) printv( " ") printv( " % s % s % s % s % s " % (h[7], h[8], h[9], h[10], h[11])) printv( " ") printv( "% s % s % s % s % s % s" % (p[27], p[29], p[31], p[33], p[35], p[37])) printv( " % s % s % s % s % s " % (p[28], p[30], p[32], p[34], p[36])) printv( " ") printv( " % s % s % s % s " % (h[12], h[13], h[14], h[15])) printv( " ") printv( " % s % s % s % s % s " % (p[38], p[40], p[42], p[44], p[46])) printv( " % s % s % s % s " % (p[39], p[41], p[43], p[45])) printv( " ") printv( " % s % s % s " % (h[16], h[17], h[18])) printv( " ") printv( " % s % s % s % s " % (p[47], p[49], p[51], p[53])) printv( " % s % s % s " % (p[48], p[50], p[52])) printv("")
def mostWithoutMe(self): for h in self.Board.hexes: for p in h.surroundPos: printv('h')
def random(self): randHexI = randint(0, len(self.Board.hexes) - 1) printv(' Moving robber from hex ' + str(self.Board.robberHexI) + ' to ' + str(randHexI)) self.Board.moveRobberTo(randHexI)