Ejemplo n.º 1
0
    def __init__(self, numPlayers):

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

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

        self.pointsForLongestRoute = 10
        self.startingNumOfTrains = 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)
Ejemplo n.º 2
0
    def __init__(self, startingHand, startingTickets, playerBoard,
                 playerPosition, numTrains, type):
        """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

        #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.playerPosition = playerPosition

        #custom board to represent
        self.playerBoard = playerBoard
        self.fullBoard = TTRBoard.Board()

        #Human or AI player
        self.type = type
        self.numTurns = 0
Ejemplo n.º 3
0
    def create_all_players(self):
        for position in range(self.numPlayers):
            startingHand = self.deck.dealCards(self.sizeStartingHand)
            startingTickets = []
            playerBoard = TTRBoard.PlayerBoard()

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

            self.players.append(player)
Ejemplo n.º 4
0
    def __init__(self):

        self.sizeDrawPile = 5
        self.maxWildsToDrawFrom = 3
        self.numTicketsDealt = 3
        self.minTicketsToKeepAtStart = 2
        self.sizeStartingHand = 4

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

        self.pointsForLongestRoute = 10
        self.startingNumOfTrains = 45

        self.deck = TTRCards.Cards(self.sizeDrawPile, self.maxWildsToDrawFrom)
        self.board = TTRBoard.Board()
        self.numPlayers = 0  # to be determined
        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}
Ejemplo n.º 5
0
    def __init__(self, numAIPlayers, numHumanPlayers, aiStrategies):
        self.sizeDrawPile = 5
        self.maxWilds = 3
        self.numTicketsDealt = 3
        self.sizeStartingHand = 4

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

        self.pointsForLongestRoute = 10
        self.startingNumOfTrains = 45

        self.deck = TTRCards.Cards(self.sizeDrawPile, self.maxWilds)
        self.board = TTRBoard.Board()
        self.fullBoard = TTRBoard.Board()
        self.numAIPlayers = numAIPlayers
        self.numHumanPlayers = numHumanPlayers
        self.numPlayers = numAIPlayers + numHumanPlayers
        self.players = []

        self.gameBoard = TTRBoard.Board()

        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(numHumanPlayers):
            type = 'Human'
            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, type)
            self.players.append(player)

        for position in range(numAIPlayers):
            type_ = 'AI'
            strategy = aiStrategies[position]
            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()

            if strategy == 'tickets':
                player = ticketAIPlayer.ticketAIPlayer(
                    startingHand, startingTickets, playerBoard, position,
                    self.startingNumOfTrains, type_)
            elif strategy == 'route':
                player = routeAIPlayer.routeAIPlayer(startingHand,
                                                     startingTickets,
                                                     playerBoard, position,
                                                     self.startingNumOfTrains,
                                                     type_)
            elif strategy == 'random':
                player = randomAIPlayer.randomAIPlayer(
                    startingHand, startingTickets, playerBoard, position,
                    self.startingNumOfTrains, type_)
            elif strategy == 'mixed':
                player = mixedAIPlayer.mixedAIPlayer(startingHand,
                                                     startingTickets,
                                                     playerBoard, position,
                                                     self.startingNumOfTrains,
                                                     type_)

            self.players.append(player)
Ejemplo n.º 6
0
import TTRBoard
import networkx as nx

B = TTRBoard.Board()

games = [["mixed", "tickets"], ["mixed", "mixed"]]


def getGraph(game):
    edgeLabels = []
    G1 = nx.Graph()
    G2 = nx.Graph()

    with open("TTR_edges_" + game[0] + "_" + game[1] + ".csv") as file:
        for line in file:
            splitLine = line.split(":")
            playerName = splitLine[0]

            data = splitLine[1]
            nodes = data.split("-")
            for node in nodes:
                nodeList = node.split(",")

                if len(nodeList) == 2:
                    if playerName == "p1" and G1.has_edge(
                            nodeList[0], nodeList[1]):
                        G1.get_edge_data(nodeList[0],
                                         nodeList[1])['count'] += 1
                    elif playerName == "p1" and not G1.has_edge(
                            nodeList[0], nodeList[1]):
                        G1.add_edge(nodeList[0], nodeList[1], count=1)