예제 #1
0
def stop_event_loop(state, events):
    """
    Turns off the camera (if on), stops sending events.
    """
    log.debug('Stopping event loop!')
    _stop_webcam(events)
    return Gamestate(current_game=state.current_game, should_go_on=True)
예제 #2
0
 def reset(self):
     #drawn power, not power
     self.gamestate = Gamestate(self.initial_deck, self.initial_power,
                                self.initial_non_power, self.initial_market)
     np.random.shuffle(self.gamestate.deck)
     np.random.shuffle(self.gamestate.power)
     np.random.shuffle(self.gamestate.non_power)
예제 #3
0
 def __init__(self, agent_name="basic"):
     """
 Initilize the list of available commands, binding appropriate names to the
 funcitons defined in this file.
 """
     commands = {}
     commands["name"] = self.gtp_name
     commands["version"] = self.gtp_version
     commands["protocol_version"] = self.gtp_protocol
     commands["known_command"] = self.gtp_known
     commands["list_commands"] = self.gtp_list
     commands["quit"] = self.gtp_quit
     commands["boardsize"] = self.gtp_boardsize
     commands["size"] = self.gtp_boardsize
     commands["clear_board"] = self.gtp_clear
     commands["play"] = self.gtp_play
     commands["genmove"] = self.gtp_genmove
     commands["showboard"] = self.gtp_show
     commands["print"] = self.gtp_show
     commands["set_time"] = self.gtp_time
     commands["winner"] = self.gtp_winner
     commands["hexgui-analyze_commands"] = self.gtp_analyze
     commands["agent"] = self.gtp_agent
     self.commands = commands
     self.game = Gamestate(8)
     self.agent_name = agent_name
     try:
         self.agent = self.AGENTS[agent_name]()
     except KeyError:
         print("Unknown agent defaulting to basic")
         self.agent_name = "basic"
         self.agent = self.AGENTS[agent_name]()
     self.agent.set_gamestate(self.game)
     self.move_time = 10
     self.last_move = None
예제 #4
0
 def gtp_clear(self, args):
     """
 Clear the game board.
 """
     self.game = Gamestate(self.game.size)
     self.agent.set_gamestate(self.game)
     self.last_move = None
     return (True, "")
예제 #5
0
    def __init__(self, game_name):
        self.game_name = game_name

        # Set the parameters for each game type
        if self.game_name == "Oh Hell":
            self.min_players = 3
            self.max_players = 7
            self.num_decks = 1
            self.valid_cards = regular_deck

        elif self.game_name == "Rummy":
            self.min_players = 2
            self.max_players = 7
            self.num_decks = 1
            self.valid_cards = regular_deck

        else:
            # Set default of game parameters
            self.min_players = 4
            self.max_players = 4
            self.num_decks = 1
            self.valid_cards = regular_deck

        # Get Number of Players
        print("Starting game: {}".format(self.game_name))
        num_players = int(input("How many players are playing? "))
        while (num_players < self.min_players
               or num_players > self.max_players):
            num_players = int(
                input(
                    "{} isn't a valid number of players, please enter a new amount: "
                    .format(num_players)))
        self.num_players = num_players

        # Enter the player names in order
        players = []
        for i in range(0, self.num_players):
            name = input("Enter the name of player {}: ".format(i + 1))
            date = math.floor(time.time())
            id_ = name + "-" + str(date)
            players.append(Player(name, id_))

        # Build the deck of cards
        deck = Deck(self.num_decks * len(self.valid_cards),
                    enforce_order=False)
        for i in range(0, self.num_decks):
            for j in self.valid_cards:
                deck.append(Card.fromID(j))

        # Create the gamestate object, likely will switch to using a factory
        # since some games will need special gamestate attributes like current suit in Oh Hell
        self.gamestate = Gamestate(deck, players)
        print(self.gamestate)

        # Start the first action
        print("Actions not implemented yet. Ending game.")
예제 #6
0
def start_event_loop(state, events):
    """
    Turns on the camera (if off), start watching for events and subsequently
    sending them to the Mother Brain.
    """
    log.debug('Starting event loop!')
    events.start_camera()
    t = threading.Thread(target=_show_webcam, args=(events, ))
    t.start()
    return Gamestate(current_game=state.current_game, should_go_on=True)
예제 #7
0
def parse_log(log):
    log = log.split('\n')
    state = Gamestate()
    nicks = {0: {}, 1: {}}
    players = {}
    start = 2
    while len(log) > 0:
        experiences = handle_turn(log, state, nicks, players)
        for experience in experiences:
            if start > 0:
                start -= 1
            else:
                yield experience
예제 #8
0
    def gtp_boardsize(self, args):
        """
    Set the size of the game board (will also clear the board).
    """
        if (len(args) < 1):
            return (False, "Not enough arguments")
        try:
            size = int(args[0])
        except ValueError:
            return (False, "Argument is not a valid size")
        if size < 1:
            return (False, "Argument is not a valid size")

        self.game = Gamestate(size)
        self.agent.set_gamestate(self.game)
        self.last_move = None
        return (True, "")
예제 #9
0
def draw_scenario(view, path, number, total):
    if os.path.exists(path + "Gamestate.json"):
        gamestate = Gamestate.from_file(path + "Gamestate.json")
    else:
        gamestate = Gamestate({}, {}, 2)

    players = [Player("Green", "Human"), Player("Red", "Human")]
    game = Game(players, gamestate)
    view.draw_game_tutorial(game)
    view.draw_tutorial_page_number(number, total)

    if os.path.exists(path + "Blue.marked"):
        marked_blue = [
            Position.from_string(position)
            for position in json.loads(open(path +
                                            "Blue.marked").read())["tiles"]
        ]
        view.shade_positions(marked_blue, shading_blue)

    if os.path.exists(path + "Red.marked"):
        marked_red = [
            Position.from_string(position)
            for position in json.loads(open(path +
                                            "Red.marked").read())["tiles"]
        ]
        view.shade_positions(marked_red, shading_red)

    if os.path.exists(path + "Unit.txt"):
        unit_name = open(path + "Unit.txt").readline()
        unit = getattr(units_module, unit_name.replace(" ", "_"))()
        view.show_unit_zoomed_tutorial(unit, None)
        draw_unit = True
    else:
        draw_unit = False

    if os.path.exists(path + "Description.txt"):
        description = open(path + "Description.txt").readlines()
        view.draw_tutorial_message(description, draw_unit)
예제 #10
0
from gamestate import Gamestate
from myboard import Myboard

# Used to run all the code
if __name__ == '__main__':
    # Creates a board with given parameters
    board = Myboard(20, 20, 75)
    # Adds mines into the board
    board.add_mines()
    # Creates a game from the given board
    game = Gamestate(board.make_tiles(), board.safespots())
    # Draws and begins the game
    game.draw()
예제 #11
0
            del (player.friends[f])
            pre_lvl = c.level + start_combat(player, c)
        else:
            pre_lvl = r_list[c].level + start_combat(player, r_list[c])
            r_list.remove(r_list[c])
        cave(player)
    elif c == 'shady roach':
        print('You decide to head over to the Shady Roach.')
        ShadyRoach.main(player)
        cave(player)
    else:
        leave(player)


if __name__ == '__main__':
    g = Gamestate()
    print('Welcome, to RODENT RUMBLE!')
    skip = select('Load Game?', 'yes', 'no')
    skip = True if skip == 'yes' else False

    if skip:
        player = g.load()
        print('You are ' + str(player) + '.')
        print(repr(player))
        wait()
        clear()
    else:
        player = pick_rodent()
        print('You are ' + str(player) + '.')
        print(repr(player))
        clear()
예제 #12
0
 def __init__(self, state=Gamestate(8)):
     self.rootstate = deepcopy(state)
     self.root = Node()
예제 #13
0
파일: game.py 프로젝트: Zed2808/pbpy
 def __init__(self):
     self.gs = Gamestate()
     self.pb = PB()
예제 #14
0
 def __init__(self, state=Gamestate(8)):
   self.set_gamestate(state)
   self.short_symetrical = True
예제 #15
0

normfont = pygame.font.Font( pygame.font.get_default_font(), 50 )


pygame.display.set_caption("Apreta_R.txt: Bloc de notas")



bggrid = bg.BackgroundAnim()

target_delay = int(1000 / 60)
tickerEvent = pygame.event.custom_type()
pygame.time.set_timer(tickerEvent, target_delay)

state = Gamestate()

def tick():
    pass

while 1:
    castTick = False
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        if event.type == tickerEvent: castTick = True

    if castTick:
        keys = pygame.key.get_pressed()

        # predraw time (bg stuf)
        msurf.fill(blackbg)