コード例 #1
0
ファイル: Locomotion.py プロジェクト: rondelion/Lingadrome
class Locomotion(object):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.Stop = Stop()
        self.goStraight = GoStraight()
        self.Turn = Turn()
        self.FullTurn = FullTurn()
        self.Approach = Approach()

    def action(self, input, states, parameters):
        if states["locomotionType"] == "Stop":
            self.Stop.action(input, states, parameters)
        elif states["locomotionType"] == "GoStraight":
            self.goStraight.action(input, states, parameters)
        elif states["locomotionType"] == "Turn":
            self.Turn.action(input, states, parameters)
        elif states["locomotionType"] == "FullTurn":
            if input.has_key("orientation") and input["orientation"]!=None:
                self.FullTurn.action(input, states, parameters)
        elif states["locomotionType"] == "Approach":
            self.Approach.action(input, states, parameters)
        elif states["locomotionType"] == "Carry":
            pass
コード例 #2
0
ファイル: Player.py プロジェクト: piercetalbert/Go-Fish
    def __init__(self, name, books):
        self.name = name
        self.books = books

        self.cards_asked = []

        self.turn = Turn()
        self.ranks = Constants.RANK
コード例 #3
0
ファイル: Locomotion.py プロジェクト: rondelion/Lingadrome
 def __init__(self):
     '''
     Constructor
     '''
     self.Stop = Stop()
     self.goStraight = GoStraight()
     self.Turn = Turn()
     self.FullTurn = FullTurn()
     self.Approach = Approach()
コード例 #4
0
    def processPlayerTurns(self):
        while (Turn.isPlayerTurn(self.currentTurn)):
            playerIndex = Turn.turnToPlayerIndex(self.currentTurn)
            powerpoints = self.getPlayerPowerpoints(playerIndex)

            if (powerpoints >= 0):
                break
            else:  #Als het aantal krachtpunten negatief is... (= aantal dagen dat de speler moet wachten)
                self.currentTurn += 1  #Sla de beurt van een speler over
                print("skip player's turn")
コード例 #5
0
ファイル: main.py プロジェクト: Hvids/CG
 def __init__(self):
     super().__init__()
     self.a = 100
     self.b = 50
     self.c = 70
     self.h = 70
     self.travel_screen = TravelScreen()
     self.vector_see = Vector(0, 0, -1)
     self.turn = Turn()
     # self.Action()
     self.initUI()
コード例 #6
0
 def get_atk_cmd(self):
     m = random.choice(self.team.mechs)
     if len(m.nearby_enemies()) > 0:
         target = random.choice(m.nearby_enemies())
         return Turn(
             str(m.location) + " atk " + str(target.location), self.team)
     else:
         if not self.team.moved_yet():
             return self.get_move_cmd()
         else:
             return Turn("pass", self.team)
コード例 #7
0
ファイル: main.py プロジェクト: Hvids/CG
 def __init__(self):
     super().__init__()
     self.__parameter = 10
     self.travel_screen = TravelScreen()
     self.phi = 0
     self.step = 0.5
     self.timer = QTimer()
     self.timer.timeout.connect(self.route)
     self.timer.start(1)
     self.turn = Turn()
     self.scale = 1
     self.initUI()
コード例 #8
0
ファイル: Locomotion.py プロジェクト: dtbinh/Lingadrome
 def __init__(self):
     '''
     Constructor
     '''
     self.Stop = Stop()
     self.goStraight = GoStraight()
     self.Turn = Turn()
     self.FullTurn = FullTurn()
コード例 #9
0
 def get_turn(self):
     command = self.check_input()
     while True:
         if self.is_malformed(command):
             command = self.check_input()
             self.malformed_input()
         else:
             self.reset_input(command)
             return Turn(command, self.team)
コード例 #10
0
 def get_turn(self):
     self.s.send("send turn".encode('ascii'))
     command = self.s.recv(1024).decode('ascii')
     while True:
         if self.is_malformed(command):
             command = self.check_input()
             self.malformed_input()
         else:
             self.reset_input(command)
             return Turn(command, self.team)
コード例 #11
0
ファイル: DotDrawer.py プロジェクト: Joboman555/Drawbot
    def draw_points(self, waypoints):
        """ Draws the given waypoints.
            waypoints : a list of point objects with x, y, and z fields.
        """
        rows = self.extract_rows(waypoints)
        sq = Sequence(outcomes=['Completed_Successfully', 'Aborted'],
                      connector_outcome='Completed_Successfully')

        list_of_rows = []
        # How far did we travel?
        dists_back = []
        for row in rows:
            abs_dists_in_front = [point.y for point in row]
            # Keep track of the farthest distance traveled
            dists_back.append(abs_dists_in_front[-1])
            dists_in_front = self.abs_to_rel(abs_dists_in_front)
            list_of_rows.append(dists_in_front)

        # assume all lines are spaced equally, and that lines are
        # seperated perfectly on the x axis
        line_spacing = abs(rows[0][0].x - rows[1][0].x)
        print 'Line Spacing: %f' % line_spacing

        with sq:
            # Turn to the left initially to start things off.
            Sequence.add('Initial Turn',
                         Turn(-1 * math.pi / 2),
                         transitions={'Aborted': 'Aborted'})

            for i, row in enumerate(rows):
                print 'Added row ' + str(i) + ' to State Machine'
                dists_in_front = list_of_rows[i]

                # Draw a Row
                Sequence.add('Draw Row %d' % i,
                             DrawRow(dists_in_front),
                             transitions={'Aborted': 'Aborted'})
                # If we're on the last line, no need to return
                if i < len(rows) - 1:
                    # Return back to the beginning of row
                    Sequence.add('Go Back %d' % i,
                                 GoForward(-1 * dists_back[i]),
                                 transitions={'Aborted': 'Aborted'})
                    # Go to the next line
                    Sequence.add('Carriage Return %d' % i,
                                 CarriageReturn(line_spacing),
                                 transitions={'Aborted': 'Aborted'})

        return sq.execute()
コード例 #12
0
    def get_turn(self):
        w = self.game.world
        scr = w.scr
        mechs = self.team.world.get_all_mechs()
        for i in range(len(mechs)):
            scr.addstr(i + 11, 50, " " * 50)
            scr.addstr(i + 11, 50, mechs[i].get_specs())
        curses.echo()
        scr.move(2, 50)
        command = scr.getstr(2, 50, Hot_Seat_Player.MAX_COMMAND_LENGTH)
        scr.addstr(2, 50, " " * 11)
        #line 2 is the input for a command to be issued
        curses.noecho()
        scr.addstr(3, 50, " " * 50)
        scr.addstr(3, 50, command)
        #line 3 is the last command issued

        return Turn(command, self.team)
コード例 #13
0
ファイル: Game.py プロジェクト: piercetalbert/Go-Fish
    def __init__(self):
        # self.card = Card()
        self.deck = Deck()
        self.turn = Turn()

        self.hands = defaultdict(list)
        self.scores = OrderedDict()
        self.players = []
        self.draw_pile = []
        self.player_books = 0
        self.ai_books = 0

        self.human_pl = self.get_human_player()

        self.generate_ai_players()
        self.deal_cards()
        self.take_turns()
        self.victory_conditions()
コード例 #14
0
def game(running, screen, background1, clock):

    # Run risk with set player params
    tempMap = Map()

    turn = Turn(
        3, tempMap)  # Turn object created given number players and map object
    turn.initialTroops(
    )  # Sets starting troops, varies depending on number of players
    turn.distributeTerritories(
        tempMap.territories
    )  # Distributes territories to players from map list

    Continents = tempMap.continents

    # Initialize players
    turn.players[0].color = c.riskRed
    turn.players[1].color = c.riskGreen
    turn.players[2].color = c.riskBlue
    ##    turn.players[3].color = c.yellow
    ##    turn.players[4].color = c.purple
    ##    turn.players[5].color = c.teal

    turn.players[0].name = "Duncan"
    turn.players[1].name = "Isaac"
    turn.players[2].name = "Lily"
    ##    turn.players[3].name = "Finn"
    ##    turn.players[4].name = "Anna"
    ##    turn.players[5].name = "Brianna"

    # Setup and start pygame
    pygame.init()
    pygameWindow = pygame.display.set_mode((c.windowLength, c.windowWidth))

    #fix for error?
    # Create instance of Game to contain risk objects
    try:
        gameInstance = Game(pygameWindow, turn)

        gameInstance.functions.append(gameInstance.run)
        gameInstance.display()
    except UnboundLocalError:
        print("Your troops are being trained, please wait...")
        print(
            "Try moving the moving your mouse cursor onto the man's nose while you wait?"
        )

        game(running, screen, background1, clock)
コード例 #15
0
def game(running, screen, background1, clock):

    # Run risk with set player params
    tempMap = Map()

    turn = Turn(
        3, tempMap)  # Turn object created given number players and map object
    turn.initialTroops(
    )  # Sets starting troops, varies depending on number of players
    turn.distributeTerritories(
        tempMap.territories
    )  # Distributes territories to players from map list

    Continents = tempMap.continents

    # Initialize players
    turn.players[0].color = c.red
    turn.players[1].color = c.green
    turn.players[2].color = c.blue
    ##    turn.players[3].color = c.yellow
    ##    turn.players[4].color = c.purple
    ##    turn.players[5].color = c.teal

    turn.players[0].name = "Duncan"
    turn.players[1].name = "Isaac"
    turn.players[2].name = "Lily"
    ##    turn.players[3].name = "Finn"
    ##    turn.players[4].name = "Anna"
    ##    turn.players[5].name = "Brianna"

    # Setup and start pygame
    pygame.init()
    pygameWindow = pygame.display.set_mode((c.windowLength, c.windowWidth))

    # Create instance of Game to contain risk objects
    try:
        gameInstance = Game(pygameWindow, turn)

        ##        # User in game menu until button click
        ##        displayFlag = False
        ##        while (not displayFlag):
        ##            gameInstance.functions.append(gameInstance.menu)
        ##            gameInstance.display()

        gameInstance.functions.append(gameInstance.run)
        gameInstance.display()
    except UnboundLocalError:
        print("Colorization of map error, restart game and try again!")
コード例 #16
0
ファイル: Game.py プロジェクト: MrDJEnz/CS205-Final
if __name__ == "__main__":
    from tkinter import *
    import random
    import copy

    from Map import Map
    from Player import Player
    from Card import Card
    from Turn import Turn

    import Constants as c

    # Run risk with set player params
    tempMap = Map()

    turn = Turn(
        3, tempMap)  # Turn object created given number players and map object
    turn.initialTroops(
    )  # Sets starting troops, varies depending on number of players
    turn.distributeTerritories(
        tempMap.territories
    )  # Distributes territories to players from map list

    Continents = tempMap.continents

    # Initialize players
    turn.players[0].color = c.riskRed  #c.red
    turn.players[1].color = c.riskGreen  #c.green
    turn.players[2].color = c.riskBlue  #c.blue
    ##    turn.players[3].color = c.yellow
    ##    turn.players[4].color = c.purple
    ##    turn.players[5].color = c.teal
コード例 #17
0
 def get_move_cmd(self):
     return Turn("pass", self.team)
コード例 #18
0
ファイル: main.py プロジェクト: Hvids/CG
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.a = 100
        self.b = 50
        self.c = 70
        self.h = 70
        self.travel_screen = TravelScreen()
        self.vector_see = Vector(0, 0, -1)
        self.turn = Turn()
        # self.Action()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 280, 270)
        self.setWindowTitle('Lab 2')

        orthographic_projection = QCheckBox('Ортографическая проекция')
        orthographic_projection.move(5, 5)
        orthographic_projection.toggle()
        self.show()

    def mouseMoveEvent(self, e):
        if e.buttons() == Qt.LeftButton:
            end = Point(e.pos().x(), e.pos().y())
            self.travel_screen.point_end = end
            self.travel_screen.update_travel()
            self.update()
            self.travel_screen.point_start = end
        if e.buttons() == Qt.RightButton:
            end = e.pos().y()
            self.turn.end = end
            self.turn.update_turn()
            self.update()
            self.turn.start = end

    def mousePressEvent(self, e):
        if e.buttons() == Qt.LeftButton:
            start = Point(e.pos().x(), e.pos().y())
            self.travel_screen.point_start = start
        if e.buttons() == Qt.RightButton:
            start = e.pos().y()
            self.turn.start = start

    def on_changed_a(self, text):
        self.a = self.__takeParameter(text)
        self.update()

    def paintEvent(self, e):
        qp = QPainter()
        qp.begin(self)
        self.drawFigure(qp)
        qp.end()

    def drawFigure(self, qp):
        size = self.size()
        width = size.width()
        height = size.height()
        # pen = QPen(Qt.white, 1, Qt.SolidLine)
        # qp.setPen(pen)
        #
        # cordinate_axes = CordinateAxes(
        #     size.width(), size.height(), self.travel_screen)
        # cordinate_axes.draw(qp)

        pen = QPen(Qt.red, 2, Qt.SolidLine)
        qp.setPen(pen)

        wedge = Wedge(self.a, self.b, self.c, self.h)
        wedge.to_scale(k_x=width / 270, k_y=width / 280, k_z=1)
        # wedge.to_turn_oz(phi=self.turn.phi)
        wedge.to_turn_ox(phi=self.turn.phi)
        # wedge.to_turn_oy(phi=self.turn.phi)

        wedge.move(d_x=width / 4 - self.travel_screen.travel_x,
                   d_y=height / 4 - self.travel_screen.travel_y,
                   d_z=1)

        wedge.clear(self.vector_see)
        wedge.to_isometric_transform(phi=math.pi / 5, tetta=math.pi / 5)

        # wedge.to_orthographic_projection_z()
        wedge.draw(qp)

    def __takeParameter(self, text):
        try:
            res = float(text)
        except Exception as e:
            res = 10
        if res <= 0:
            res = 10
        return res
コード例 #19
0
ファイル: main.py プロジェクト: Hvids/CG
class Example(QWidget):

    def __init__(self):
        super().__init__()
        self.__parameter = 10
        self.travel_screen = TravelScreen()
        self.phi = 0
        self.step = 0.5
        self.timer = QTimer()
        self.timer.timeout.connect(self.route)
        self.timer.start(1)
        self.turn = Turn()
        self.scale = 1
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 280, 270)
        self.setWindowTitle('Lab 1')
        self.label_a = QLabel(self)
        self.label_a.setText('a')
        self.label_a.move(90, 5)
        self.label_step = QLabel(self)

        self.label_step.setText('step')
        self.label_step.move(90, 30)
        input_a = QLineEdit(self)
        input_a.setMaximumWidth(80)
        input_step = QLineEdit(self)
        input_step.move(5, 30)
        input_step.setMaximumWidth(80)
        input_a.move(5, 5)
        input_a.textChanged[str].connect(self.onChanged)
        input_step.textChanged[str].connect(self.onChangedStep)

        btn1 = QPushButton('+', self)
        btn2 = QPushButton('-', self)
        btn1.move(200, 5)
        btn2.move(200, 30)
        btn1.clicked.connect(self.onScalePlus)
        btn2.clicked.connect(self.onScaleMinus)
        self.show()

    def onScalePlus(self):
        self.scale += 1
        self.update()

    def onScaleMinus(self):
        self.scale -= 1
        if self.scale < 1:
            self.scale = 1
        self.update()

    def onChangedStep(self, text):
        try:
            self.step = float(text) / 10
        except Exception as e:
            print('lol')
            self.step = 0.5
        if self.step <= 0:
            self.step = 0.5

        print(self.step)
        self.update()

    def mouseMoveEvent(self, e):
        if e.buttons() == Qt.LeftButton:
            end = Point(e.pos().x(), e.pos().y())
            self.travel_screen.point_start = self.travel_screen.point_end
            self.travel_screen.point_end = end
            self.travel_screen.update_travel()
            self.update()
        if e.buttons() == Qt.RightButton:
            end = e.pos().y()
            self.turn.end = end
            self.turn.update_turn()
            self.update()

    def mousePressEvent(self, e):
        if e.buttons() == Qt.LeftButton:

            start = Point(e.pos().x(), e.pos().y())
            self.travel_screen.point_start = start
            self.travel_screen.point_end = start
        if e.buttons() == Qt.RightButton:

            start = e.pos().y()
            self.turn.start = start

    def onChanged(self, text):
        self.__takeParameter(text)
        self.update()

    def paintEvent(self, e):
        qp = QPainter()
        qp.begin(self)
        self.drawFigure(qp)
        qp.end()

    def drawFigure(self, qp):
        size = self.size()

        pen = QPen(Qt.white, 1, Qt.SolidLine)
        qp.setPen(pen)

        cordinate_axes = CordinateAxes(
            size.width(), size.height(), self.travel_screen, self.scale * 10)
        cordinate_axes.draw(qp)

        pen = QPen(Qt.red, 2, Qt.SolidLine)
        qp.setPen(pen)

        curve = Curve(qp, size.width(), size.height(),
                      self.__parameter, self.step, self.travel_screen, self.phi, self.scale)
        curve.draw()

    def route(self):
        try:
            self.phi = (self.phi + 0.1)
        except Exception as e:
            self.phi = 0

        self.update()

    def __takeParameter(self, text):
        try:
            self.__parameter = float(text)
        except Exception as e:
            self.__parameter = 10
        if self.__parameter <= 0:
            self.__parameter = 10
コード例 #20
0
ファイル: Player.py プロジェクト: piercetalbert/Go-Fish
class Player:
    def __init__(self, name, books):
        self.name = name
        self.books = books

        self.cards_asked = []

        self.turn = Turn()
        self.ranks = Constants.RANK

    def play_turn(self, hands, draw_pile, player):
        while True:
            print("")
            self.turn.see_current_hand(hands, player)
            print("")
            cards_taken = 0
            p_hand = list(hands[player])

            if len(p_hand) > 0:
                while True:
                    ask_card = input("Choose a card: ")

                    #check if card is valid
                    if ask_card in self.ranks:
                        valid_cards = [y for y in p_hand if y.rank == ask_card]
                        if not valid_cards:
                            print("ERROR: card not in hand.")
                            continue
                        break
                    else:
                        print("ERROR: not a valid card.")
                        continue

                ##set asked card to any of the tmp cards
                #(doesn't matter which one, we just want rank)
                crd = valid_cards[0]
                self.cards_asked.append(crd)

                table = self.turn.get_players(hands.keys())
                #can't ask yourself
                table.remove(player)

                #pick a player to ask
                while True:
                    print("")
                    print(table)
                    print("")
                    ask_player = input("Choose player: ")
                    if ask_player in table:
                        pl = ask_player
                        break
                    else:
                        print("")
                        print("Not a valid player.")
                        continue

                time.sleep(0.2)
                print("")
                print(pl + ", do you have any " + crd.rank + "'s?")

                #check if you made a catch, try to make a book
                cards_taken = self.turn.ask_for_card(hands, crd, player, pl)
                if cards_taken > 0:
                    self.books = self.create_book(hands, player, self.books)
                    continue
                else:
                    break
            else:
                print("")
                print("Hand empty!")
                break

        ##check if the draw pile has cards, and draw
        #also do another check if a book can be made
        if len(draw_pile) > 0:
            fished_card = self.turn.go_fish(draw_pile, hands, player)
            self.books = self.create_book(hands, player, self.books)
            print("")
            print("Go fish!")

            time.sleep(0.2)
            print("")
            print("Draw card: ", fished_card.get_full_name())

        else:
            print("")
            print("Draw pile empty!")

    def create_book(self, hands, player, books):
        p_hand = list(hands[player])
        x = 0
        ##make a tmp book with any matching ranks in the player's hand
        #if tmp book has all four suits of that rank, remove them and add to books count
        while x < len(self.ranks):
            temp_book = [y for y in p_hand if y.rank == self.ranks[x]]
            if len(temp_book) == 4:
                books += 1
                hands[player] = [
                    z for z in hands[player] if z not in temp_book
                ]
            x += 1
            temp_book = []

        return books
コード例 #21
0
ファイル: AIPlayer.py プロジェクト: piercetalbert/Go-Fish
    def ai_turn(self, hands, draw_pile, player, players):

        print("")
        self.turn.see_current_hand(hands, player)

        previous_moves = []

        cards_taken = 1
        while cards_taken > 0:
            cards_taken = 0
            ai_hand = list(hands[player])

            if len(ai_hand) > 0:

                table = []

                ##table contains the eligible players to ask
                # removes itself and any players who have 0 cards
                for x in players:
                    if x.name == player:
                        continue
                    elif not hands[x.name]:
                        continue
                    else:
                        table.append(x)

                # default move
                pl = self.__ai_choose_player(table, hands, player, players)
                crd = self.__ai_choose_card(ai_hand, player, pl, players)
                move = (pl, crd)

                # check if this is the AIs first turn, if yes do not evaluate previous cards
                if self.previous_player == None or self.previous_card == None:
                    pl = self.__ai_choose_player(table, hands, player, players)
                    crd = self.__ai_choose_card(ai_hand, player, pl, players)

                ##if the move is equal to any previous move this turn,
                # choose a different player to ask
                else:
                    if move in previous_moves:
                        table.remove(pl)
                        pl = self.__ai_choose_player(table, hands, player,
                                                     players)
                        crd = self.__ai_choose_card(ai_hand, player, pl,
                                                    players)

                self.cards_asked.append(crd)
                self.previous_player = pl
                self.previous_card = crd
                previous_move = (self.previous_player, self.previous_card)
                previous_moves.append(previous_move)

                # ask for cards as long as its hand has cards
                time.sleep(0.2)
                print("")
                print(pl.name + ", do you have any " + crd.rank + "'s?")
                cards_taken = self.turn.ask_for_card(hands, crd, player,
                                                     pl.name)
                self.books = self.create_book(hands, player, self.books)
            else:
                print("")
                print("Hand empty!")
                break

        ##check if the draw pile has cards, and draw
        # also do another check if a book can be made
        if len(draw_pile) > 0:
            turn = Turn()
            fished_card = turn.go_fish(draw_pile, hands, player)
            self.books = self.create_book(hands, player, self.books)
            time.sleep(0.2)
            print("")
            print("Go fish!")
        else:
            print("")
            print("Draw pile empty!")