Example #1
0
def playMousePressed(event, data):
    if assist.assistModePressed(event,
                                data) != None and data.assistMode == True:
        data.turnOrder[data.turnInd].recTiles = logic.discAI(data)
        assist.sortTiles(data, data.turnOrder[data.turnInd])
        assist.sortTilesMeld(data, data.turnOrder[data.turnInd])
        return  # don't go to next turn, etc. if you click on the assist mode check
    # skip right to nextTurn(data) if you were waiting to continue turn
    if data.paused == False:
        cpuTurn = type(
            data.turnOrder[data.turnInd]) in data.cpus  # if it's a cpu's turn
        if cpuTurn:
            if data.hardAI == False:
                # AI: have cpu choose a tile among non-melded tiles
                bestTiles = logic.discAIEasy(data)
                # bestTiles should only have tiles not already in a meld left
            elif data.hardAI == True:
                # AI: have cpu choose a tile to discard among equally high heuristic value hand outcomes
                bestTiles = logic.discAI(data)
            chosenTileName = random.choice(bestTiles)
            chosenTile = None
            for tile in data.turnOrder[data.turnInd].tiles:
                if chosenTileName == tile[2][1]:
                    chosenTile = tile
            event.x = chosenTile[0]
            event.y = chosenTile[1]
        # highlights tile if pressed
        graphicsFunc.tilePressed(event, data)
        if cpuTurn:
            # make event.x and event.y "press" the discard button
            event.x = data.width / 2 - 200
            event.y = data.height / 2 + 200
        # can't discard if you have no tile highlighted
        if data.turnOrder[data.turnInd].highlighted == None:
            return
        # discards highlighted tile, returns None unless a human player discards
        if graphicsFunc.discardPressed(event, data) != None:
            if data.mode == "pause":  # don't change turn and add the tile yet if paused
                return
            graphicsFunc.nextTurn(data)  # change turn and add tile
            data.paused = False
            if data.assistMode == True:
                data.turnOrder[data.turnInd].recTiles = logic.discAI(data)
            if len(data.drawPile) == 0:
                data.mode = "drawn"
                print("Game over no one wins.")  # temp
    else:  # after you've come back from pausing
        graphicsFunc.nextTurn(data)  # change turn and add tile
        data.paused = False
        if data.assistMode == True:
            data.turnOrder[data.turnInd].recTiles = logic.discAI(data)
        if len(data.drawPile) == 0:
            data.mode = "drawn"
            print("Game over, no one wins.")  # temp
Example #2
0
	def discardTileAfterAni(self, data, handOrder, removed):
		self.discarded.append(removed)
		data.discPile.append(removed)
		self.tileNames.remove(removed[2][1])
		# update winning tiles everytime a tile is discarded
		self.winningTiles = logic.winningTiles(data.imageNames, self)
		meldsAndTiles = self.melds + self.tiles
		meldsAndTilesNames = []
		for tile in meldsAndTiles:
			meldsAndTilesNames.append(tile[2][1])
		# check if anyone can win with the tile
		for hand in handOrder:
			if removed[2][1] in hand.winningTiles:
				if type(removed) == int:
					print("LALALALA")
					print()
					print()
					print("ALALA")
				hand.tiles.append(removed)
				hand.tileNames.append(removed[2][1])
				print("Won from someone else's tile!")
				print("Loser: " + self.name)
				data.loser = " " + self.name + " lost."
				assist.sortTiles(data, self)
				data.winner = hand.name
				data.winningHand = hand.melds + hand.tiles
				winningHandNames = []
				for tile in data.winningHand:
					winningHandNames.append(tile[2][1])
				data.handSco = logic.handScore(data, winningHandNames)
				print("Hand Score: " + str(data.handSco[0]))
				print(winningHandNames)
				data.mode = "win"
				return
		# check if anyone can pong or chow the tile
		for hand in handOrder:
			if hand.canPong(data, removed):
				data.pongOptHand = hand
				data.pongOptTile = removed
				data.mode = "pong"
		# chow only works for next person
		hand = handOrder[0]
		if hand.canChow(data, removed):
			data.chowOptHand = hand
			data.chowOptTile = removed
			data.mode = "chow"
Example #3
0
	def addTile(self, data):
		randInd = random.randint(0, len(data.drawPile) - 1)
		drawnTile = data.drawPile.pop(randInd)
		# draw another tile for flowers and seasons
		if drawnTile[1][0] == "s" or drawnTile[1][0] == "f":
			self.melds.append([None, None, drawnTile, False])
			self.addTile(data)
			return
		# add new tile at corresponding position
		self.tiles.append([data.widthTop, 1.2 * data.height / 12, drawnTile, False])
		self.tileNames.append(drawnTile[1])
		self.lastDrawnTileName = drawnTile[1]
		if data.assistMode == True:
			if data.meldsFirst == True:
				assist.sortTilesMeld(data, self)
			else:
				# sort normally
				assist.sortTiles(data, self)