python Ticket to Ride Game

Pandas入门教程(二十二):股票数据分析实战——yfinance 获取数据、技术指标与收益率分析 把 Pandas 用在真实场景,才能体会它的价值。本文以茅台股票为例,用 yfinance 获取历史行情,完成缺失值处理与列筛选,绘制收盘价曲线,计算 SMA 移动平均线与 RSI 相对强弱指数,并通过日收益率、累计收益率和波动率完成完整的量化分析流程。 阅读详情

在这里插入图片描述
在这里插入图片描述
TTRPlayer.py

import collections

from TTRBoard import Board


class Player(object):
    
    def __init__(self, 
                 startingHand, 
                 startingTickets, 
                 playerBoard, 
                 playerPosition, 
                 numTrains
                 ):
        """orderNumber: int
        startingHand: list
        startingTickets: list
        playerBoard: PlayerBoard object from the TTRBoard module
        playerPosition: int
        """
        self.name           = '' #ask for them to enter it on first turn
        self.isComputerPlayer = False
        #implimented as a collection to avoid O(n) hand.remove(x)
        self.hand           = collections.Counter(startingHand)
        
        self.tickets        = {x:False for x in startingTickets}
        self.numTrains      = numTrains
        self.points         = 0
        self.useDijkstra = False
        self.playerPosition = playerPosition
        self.board = Board()
        self.wayAvailable = []
        self.results = []
        #custom board to represent
        self.playerBoard    = playerBoard
                    
    def removeCardsFromHand(self, color, numColor):
        """removes one ore more cards from hand
        assumes all cards are in hand, error if not
        cards: list
        """
        assert self.hand[color] >= numColor
        self.hand[color] -= numColor
        
    #add card to hand
    def addCardToHand(self, card):
        """adds a single card to hand
        assumes card is a valid choice
        card: String
        """
        if card != None:
            self.hand[card] += 1
    
    #add ticket to hand
    def addTicket(self, ticket):
        """adds a single ticket to tickets
        ticket: tuple(city1, city2, value)
        """
        self.tickets[ticket] = False
    
    def completeTicket(self, ticket):
        """updates the value in the tickets dict to True for key: ticket
        ticket: tuple(city1, city2, value)
        """
        assert ticket in self.tickets
        self.tickets[ticket] = True
    
    def getHand(self):
        return self.hand
    
    def addPoints(self, numPoints):
        self.points += numPoints
    
    def subtractPoints(self, numPoints):
        self.points -= numPoints
        
    def getPoints(self):
        return self.points
        
    def getTickets(self):
        return self.tickets
    
    def getNumTrains(self):
        return self.numTrains
    
    def playNumTrains(self, numTrains):
        assert numTrains <= self.numTrains
        self.numTrains -= numTrains
        
    def setPlayerName(self, name):
        """sets playerName to name
        name: string
        """
        self.name = name
    
    def getName(self):
        return self.name

    def getConnectCityList(self):
        cityList = []
        for ticket in self.getTickets():
            if self.useDijkstra:
                shortest_path = self.board.dijkstraShortestPath(ticket[0], ticket[1])
            else:
                shortest_path = self.board.findAnyPath(ticket[0], ticket[1])
            cityList.append(shortest_path)
        return cityList

    def hasTrainsConnectTicket(self, ways):
        for way in ways:
            for citys in self.getConnectCityList():
                if way[0] in citys and way[1] in citys:
                    self.wayAvailable = [way[0], way[1]]
                    return True
        return False

    def getNeedColors(self):
        colors = []
        for cities in self.getConnectCityList():
            self.results = [[cities[i], cities[i + 1]] for i in range(len(cities) - 1)]
            for result in self.results:

                colors += self.board.getEdgeColors(result[0], result[1])

        return colors


TTRGameSim.py

# this version no longer takes input from user.
# Designed for computer OR human player (mainly comp v comp sim)
import random

# All values and methods associated with the Original Ticket to Ride board game
import TTRBoard
import TTRCards
import TTRPlayer
import collections
import pprint


class Game(object):
    def __init__(self, numPlayers):

        self.sizeDrawPile = 5
        self.numTicketsDealt = 3
        self.sizeStartingHand = 4
        self.maxWilds = 3

        self.endingTrainCount = 3  # ending condition to trigger final round

        self.pointsForLongestRoute = 10
        self.startingNumOfTrains = 10  # 45
        self.deck = TTRCards.Cards(self.sizeDrawPile, self.maxWilds)

        self.board = TTRBoard.Board()
        self.numPlayers = numPlayers
        self.players = []

        self.posToMove = 0

        # point values for tracks of different lengths
        self.routeValues = {1: 1, 2: 2, 3: 4, 4: 7, 5: 10, 6: 15}

        for position in range(numPlayers):
            startingHand = self.deck.dealCards(self.sizeStartingHand)
            startingTickets = []  # self.deck.dealTickets(self.numTicketsDealt)
            # this is now done in initialize method below
            # occurs before first player's first move
            playerBoard = TTRBoard.PlayerBoard()

            player = TTRPlayer.Player(startingHand,
                                      startingTickets,
                                      playerBoard,
                                      position,
                                      self.startingNumOfTrains
                                      )
            self.players.append(player)

    def printSepLine(self, toPrint):
        print(toPrint)

    def advanceOnePlayer(self):
        """Updates self.posToMove"""
        self.posToMove += 1
        self.posToMove %= self.numPlayers

    def getCurrentPlayer(self):
        return self.players[self.posToMove]

    def doesPlayerHaveCardsForEdge(self, player, city1, city2):
        if player.playerBoard.hasEdge(city1, city2):
            return False
        routeDist = self.board.getEdgeWeight(city1, city2)
        routeColors = self.board.getEdgeColors(city1, city2)
        for col in routeColors:
            if col == 'grey':
                if max([x for x in player.hand.values() if x != 'wild']) \
                        + player.hand['wild'] >= routeDist:
                    return True
            else:
                routeDist = self.board.getEdgeWeight(city1, city2)
                if player.hand[col] + player.hand['wild'] >= routeDist:
                    return True
        return False

    def checkEndingCondition(self, player):
        return player.getNumTrains() < self.endingTrainCount

    def initialize(self):
        """Before game turns starts, enter names and pick destination tickets
        """

        for player in self.players:
            # pick desination tickets
            if len(player.getName()) == 0:
                player.setPlayerName(input("Enter your name: "))

            if input("Human(0) or Computer(1) ? ") == '1':
                player.isComputerPlayer = True
                if input("Use Dijkstra(1) or not(0)?") == '1':
                    player.useDijkstra = True

            self.pickTickets(player, 2)

            self.advanceOnePlayer()

    def scorePlayerTickets(self, player):
        """returns None.  
        Scores player's destination tickets and 
        adds/subtracts from player's points
        """
        for ticket in player.tickets:
            city1 = ticket[0]
            city2 = ticket[1]
            value = ticket[2]
            posNodes = player.playerBoard.getNodes()
            if city1 not in posNodes or city2 not in posNodes:
                player.subtractPoints(value)
                continue
            if player.playerBoard.hasPath(city1, city2):
                player.addPoints(value)
                player.completeTicket(ticket)

    def scoreLongestPath(self):
        """determines which player has the longest route and 
        adjusts their score accordingly
        players: list of players
        adds self.pointsForLongestRoute to player with longest route
        """

        scores = {x: (0, ()) for x in self.players}
        longestPath = 0
        for player in scores:

            for city in player.playerBoard.getCities():
                pathInfo = player.playerBoard.longestPath(city)
                if pathInfo[0] > scores[player][0]:
                    scores[player] = pathInfo

            if scores[player][0] > longestPath:
                longestPath = scores[player][0]

        print(scores)

        for player in scores:
            if scores[player][0] == longestPath:
                player.addPoints(self.pointsForLongestRoute)

        # does not return anthing

    def printAllPlayerData(self):
        """prints out all of the non method attributes values for all players
        """
        for player in self.players:
            print(player.name)
            print("------------------------------")
            for x in player.__dict__:
                print(x, player.__dict__[x])
            print(player.playerBoard.iterEdges())


            print("==============================")

    def playTurn(self, player):
        """player chooses 'cards', 'trains', 'tickets'
        player: player object
        """
        choice = ""
        if player.isComputerPlayer:
            print("Please type: cards, trains or tickets: ")
            ways = [x for x in sorted(self.board.iterEdges()) if self.doesPlayerHaveCardsForEdge(player, x[0], x[1])]
            if player.hasTrainsConnectTicket(ways):
                choice = 'trains'
            else:
                choice = 'cards'
            print(choice)
        else:
            choice = input("Please type: cards, trains or tickets: ")

            count = 0  # a way out of the loop if 5 invalid responses
            while choice not in ['cards', 'trains', 'tickets'] and count < 5:
                choice = input("Invalid repsonse. Please select either cards, "
                               + "trains or tickets: ")
                count += 1

            displayMap = input("Display map? y/n: ")
            if displayMap == 'y':
               pauseTime = input("For how many seconds? (between 1 and 30): ")
               if int(pauseTime) not in range(1, 31):
                   pass
               else:
                   self.board.showBoard(self.board.G, int(pauseTime))
                   #Depricated?

            if count >= 5:
                return "Move complete"

        if choice == 'cards':
            self.pickCards(player)
            return "Move complete"

        elif choice == 'trains':
            self.placeTrains(player)
            return "Move complete"
        else:
            self.pickTickets(player)
            return "Move complete"

    def pickCards(self, player):
        count = 0  # a way out of the loop if 5 invalid responses
        print("Your hand consists of: ")
        self.printSepLine(player.getHand())

        print("Draw pile consists of: ")
        self.printSepLine(self.deck.getDrawPile())
        choice1 = ""
        if player.isComputerPlayer:
            print("Please type a card from the above list or "
                  + "type 'drawPile': ")
            if 'wild' in self.deck.getDrawPile():
                choice1 = 'wild'
            else:
                colors = player.getNeedColors()
                for card in self.deck.getDrawPile():
                    if card in colors:
                        choice1 = card
                        break
                if choice1 == '':
                    choice1 = 'drawPile'

        else:
            choice1 = input("Please type a card from the above list or "
                            + "type 'drawPile': ")
            while choice1 not in self.deck.getDrawPile() + ['drawPile'] \
                    and count < 5:
                choice1 = input("Invalid repsonse. Please type either from "
                                + str(self.deck.getDrawPile())
                                + " or type 'drawPile' "
                                )
                count += 1

        # add card to player's hand
        # remove it from drawPile or cards and
        # add new card to drawPile
        if count >= 5:
            pass
        elif choice1 == 'drawPile':
            chosenCard = self.deck.pickFaceDown()
            print("You selected: " + str(chosenCard))
            player.addCardToHand(chosenCard)
        else:
            player.addCardToHand(self.deck.pickFaceUpCard(choice1))

        # start second card selection
        if choice1 == 'wild':
            print("Your hand now consists of: ")
            self.printSepLine(player.getHand())

            return "Move complete"

        count = 0

        self.printSepLine(self.deck.getDrawPile())

        choice2 = ""
        if player.isComputerPlayer:
            print("Please type a card from the above list or "
                  + "type 'drawPile': ")
            colors = player.getNeedColors()
            for card in self.deck.getDrawPile():
                if card in colors:
                    choice2 = card
                    break
            if choice2 == '':
                choice2 = 'drawPile'

        else:
            choice2 = input("Please type another card from the above list or "
                            + "type 'drawPile': ")
            while choice2 == 'wild' \
                    or (choice2 not in self.deck.getDrawPile() + ['drawPile'] \
                        and count < 5):
                choice2 = input("Invalid repsonse. Please type either from "
                                + str(self.deck.getDrawPile())
                                + " or type 'drawPile' \
                                    NOTE: second choice cannot be 'wild' "
                                )
                count += 1

        # add card to player's hand
        # remove it from drawPile or cards and
        # add new card to drawPile
        if count >= 5:
            return "Move complete"
        elif choice2 == 'drawPile':
            chosenCard = self.deck.pickFaceDown()
            print("You selected: " + str(chosenCard))
            player.addCardToHand(chosenCard)
        else:
            player.addCardToHand(self.deck.pickFaceUpCard(choice2))

        print("Your hand now consists of: ")
        self.printSepLine(player.getHand())
        return "Move complete"

    def placeTrains(self, player):
        count = 0
        print("Available cities:")

        # only print routes that are legal given the players cards
        # sort alphabetically
        self.printSepLine([x for x in sorted(self.board.iterEdges())
                           if self.doesPlayerHaveCardsForEdge(player, x[0], x[1])])

        print("Your hand consists of: ")
        self.printSepLine(player.getHand())
        city1 = ''
        city2 = ''
        if player.isComputerPlayer:
            print("Please type the start city of desired route: ", end='')
            city1 = player.wayAvailable[0]
            print(city1)
            print("Please type the destination city to go to from "
                          + str(city1)
                          + " : ", end='')
            city2 = player.wayAvailable[1]
            print(city2)
        else:
            city1 = input("Please type the start city of desired route: ")

            while city1 not in self.board.getCities() and count < 5:
                city1 = input("Invalid response.  "
                              + "Please select from the above city list: "
                              )
                count += 1

            if count >= 5:
                return "Move complete"

            if len([x for x in self.board.G.neighbors(city1)
                    if self.board.hasEdge(city1, x)]) == 0:
                print("You have a selected a city with no legal destination")
                return "Move complete"

            # start city2
            count = 0

            print("Available destination cities: " \
                  + str([x for x in self.board.G.neighbors(city1)
                         if self.doesPlayerHaveCardsForEdge(player, city1, x)]))

            city2 = input("Please type the destination city to go to from "
                          + str(city1)
                          + " : "
                          )

            while not self.board.hasEdge(city1, city2) and count < 5:
                city2 = input("Invalid response.  "
                              + "Please type one of the following cities "
                              + "(without quotes): \n"
                              + str([x for x in self.board.G.neighbors(city1)
                                     if self.board.hasEdge(city1, x)])
                              + " : "
                              )
                count += 1

            if count >= 5:
                return "Move complete"

        # start exchange cards and place trains
        routeDist = self.board.getEdgeWeight(city1, city2)
        spanColors = self.board.getEdgeColors(city1, city2)

        if len(spanColors) == 0:
            # a little harsh but will updated later to players start over
            print("You have a selected two cities with no legal route")
            return "Move complete"

        print("\n This route is of length: ")
        self.printSepLine(routeDist)
        print("Your hand consists of: ")
        self.printSepLine(player.getHand())

        color = ""
        if len(spanColors) == 1:
            color = spanColors[0]  # use first element, getEdgeColors returns list
            print("This route is: " + str(color))
        else:
            color = ""
            if player.isComputerPlayer:
                num = 0
                for i in spanColors:
                    if player.getHand()[i] > num:
                        num = player.getHand()[i]
                        color = i
                if color == 'wild':
                    color = random.choice(spanColors)


            else:
                color = input("which color track would you like to claim? ("
                              + str(spanColors)
                              + " available): "
                              )
                if color not in spanColors:
                    print("Invalid Color")
                    return "Move complete"

        # check to see if player has appropriate cards to play route
        # (edge weight, color/wild)
        if not self.doesPlayerHaveCardsForEdge(player, city1, city2):
            print("You do not have sufficient cards to play this route")
            return "Move complete"
        if color == 'grey':
            availColor = max(x for x in player.hand.values())
        else:
            availColor = player.hand[color]

        availWild = player.hand['wild']
        if color == 'grey':
            if player.isComputerPlayer:
                print(("Which color would you like to play "
                              + "on this grey route? "
                              + "(pick a color, not 'wild'): "
                              ), end='')
                num = 0
                for i in player.getHand().keys():
                    if player.getHand()[i] > num and i != 'wild':
                        num = player.getHand()[i]
                        color = i
                print(color)
            else:
                color = input("Which color would you like to play "
                              + "on this grey route? "
                              + "(pick a color, not 'wild'): "
                              )

                if color not in self.deck.possibleColors:
                    print("Invalid Color")
                    return "Move complete"

            availColor = player.hand[color]

            if player.isComputerPlayer:
                if availColor > routeDist:
                    numColor = routeDist
                else:
                    numColor = availColor
            else:
                numColor = input("How many " + str(color)
                                 + " cards would you like to play? ("
                                 + str(availColor)
                                 + " available): "
                                 )
        else:
            if player.isComputerPlayer:
                if availColor > routeDist:
                    numColor = routeDist
                else:
                    numColor = availColor
            else:
                numColor = input("How many "
                                 + str(color)
                                 + " cards would you like to play? ("
                                 + str(availColor)
                                 + " available) "
                                 )
        if str(numColor) not in [str(x) for x in range(routeDist + 1)]:
            print("Invalid Entry")
            return "Move complete"
        numColor = int(numColor)  # change raw string to int
        if numColor not in range(0, availColor + 1):
            print("You do not have that many")
            return "Move complete"

        if numColor < routeDist:  # span distance

            if player.isComputerPlayer:
                numWild = routeDist - numColor
            else:
                numWild = input("How many wild cards would you like to play? ("
                                + str(availWild)
                                + " available) "
                                )
                numWild = int(numWild)
                if numWild not in range(0, availWild + 1):
                    print("You do not have that many")
                    return "Move complete"
        else:
            numWild = 0

        # verify that this is a legal move
        if numWild + numColor != routeDist:
            print("Selected cards do not properly span that route")
            return "Move complete"

        # claim route for player (see dedicated method within Game class)
        player.playerBoard.addEdge(city1, city2, routeDist, color)

        # remove route from main board
        self.board.removeEdge(city1, city2, color)

        # calculate points
        player.addPoints(self.routeValues[routeDist])

        # remove cards from player's hand
        player.removeCardsFromHand(color, numColor)
        player.removeCardsFromHand('wild', numWild)

        # add cards to discard pile
        self.deck.addToDiscard([color for x in range(numColor)]
                               + ['wild' for x in range(numWild)]
                               )

        # remove trains from players numTrains
        player.playNumTrains(routeDist)

        print("Number of trains left to play: ")
        self.printSepLine(player.getNumTrains())

        return "Move complete"

    def pickTickets(self, player, minNumToSelect=1):
        count = 0
        tickets = self.deck.dealTickets(self.numTicketsDealt)

        # assign a number to each ticket to make it easier to choose
        tickets = {x[0]: x[1] for x in zip(range(len(tickets)), tickets)}
        print("Please select at least " + str(minNumToSelect) + ": ")

        self.printSepLine(tickets)

        choices = set()
        if player.isComputerPlayer:
            choices.add(tickets[0])
            choices.add(tickets[1])
            choices.add(tickets[2])
        else:
            choice = input("Select a number corresponding to the above tickets,"
                           + " type done when finished: ")

            while (choice != 'done' and count < 7) \
                    or len(choices) < minNumToSelect:
                try:
                    choices.add(tickets[int(choice)])
                    choice = input("Select the number corresponding to the "
                                   + "above tickets, type 'done' when finished: "
                                   )
                except:
                    choice = input("Invalid Choice: Select the number "
                                   + "corresponding to the above tickets, "
                                   + "type 'done' when finished: "
                                   + " (must select at least "
                                   + str(minNumToSelect)
                                   + ") "
                                   )
                    count += 1

        print("You selected: ")
        for ticket in choices:
            player.addTicket(ticket)
            print(ticket)

        # add tickets that weren't chosen to the ticketDiscardPile
        notChosen = set(range(len(tickets))).difference(choices)
        for i in notChosen:
            self.deck.addToTicketDiscard(tickets[i])

        print("All of your tickets: ")
        self.printSepLine(player.getTickets())

        return "Move complete"


def playTTR():
    # before first turn, select 1, 2 or 3 destination tickets

    print("\n Welcome to Ticket to Ride! \n")

    numPlayers = input("How many players will be playing today? "
                       + "1,2,3,4,5 or 6? ")

    count = 0
    while int(numPlayers) not in range(1, 7) and count < 5:
        if numPlayers == 'exit': return "Thanks for playing!"
        numPlayers = input("Please enter either 1,2,3,4,5 or 6: ")
        count += 1
    if count >= 5:
        print("Default player count has been set to 2")
        numPlayers = 2

    game = Game(int(numPlayers))

    game.initialize()

    player = game.players[game.posToMove]

    # main game loop
    while True:
        print("\n_________________NEW PLAYER'S TURN_________________ \n")

        print("It's your turn " + str(player.getName()) + "! ")
        game.playTurn(player)

        # condition to break out of loop
        if game.checkEndingCondition(player):
            game.advanceOnePlayer()
            player = game.getCurrentPlayer()
            break
        game.advanceOnePlayer()
        player = game.getCurrentPlayer()

    print("\n This is the last round!  Everyone has one more turn! \n")

    for i in range(len(game.players)):
        print("\n_________________NEW PLAYER'S TURN_________________ \n")
        print("This is your LAST TURN " + str(player.getName()) + "! ")
        game.playTurn(player)
        game.advanceOnePlayer()
        player = game.getCurrentPlayer()

    for player in game.players:
        game.scorePlayerTickets(player)

    game.scoreLongestPath()

    scores = []
    for player in game.players:
        print(str(player.getName())
              + " had "
              + str(player.getPoints())
              + " points!"
              )
        score = player.getPoints()
        scores.append(score)

    winners = [x.getName() for x in game.players
               if x.getPoints() == max(scores)]

    if len(winners) == 1:
        print("The winner is " + str(winners[0]))
    else:
        print("The winners are " + ' and '.join(winners))

    print("\n =========== Data =========== \n")

    game.printAllPlayerData()

    print("\n =========== fin =========== \n")


if __name__ == "__main__":
    playTTR()

如何处理动态语言(Python / JS)的“隐形”调用链? 本文揭示动态语言(Python/JS)中静态AST解析导致调用链“断链”的核心问题,提出通过运行时追踪补全图谱的解决方案。基于Code-Graph-RAG的cgr trace机制,分别利用pytest插件与V8 Profiler捕获真实调用路径,将动态边合并至静态图谱,并在权重体系中提升动态边优先级。实践表明,该方法可显著提升图谱覆盖率,实现“结构+行为”双视角理解代码,为MCP与Rerank系统提供可靠支持。 阅读详情

相关推荐

快速了解GPU分布通信技术:PCIe、NVLink与NVSwitch

PCIe(Peripheral Component Interconnect Express)是一种高速串行计算机扩展总线标准,广泛用于连接计算机的各种硬件设备。PCIe4.0是目前较为先进的版本,提供了高达64GB/s的带宽。InfiniBand是一种用于高性能计算的高速互连技术,通过交换机在节点之间直接创建一个专用的受保护通道。InfiniBand适配器通过PCIe接口连接到CPU,另一端通过InfiniBand网络端口连接到InfiniBand子网。

全世界的博客 7543

AI全栈实战 | 3.9-01 爬虫入门:requests 加 BeautifulSoup 三分钟跑通,但 90% 的人栽在这 4 个“礼貌“问题上

⚠️:本文内容仅用于。请遵守目标站点的服务条款与相关法律法规,不得对目标服务造成负担,不得采集、传播个人隐私数据。技术是中性的,边界在你手里。爬虫的入门技术(requests 发请求 + BeautifulSoup 解析)三分钟就能学会。真正区分"会用爬虫"和"会做爬虫的人"的,是这篇我们跑通"请求→解析→存储"的最小闭环,然后重点把"合规与礼貌"这根弦给你绷上。

源码获取 | 运行部署 | 定制二开修改,如果回复不及时请耐心等待,请见谅。 406

MediaPipe+Unity动作捕捉实战:如何用普通摄像头驱动3D人物模型(附避坑指南)

本文详细介绍了如何利用MediaPipe和Unity实现低成本动作捕捉,仅需普通摄像头即可驱动3D人物模型。通过MediaPipe的3D坐标预测能力,结合Unity的骨骼映射优化,解决单目摄像头下的三维重建难题,并提供实战避坑指南和性能优化技巧,帮助开发者快速实现专业级的人物模型驱动效果。

weixin_29047545的博客 357

从一段视频到可漫游的 4D 有声场景:思路拆解与最小复现手记

只需一段手机视频,你就能生成可"走进去"的 4D 有声场景:转头时狗叫声方向随之变化,走近时声音更清晰。本文拆解 Video-to-4DAVScene 的核心思路,手把手带你用几十行 Python 搭出最小管线,把视频中的运动物体变成带空间位置的声源,并附上三个真实踩坑的排障经验,代码可直接跑。🎧

helloagent的博客 235

Win10插网线显示未识别网络的三种解决方法

本文介绍了三种解决Win10插网线显示未识别网络问题的方法:更新或重启网络设备驱动程序、重置Winsock目录、启用Network Setup Service服务。这些方法都是基于常见的网络问题和解决方案而设计的,适用于大多数Win10用户。如果你遇到了这一问题,可以按照上述步骤进行操作,相信一定能够找到解决问题的方法。需要注意的是,在进行任何操作之前,请务必备份重要数据以防万一。此外,如果你对计算机硬件或软件不熟悉,建议寻求专业人士的帮助以避免造成不必要的损失。

nntxthml的博客 6773

ROS基础(一)——命令行代码(以小乌龟程序为例)

ROS学习(一)——命令行代码(以小乌龟程序为例)1 基础命令行语句1.1 roscore1.2 rqt_graph(显示系统计算图)1.3 rosnode(显示所有节点相关信息)1.4 rostopic(和话题相关)2 服务类型指令rosservice同时存在两只海龟3 指令记录 1 基础命令行语句 从大二四旋翼无人机编队后就没再接触过ROS了,最近由于科研任务需要重新捡起来,打算系统学一下!学习过程参考古月居老师的视频,有兴趣的同学可以去[BliBli]学习。 学习平台:Ubuntu 18.04 硬件

北理自动化小白 6266

【每天一个 Python 小案例30】Python 基础知识综合小项目:我的工具盒

作为系列收官,本篇把前 29 篇的知识点合成一个能直接用的命令行工具"我的工具盒":计算器(用 ast 解析表达式,不碰 eval)、单位换算与温度转换(一张换算表 + 特例分支)、记账与分类统计(Decimal + JSON 持久化)、以及用"字典当命令表"把菜单和业务逻辑解耦的主循环。文中对比了 eval 的安全隐患与 ast 白名单的做法,解释了 lambda 闭包在字典里的写法与晚绑定陷阱,并在最后给出整个系列的知识地图,把变量、数据结构、控制流、函数、类、异常、文件、标准库八块内容对应到具体篇目。

xinjiyaya的博客 426

腾讯2020 unreal虚幻面试题

解析一下,腾讯的unreal客户端面试题: 1.lua性能优化的方向 申请的内存,是造成卡顿的原因之一,在C++与lua交互中,如果参数或者返回值有类变量,那么这个变量不会再交互的栈中存放数据,而会通过申请内存,再指定在交互,这样就造成卡顿,因此可以通过把C++的对象的每个参数分开单独传递,可以解决问题,当时我们游戏改完这个问题后,整体提升了2帧。 其实,主要是Tick循环中,减少与C++的交互,需要的数据不要每帧都去拿,其次,经常拿的一些数据(比方说主角信息),可以做一个lua缓存,...

qq_17347313的博客 1万+

详解Python条件语句

在 Python 中,if...else 是一种条件语句,可以根据给定的条件执行不同的操作。这个语句通常用于控制程序的流程。

2601_96798737的博客 207

解决此平台不支持虚拟化的 Intel VT-x/EPT故障问题

当我们在VMware Workstation虚拟机上【启用】虚拟系统(如:Windows10)所在的虚【拟机设置】【处理器】【虚拟化引擎】下面的【虚拟化 Intel VT-x/EPT 或AMD-V/RVI(V)】内容后,在启动虚拟系统时,虚拟系统无法启动,且弹出【此平台不支持虚拟化的 Intel VT-x/EPT。不使用虚拟化的 Intel VT-x/EPT,是否继续】窗口

提供C#相关开发 、云计算、运维测试、网络安全相关技术分享与服务,有意向可联系。 1万+

YOLOv8源码解析与复现:ShuffleAttention:高效的混合注意力机制 实现通道和空间混合注意力

随着深度学习在计算机视觉领域的飞速发展,卷积神经网络(CNNs)已经成为图像分类、目标检测、语义分割等任务的核心。为了进一步提升模型的性能,研究者们引入了“注意力机制”,旨在让网络能够动态地关注输入数据中最具信息量的部分。经典的注意力模块,如SE-Net(Squeeze-and-Excitation Networks)和CBAM(Convolutional Block Attention Module),通过通道注意力或结合通道与空间注意力,显著增强了模型的特征表达能力。

FJN110的博客 554

Python3 协程:异步编程的核心机制与实战

协程是解决I/O密集型任务等待瓶颈的高效机制,相比线程更轻量、无锁开销。从yield到async/await的演进,使异步编程语义清晰、易于理解。通过async/await可实现并发执行多个任务(如gather、create_task),显著提升网络请求、爬虫等场景性能。关键在于使用异步库(如aiohttp)替代同步库,避免阻塞事件循环。合理控制超时与并发数,才能发挥协程最大优势。

Lxn2zh的博客 159

audio语音相关的基础知识-VAD,ASR,AEC,AGC,BF等

有音素之间的间隙,也有静音和语音本身的间隙,为了对数据从时间上进行相对的校准,语音端点检测技术就应运而生了,因此端点检测技术可以决定这种校准的相对精度,使得同一内容的特征更趋于相同,当然,一般情况下是不可能完全相同的。盲源分离的目的是求得源信号的最佳估计,盲辨识的目的是求得传输通道的。这个技术的主要任务是从带有噪声的语音中准确的定位出语音的开始和结束点,因为语音中含有很长的静音,也就是把静音和实际语音分离开来,因为是语音数据的原始处理,所以VAD是语音信号处理过程的关键技术之一。呈现出与会者清晰的声音。

u013250861的博客 1034

torch.compile 差异仅 1e-6,边界样本预测为何翻转

torch.compile 加速后输出与 eager 不一致,部分预测翻转。逐层对比与 graph break 分析定位到动态分支翻转根因。容差回归仅适用于无分支翻转场景,零容忍场景应禁用编译。

昨日种种,皆成今我。今日种种,皆成新我。 159

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

二进制木马免杀-Python 分离免杀与 Web 挂马

二进制木马免杀-Python 分离免杀与 Web 挂马

2503_94637398的博客 268

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级 备考:莫队算法离线区间查询详解

备赛进行时:第十八届蓝桥杯软件赛报名已于 2026-10-08 10:00 开启、12-18 14:00 截止,省赛定在 2027-04-10(C/C++·Python 程序设计 9:00–13:00);中国电子学会 2026 年 12 月软件编程(C/C++ 一级至十级、Python 一级至六级)考级报名 9/23–12/2 16:00、统考 12-12;全国青少年信息素养大赛 2026—2027 赛季算法应用主题赛也已进入复盘练兵窗口。

IT_Scratch的博客 137

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【Python】国家中小学智慧教育平台电子教材批量下载与 PDF 合成实战

成果:两本语文电子课本(一年级上册 118 页 / 23MB、三年级上册 130 页 / 30.3MB),合计 248 页、约 54MB,单本下载加合成 40~60 秒,PDF 页数校验全部通过。经验教训SPA 站点的数据接口优先从 bundle 里挖,比抓页面稳得多;资源链接要按 private/public 分组看待,只取平台公开部分;页数、目录名这类“可推断”的信息,永远用实际响应验证一次;受限环境里“能不能跑浏览器”要在方案定稿前确认。后续计划:这版 PDF 是图片版,没有文字层;

木头大左的博客 137

魔塔社区微调训练Qwen2-1.5B-Instruct模型并烧录到‌RK3568开发板教程

本文基于Ubuntu 22.04 + CUDA 13.0.3环境,使用LLaMA-Factory框架对Qwen2-1.5B-Instruct模型进行LoRA微调,训练儿童故事生成专用模型。通过配置qwen模板、制作alpaca格式数据集、执行sft训练并合并LoRA权重,最终将模型转换为GGUF格式,并量化为Q4_K_M以适配RK3568嵌入式平台。全程支持国产镜像加速下载与显存优化,实现高效轻量化部署。

浅清秋慕夏的博客 186

【回眸】DeepSeek V4.1 Flash 快速上手与实战

本文介绍如何高效本地部署开源大模型,通过现代化工具链实现分钟级环境搭建。聚焦显存优化、一键安装、代码调用与多轮对话实现,解决“显存不足”“连接超时”等痛点,提供参数调优与结构化输出技巧,助力开发者在离线场景下快速构建稳定、高效的本地推理系统。

啤酒鸭的物联网开发记录博客 223

智叟云集-手机证据抓取系统的工程结构与应用入口

本文系统阐述手机证据抓取系统的工程结构与应用入口,涵盖四大层面:工程目录划分(Android、Python服务、Web页面、测试与构建工具);Android组件通过Manifest声明可启动页面,主界面由MainActivity管理;Python服务通过run.py解析参数并启动FastAPI应用,支持远程访问;浏览器页面采用HTML/CSS/JS分离架构,静态资源通过路径关联,实现动态交互。各模块分工明确,协同构建可运行的采集系统。

2301_77178996的博客 232

Java Arrays.asList 常见坑详解|UnsupportedOperationException、数组联动、基本类型 bug

解析 Arrays.asList 常见开发陷阱,演示 UnsupportedOperationException、底层数组引用共享、基本类型数组问题,区分 Arrays 内部 ArrayList 与 java.util.ArrayList,给出数组转 List 的各种场景正确代码。

weixin_42617033的博客 473

利用python中matplotlib.pyplot库绘制图

plt.plot(x,y) # x,y是每个点的坐标,plot()把每个点按顺序画折线。plt.subplots(2,2)表示绘制2*2的子图布局,axs[0,0]表示在第0行第0列绘制子图...coordinates_i[:,0]表示获取每一行(每一个spot)的第0列(x坐标)coordinates_i[:,1]表示获取每一行(每一个spot)的第0列(y坐标)plot.subplot(2,2,1) 表示子图布局是2*2的,开始绘制第一个。也可以导入数据绘制。可以设置color属性,设置颜色。

qq_46147236的博客 102

Spring Boot 自动配置原理

Spring Boot 自动配置由 @EnableAutoConfiguration 导入选择器,读取 jar 中 .imports 候选清单,经去重、排序、排除后逐类做条件判断,通过才注册 Bean。延迟导入让用户 Bean 优先,@ConditionalOnMissingBean 使默认配置让位。失效时查清单和 Negative matches。

2401_89855466的博客 377

【随笔】KV缓存量化:省下的显存,要付出多少数值误差

用可运行量化器解释位宽、比例信息、分组和离群值的关系,核算KV缓存实际载荷,并给出Transformers配置与容量、延迟、质量验收方法。

code2cat的博客 454

【每天一个 Python 小案例29】Python 实现商品购物车

本篇实现一个购物车:商品目录、加入商品、修改数量、移除商品、查看小计、计算满减与 VIP 折扣、结算扣库存。核心设计是"目录与购物车分离"——目录存商品主数据,购物车只存 {商品编号: 数量};金额一律用 Decimal 并做 ROUND_HALF_UP 舍入。折扣部分讲清阶梯满减的匹配顺序(阈值从高到低、命中即停)与叠加顺序(先满减、后打折),并用一次完整结算演示 706 元如何变成 613.70 元。

xinjiyaya的博客 212

Python的字典

Python字典是存储键值对的数据结构,通过键(key)快速查找对应的值(value)。可使用{}定义,支持增删改查操作:通过dict[key]查询或修改值,get()方法安全获取并设置默认值,del dict[key]删除键值对,keys()、values()和items()用于遍历。items()结合双变量循环可高效遍历所有键值对,提升代码可读性与灵活性。

qq_43010954的博客 197
上一篇: COMP62421 Querying Data on the Web Coursework Manual
下一篇: Programming Assignment 5 - Gotta Catch ‘Em All
todcode
博客等级 码龄7年 359粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值