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
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)