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)
Esempio n. 2
0
    def __init__(self, name, books):
        self.name = name
        self.books = books

        self.cards_asked = []

        self.turn = Turn()
        self.ranks = Constants.RANK
Esempio n. 3
0
 def __init__(self):
     '''
     Constructor
     '''
     self.Stop = Stop()
     self.goStraight = GoStraight()
     self.Turn = Turn()
     self.FullTurn = FullTurn()
     self.Approach = Approach()
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
File: main.py Progetto: 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()
Esempio n. 7
0
File: main.py Progetto: 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()
Esempio n. 8
0
    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()
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!")
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)
Esempio n. 11
0
    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()
    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)
Esempio n. 13
0
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
Esempio n. 14
0
    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!")
Esempio n. 15
0
 def get_move_cmd(self):
     return Turn("pass", self.team)