当前位置: 首页>>代码示例>>Python>>正文


Python State.get方法代码示例

本文整理汇总了Python中giles.state.State.get方法的典型用法代码示例。如果您正苦于以下问题:Python State.get方法的具体用法?Python State.get怎么用?Python State.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在giles.state.State的用法示例。


在下文中一共展示了State.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Talpa

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Talpa(SeatedGame):
    """A Talpa game table implementation.  Invented in 2010 by Arty Sandler.
    """

    def __init__(self, server, table_name):

        super(Talpa, self).__init__(server, table_name)

        self.game_display_name = "Talpa"
        self.game_name = "talpa"
        self.seats = [Seat("Red"), Seat("Blue")]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RTalpa^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Talpa-specific stuff.
        self.size = 8
        self.turn = None
        self.red = self.seats[0]
        self.red.data.seat_str = "^RRed/Vertical^~"
        self.blue = self.seats[1]
        self.blue.data.seat_str = "^BBlue/Horizontal^~"
        self.resigner = None
        self.layout = None

        # Like in most connection games, there is no difference between pieces
        # of a given color, so we save time and create our singleton pieces
        # here.
        self.rp = Piece("^R", "x", "X")
        self.rp.data.owner = self.red
        self.bp = Piece("^B", "o", "O")
        self.bp.data.owner = self.blue

        # Initialize the starting layout.
        self.init_layout()

    def init_layout(self):

        # Create the layout and fill it with pieces.
        self.layout = SquareGridLayout(highlight_color="^I")
        self.layout.resize(self.size)

        for i in range(self.size):
            for j in range(self.size):
                if (i + j) % 2:
                    self.layout.place(self.rp, i, j, update=False)
                else:
                    self.layout.place(self.bp, i, j, update=False)

        self.layout.update()

    def get_sp_str(self, seat):

        return "^C%s^~ (%s)" % (seat.player_name, seat.data.seat_str)

    def get_turn_str(self):

        if not self.turn:
            return "The game has not yet started.\n"

        return "It is ^C%s^~'s turn (%s).\n" % (self.turn.player_name, self.turn.data.seat_str)

    def show(self, player):

        player.tell_cc(self.layout)
        player.tell_cc(self.get_turn_str())

    def send_board(self):

        for player in self.channel.listeners:
            self.show(player)

    def set_size(self, player, size_str):

        if not size_str.isdigit():
            self.tell_pre(player, "You didn't even send a number!\n")
            return False

        size = int(size_str)

        if size < MIN_SIZE or size > MAX_SIZE:
            self.tell_pre(player, "Size must be between %d and %d inclusive.\n" % (MIN_SIZE, MAX_SIZE))
            return False

        # Size must be even.
        if size % 2:
            self.tell_pre(player, "Size must be even.\n")
            return False

        # Valid!
        self.size = size
        self.bc_pre("^R%s^~ has set the board size to ^C%d^~.\n" % (player, size))
        self.init_layout()

    def move(self, player, src_bits, dst_bits):

        seat = self.get_seat_of_player(player)
        if not seat:
#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:talpa.py

示例2: Breakthrough

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Breakthrough(SeatedGame):
    """A Breakthrough game table implementation.  Invented in 2000 by Dan Troyka.
    """

    def __init__(self, server, table_name):

        super(Breakthrough, self).__init__(server, table_name)

        self.game_display_name = "Breakthrough"
        self.game_name = "breakthrough"
        self.seats = [
            Seat("Black"),
            Seat("White")
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RBreakthrough^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Breakthrough-specific stuff.
        self.width = 8
        self.height = 8
        self.turn = None
        self.black = self.seats[0]
        self.white = self.seats[1]
        self.resigner = None
        self.layout = None

        # We cheat and create a black and white piece here.  Breakthrough
        # doesn't differentiate between pieces, so this allows us to do
        # comparisons later.
        self.bp = Piece("^K", "b", "B")
        self.bp.data.owner = self.black
        self.wp = Piece("^W", "w", "W")
        self.wp.data.owner = self.white

        self.init_board()

    def init_board(self):

        # Create the layout and the pieces it uses as well.  Note that we
        # can be ultra-lazy with the pieces, as Breakthrough doesn't distinguish
        # between them, so there's no reason to create a bunch of identical
        # bits.
        self.layout = SquareGridLayout()
        self.layout.resize(self.width, self.height)
        last_row = self.height - 1
        next_last_row = last_row - 1

        for i in range(self.width):
            self.layout.place(self.bp, 0, i, update=False)
            self.layout.place(self.bp, 1, i, update=False)
            self.layout.place(self.wp, next_last_row, i, update=False)
            self.layout.place(self.wp, last_row, i, update=False)

        # Set the piece counts.
        self.white.data.piece_count = self.width * 2
        self.black.data.piece_count = self.width * 2
        self.layout.update()

    def show(self, player):

        player.tell_cc(self.layout)
        player.tell_cc(self.get_turn_str() + "\n")

    def send_board(self):

        for player in self.channel.listeners:
            self.show(player)

    def get_turn_str(self):

        if not self.turn:
            return ("The game has not yet started.\n")

        if self.turn == self.black:
            player = self.seats[0].player
            color_msg = "^KBlack^~"
        else:
            player = self.seats[1].player
            color_msg = "^WWhite^~"

        return ("It is ^Y%s^~'s turn (%s)." % (player, color_msg))

    def move(self, player, src, dst):

        seat = self.get_seat_of_player(player)
        if not seat:
            self.tell_pre(player, "You can't move; you're not playing!\n")
            return False

        if self.turn != seat:
            self.tell_pre(player, "You must wait for your turn to move.\n")
            return False

        src_c, src_r = src
        dst_c, dst_r = dst
        src_str = "%s%s" % (COLS[src_c], src_r + 1)
        dst_str = "%s%s" % (COLS[dst_c], dst_r + 1)
#.........这里部分代码省略.........
开发者ID:Cloudxtreme,项目名称:giles,代码行数:103,代码来源:breakthrough.py

示例3: Crossway

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Crossway(SeatedGame):
    """A Crossway game table implementation.  Invented in 2007 by Mark Steere.
    """

    def __init__(self, server, table_name):

        super(Crossway, self).__init__(server, table_name)

        self.game_display_name = "Crossway"
        self.game_name = "crossway"
        self.seats = [
            Seat("Black"),
            Seat("White")
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RCrossway^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Crossway-specific stuff.
        self.board = None
        self.printable_board = None
        self.size = 19
        self.turn = None
        self.turn_number = 0
        self.seats[0].data.side = BLACK
        self.seats[1].data.side = WHITE
        self.last_r = None
        self.last_c = None
        self.resigner = None
        self.adjacency_map = None
        self.found_winner = False

        self.init_board()

    def init_board(self):

        self.board = []

        # Generate a new empty board.
        for r in range(self.size):
            self.board.append([None] * self.size)

    def update_printable_board(self):

        self.printable_board = []
        col_str = "    " + "".join([" " + COLS[i] for i in range(self.size)])
        self.printable_board.append(col_str + "\n")
        self.printable_board.append("   ^m.=" + "".join(["=="] * self.size) + ".^~\n")
        for r in range(self.size):
            this_str = "%2d ^m|^~ " % (r + 1)
            for c in range(self.size):
                if r == self.last_r and c == self.last_c:
                    this_str += "^5"
                loc = self.board[r][c]
                if loc == WHITE:
                    this_str += "^Wo^~ "
                elif loc == BLACK:
                    this_str += "^Kx^~ "
                else:
                    this_str += "^M.^~ "
            this_str += "^m|^~ %d" % (r + 1)
            self.printable_board.append(this_str + "\n")
        self.printable_board.append("   ^m`=" + "".join(["=="] * self.size) + "'^~\n")
        self.printable_board.append(col_str + "\n")

    def show(self, player):

        if not self.printable_board:
            self.update_printable_board()
        for line in self.printable_board:
            player.tell_cc(line)
        player.tell_cc(self.get_turn_str() + "\n")

    def send_board(self):

        for player in self.channel.listeners:
            self.show(player)

    def get_turn_str(self):

        if not self.turn:
            return ("The game has not yet started.\n")

        if self.turn == BLACK:
            player = self.seats[0].player_name
            color_msg = "^KBlack/Vertical^~"
        else:
            player = self.seats[1].player_name
            color_msg = "^WWhite/Horizontal^~"

        return ("It is ^Y%s^~'s turn (%s)." % (player, color_msg))

    def is_valid(self, row, col):

        if row < 0 or row >= self.size or col < 0 or col >= self.size:
            return False
        return True

#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:crossway.py

示例4: RockPaperScissors

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class RockPaperScissors(SeatedGame):
    """A Rock-Paper-Scissors game table implementation.
    """

    def __init__(self, server, table_name):

        super(RockPaperScissors, self).__init__(server, table_name)

        self.game_display_name = "Rock-Paper-Scissors"
        self.game_name = "rps"
        self.seats = [
            Seat("Left"),
            Seat("Right"),
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.plays = [None, None]
        self.prefix = "(^RRPS^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # RPS requires both seats, so may as well mark them active.
        self.seats[0].active = True
        self.seats[1].active = True

    def handle(self, player, command_str):

        # Handle common commands.
        handled = self.handle_common_commands(player, command_str)

        state = self.state.get()

        if state == "need_moves":

            command_bits = command_str.split()
            primary = command_bits[0].lower()

            # If this player is used to prefacing plays with 'move'/'play',
            # let's be polite and just chomp that away.  Also allow 'throw'
            # and 'th', even though they're undocumented, because they seem
            # like an obvious sort of command to try.  (Read that as: I kept
            # typing it.)
            if primary in ('move', 'play', 'throw', 'mv', 'pl', 'th') and len(command_bits) > 1:
                primary = command_bits[1].lower()
            if primary in ('r', 'p', 's', 'rock', 'paper', 'scissors'):
                self.move(player, primary)
                handled = True

            if self.plays[0] and self.plays[1] and self.active:

                # Got the moves!
                self.resolve()
                self.finish()

        if not handled:
            player.tell_cc(self.prefix + "Invalid command.\n")

    def tick(self):

        # If we were looking for players, check to see if both
        # seats are full and the game is active.  If so, autostart.
        if (self.state.get() == "need_players" and self.seats[0].player and
           self.seats[1].player and self.active):
            self.state.set("need_moves")
            self.channel.broadcast_cc(self.prefix + "Left: ^Y%s^~; Right: ^Y%s^~\n" %
               (self.seats[0].player, self.seats[1].player))
            self.channel.broadcast_cc(self.prefix + "Players, make your moves!\n")

    def show(self, player):

        state = self.state.get()
        if state == "need_players":
            player.tell_cc(self.prefix + "Everyone is hovering around the table, waiting for players.\n")
        elif state == "need_moves":
            for loc, color in ((0, "^Y"), (1, "^M")):
                if self.seats[loc].player:
                    name = repr(self.seats[loc].player)
                    if self.plays[loc]:
                        player.tell_cc(self.prefix + color + name + "^~'s hand is trembling with anticipation.\n")
                    else:
                        player.tell_cc(self.prefix + color + name + "^~ seems to be deep in thought.\n")
                else:
                    player.tell_cc(self.prefix + "^C%s^~ is strangely empty.\n" % self.seats[loc])
        else:
            player.tell_cc(self.prefix + "Nothing to see here.  Move along.\n")

    def show_help(self, player):

        super(RockPaperScissors, self).show_help(player)
        player.tell_cc("\nROCK-PAPER-SCISSORS:\n\n")
        player.tell_cc("                      ^!rock^., ^!r^.     Throw rock.\n")
        player.tell_cc("                     ^!paper^., ^!p^.     Throw paper.\n")
        player.tell_cc("                  ^!scissors^., ^!s^.     Throw scissors.\n")

    def move(self, player, play):

        seat = self.get_seat_of_player(player)
        if not seat:
            player.tell_cc(self.prefix + "You're not playing in this game!\n")
            return
#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:rock_paper_scissors.py

示例5: Ataxx

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]

#.........这里部分代码省略.........

        # ...and reinitialize the board.
        self.init_board()

    def update_printable_board(self):

        self.printable_board = []
        col_str = "    " + "".join([" " + COLS[i] for i in range(self.size)])
        self.printable_board.append(col_str + "\n")
        self.printable_board.append("   ^m.=" + "".join(["=="] * self.size) + ".^~\n")
        for r in range(self.size):
            this_str = "%2d ^m|^~ " % (r + 1)
            for c in range(self.size):
                if r == self.last_r and c == self.last_c:
                    this_str += "^I"
                loc = self.board[r][c]
                if loc == RED:
                    this_str += "^RR^~ "
                elif loc == BLUE:
                    this_str += "^BB^~ "
                elif loc == GREEN:
                    this_str += "^GG^~ "
                elif loc == YELLOW:
                    this_str += "^YY^~ "
                elif loc == PIT:
                    this_str += "^Ko^~ "
                else:
                    this_str += "^M.^~ "
            this_str += "^m|^~ %d" % (r + 1)
            self.printable_board.append(this_str + "\n")
        self.printable_board.append("   ^m`=" + "".join(["=="] * self.size) + "'^~\n")
        self.printable_board.append(col_str + "\n")

    def get_info_str(self):

        if not self.turn:
            return("The game has not yet started.\n")

        if self.turn == RED:
            name = self.seats[0].player_name
            turn_str = "^RRed^~"
        elif self.turn == BLUE:
            name = self.seats[1].player_name
            turn_str = "^BBlue^~"
        elif self.turn == GREEN:
            name = self.seats[2].player_name
            turn_str = "^GGreen^~"
        else:
            name = self.seats[3].player_name
            turn_str = "^YYellow^~"

        info_str = "It is %s's turn (%s).\n" % (name, turn_str)
        info_str += "^RRed^~: %d  ^BBlue^~: %d" % (self.seats[0].data.count, self.seats[1].data.count)
        if self.player_mode == 4:
            info_str += "  ^GGreen^~: %d  ^YYellow^~: %d" % (self.seats[2].data.count, self.seats[3].data.count)
        info_str += "\n"
        return(info_str)

    def show(self, player):

        if not self.printable_board:
            self.update_printable_board()
        for line in self.printable_board:
            player.tell_cc(line)
        player.tell_cc(self.get_info_str())
开发者ID:Cloudxtreme,项目名称:giles,代码行数:69,代码来源:ataxx.py

示例6: Metamorphosis

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Metamorphosis(SeatedGame):
    """A Metamorphosis game table implementation.  Invented in 2009 by Gregory
    Keith Van Patten.  Play seems to show that ko fight mode is definitely
    superior to the alternative, so we set it as default.
    """

    def __init__(self, server, table_name):

        super(Metamorphosis, self).__init__(server, table_name)

        self.game_display_name = "Metamorphosis"
        self.game_name = "metamorphosis"
        self.seats = [
            Seat("Black"),
            Seat("White")
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RMetamorphosis^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Metamorphosis-specific stuff.
        self.board = None
        self.printable_board = None
        self.size = 12
        self.ko_fight = True
        self.group_count = None
        self.turn = None
        self.turn_number = 0
        self.seats[0].data.side = BLACK
        self.seats[0].data.last_was_ko = False
        self.seats[1].data.side = WHITE
        self.seats[1].data.last_was_ko = False
        self.last_r = None
        self.last_c = None
        self.resigner = None
        self.adjacency_map = None
        self.found_winner = False

        self.init_board()

    def init_board(self):

        self.board = []

        # Generate a new empty board.  Boards alternate the starting checkered
        # layout, which we can pregen.
        white_first_row = []
        black_first_row = []
        for c in range(self.size):
            if c % 2:
                white_first_row.append(BLACK)
                black_first_row.append(WHITE)
            else:
                white_first_row.append(WHITE)
                black_first_row.append(BLACK)

        # Then we just add the appropriate rows, two at a time.
        for r in range(self.size / 2):
            self.board.append(white_first_row[:])
            self.board.append(black_first_row[:])

        # Count the number of groups on the board.  Should be size^2.
        self.group_count = self.get_group_count()

    def update_printable_board(self):

        self.printable_board = []
        col_str = "    " + "".join([" " + COLS[i] for i in range(self.size)])
        self.printable_board.append(col_str + "\n")
        self.printable_board.append("   ^m.=" + "".join(["=="] * self.size) + ".^~\n")
        for r in range(self.size):
            this_str = "%2d ^m|^~ " % (r + 1)
            for c in range(self.size):
                if r == self.last_r and c == self.last_c:
                    this_str += "^5"
                loc = self.board[r][c]
                if loc == WHITE:
                    this_str += "^Wo^~ "
                elif loc == BLACK:
                    this_str += "^Kx^~ "
                else:
                    this_str += "^M.^~ "
            this_str += "^m|^~ %d" % (r + 1)
            self.printable_board.append(this_str + "\n")
        self.printable_board.append("   ^m`=" + "".join(["=="] * self.size) + "'^~\n")
        self.printable_board.append(col_str + "\n")

    def show(self, player):

        if not self.printable_board:
            self.update_printable_board()
        for line in self.printable_board:
            player.tell_cc(line)
        player.tell_cc(self.get_turn_str() + "\n")

    def send_board(self):

        for player in self.channel.listeners:
#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:metamorphosis.py

示例7: Hex

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]

#.........这里部分代码省略.........
        for x in range(self.size):
            msg = " "
            color_char = "^W"
            if x % 2 == 0:
                color_char = "^K"
            slash_line += color_char + "/^~ "
            char_line += "%s " % COL_CHARACTERS[x]
            for spc in range(self.size - x):
                msg += " "
            for y in range(self.size):
                piece = self.board[y][x]
                if y == self.last_x and x == self.last_y:
                    msg += "^5"
                if piece == BLACK:
                    msg += "^Kx^~ "
                elif piece == WHITE:
                    msg += "^Wo^~ "
                elif y % 2 == 0:
                    msg += "^m,^~ "
                else:
                    msg += "^M.^~ "
            msg += "- " + str(x + 1) + "\n"
            self.printable_board.append(msg)
        self.printable_board.append(slash_line + "\n")
        self.printable_board.append(char_line + "\n")

    def print_board(self, player):

        if not self.printable_board:
            self.update_printable_board()
        for line in self.printable_board:
            player.tell_cc(line)

    def get_turn_str(self):
        if self.state.get() == "playing":
            if self.seats[0].data.color == self.turn:
                color_word = "^WWhite/Horizontal^~"
                name_word = "^R%s^~" % self.seats[0].player_name
            else:
                color_word = "^KBlack/Vertical^~"
                name_word = "^Y%s^~" % self.seats[1].player_name
            return "It is %s's turn (%s).\n" % (name_word, color_word)
        else:
            return "The game is not currently active.\n"

    def send_board(self):

        for player in self.channel.listeners:
            self.print_board(player)

    def resign(self, seat):

        # Okay, this person can resign; it's their turn, after all.
        self.channel.broadcast_cc(self.prefix + "^R%s^~ is resigning from the game.\n" % seat.player_name)
        self.resigner = seat.data.color
        return True

    def show(self, player):
        self.print_board(player)
        player.tell_cc(self.get_turn_str())

    def show_help(self, player):

        super(Hex, self).show_help(player)
        player.tell_cc("\nHEX SETUP PHASE:\n\n")
        player.tell_cc("          ^!setup^., ^!config^., ^!conf^.     Enter setup phase.\n")
开发者ID:Cloudxtreme,项目名称:giles,代码行数:70,代码来源:hex.py

示例8: Redstone

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Redstone(SeatedGame):
    """A Redstone game table implementation.  Invented in 2012 by Mark Steere.
    """

    def __init__(self, server, table_name):

        super(Redstone, self).__init__(server, table_name)

        self.game_display_name = "Redstone"
        self.game_name = "redstone"
        self.seats = [
            Seat("Black"),
            Seat("White"),
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RRedstone^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Redstone-specific stuff.
        self.height = 19
        self.width = 19
        self.turn = None
        self.black = self.seats[0]
        self.black.data.seat_str = "^KBlack^~"
        self.black.data.made_move = False
        self.white = self.seats[1]
        self.white.data.seat_str = "^WWhite^~"
        self.white.data.made_move = False
        self.resigner = None
        self.layout = None

        # Like most abstracts, Redstone doesn't need to differentiate between
        # the pieces on the board.
        self.bp = Piece("^K", "x", "X")
        self.bp.data.owner = self.black
        self.black.data.piece = self.bp
        self.wp = Piece("^W", "o", "O")
        self.wp.data.owner = self.white
        self.white.data.piece = self.wp
        self.rp = Piece("^R", "r", "R")
        self.rp.data.owner = None

        # Initialize the starting layout.
        self.init_layout()

    def init_layout(self):

        # Create the layout.  Empty, so easy.
        self.layout = SquareGridLayout(highlight_color="^I")
        self.layout.resize(self.width, self.height)

    def get_sp_str(self, seat):

        return "^C%s^~ (%s)" % (seat.player_name, seat.data.seat_str)

    def get_turn_str(self):

        if not self.turn:
            return "The game has not yet started.\n"

        return "It is ^C%s^~'s turn (%s).\n" % (self.turn.player_name, self.turn.data.seat_str)

    def show(self, player):

        player.tell_cc(self.layout)
        player.tell_cc(self.get_turn_str())

    def send_board(self):

        for player in self.channel.listeners:
            self.show(player)

    def set_size(self, player, size_bits):

        # Is there an 'x' in the middle of a single argument?
        if len(size_bits) == 1:
            size_bits[0] = size_bits[0].lower()
            if "x" in size_bits[0]:
                size_bits = size_bits[0].split("x")

        width = size_bits[0]
        # If there's a single element, height == width.
        if len(size_bits) == 1:
            height = width
        elif len(size_bits) == 2:
            width = size_bits[0]
            height = size_bits[1]
        else:
            self.tell_pre(player, "Invalid size command.\n")
            return

        if not width.isdigit() or not height.isdigit():
            self.tell_pre(player, "You didn't even send numbers!\n")
            return

        w = int(width)
        h = int(height)

#.........这里部分代码省略.........
开发者ID:Cloudxtreme,项目名称:giles,代码行数:103,代码来源:redstone.py

示例9: Expeditions

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]

#.........这里部分代码省略.........
        # All right, we have a list of suits involved in this game.  Let's
        # build the various piles that are based on those suits.
        self.left.data.expeditions = []
        self.right.data.expeditions = []
        self.discards = []
        for suit in suit_list:
            discard_pile = Struct()
            left_expedition = Struct()
            right_expedition = Struct()
            for pile in (discard_pile, left_expedition, right_expedition):
                pile.suit = suit
                pile.hand = Hand()
                pile.value = 0
            self.left.data.expeditions.append(left_expedition)
            self.right.data.expeditions.append(right_expedition)
            self.discards.append(discard_pile)

        # We'll do a separate loop for generating the deck to minimize
        # confusion.
        self.draw_pile = Hand()
        for suit in suit_list:
            for rank in NUMERICAL_RANKS:
                self.draw_pile.add(ExpeditionsCard(rank, suit))

            # Add as many agreements as requested.
            for agreement in range(self.agreement_count):
                self.draw_pile.add(ExpeditionsCard(AGREEMENT, suit))

        # Lastly, shuffle the draw deck and initialize hands.
        self.draw_pile.shuffle()
        self.left.data.hand = Hand()
        self.right.data.hand = Hand()

    def get_discard_str(self, pos):

        discard_pile = self.discards[pos]
        if len(discard_pile.hand):
            return(value_to_str(discard_pile.hand[-1].value()))
        return "."

    def get_expedition_str(self, expedition):

        to_return = ""
        for card in expedition:
            to_return += value_to_str(card.value())

        return to_return

    def get_sp_str(self, seat):

        if seat == self.left:
            return "^C%s^~" % self.left.player_name
        else:
            return "^M%s^~" % self.right.player_name

    def update_printable_layout(self):

        self.printable_layout = []
        self.printable_layout.append("                   .---.\n")

        # Loop through all table rows.
        for row in range(self.suit_count):
            left = self.left.data.expeditions[row]
            right = self.right.data.expeditions[row]
            suit_char = left.suit[0].upper()
            left_suit_char = suit_char
开发者ID:sunfall,项目名称:giles,代码行数:70,代码来源:expeditions.py

示例10: FortyOne

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class FortyOne(SeatedGame):
    """An implementation of Forty-One, a quirky combination of solo and
    partnership trick-taking that is apparently popular in Syria.  The only
    real differences from the rules I've seen online are that this version
    supports a 'whist' mode rather than always having Hearts as trump and it
    forces play to continue if winning scores are tied.
    """

    def __init__(self, server, table_name):

        super(FortyOne, self).__init__(server, table_name)

        self.game_display_name = "Forty-One"
        self.game_name = "fortyone"

        # Seat ordering is "Persian."
        self.seats = [
            Seat("North"),
            Seat("West"),
            Seat("South"),
            Seat("East"),
        ]

        self.min_players = 4
        self.max_players = 4
        self.state = State("need_players")
        self.prefix = "(^RForty-One^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # 41-specific stuff.
        self.goal = 41
        self.double = 7
        self.minimum = 11
        self.whist = False
        self.positive = True
        self.trick = None
        self.trump_suit = None
        self.led_suit = None
        self.turn = None
        self.dealer = None
        self.winner = None

        self.north = self.seats[0]
        self.west = self.seats[1]
        self.south = self.seats[2]
        self.east = self.seats[3]

        self.north.data.who = NORTH
        self.west.data.who = WEST
        self.south.data.who = SOUTH
        self.east.data.who = EAST

        self.north.data.partner = self.south
        self.west.data.partner = self.east
        self.south.data.partner = self.north
        self.east.data.partner = self.west

        self.layout = FourPlayerCardGameLayout()

        # Set everyone's score to zero.
        for seat in self.seats:
            seat.data.score = 0

    def show_help(self, player):

        super(FortyOne, self).show_help(player)
        player.tell_cc("\nFORTY-ONE SETUP PHASE:\n\n")
        player.tell_cc("          ^!setup^., ^!config^., ^!conf^.     Enter setup phase.\n")
        player.tell_cc("            ^!goal^. <num>, ^!score^.     Set the goal score to <num>.\n")
        player.tell_cc("           ^!double^. <num>, ^!doub^.     Set the lowest doubling to <num>.\n")
        player.tell_cc("           ^!minimum^. <num>, ^!min^.     Set the minimum deal bid to <num>.\n")
        player.tell_cc("         ^!positive^. on|off, ^!pos^.     Require positive partners for wins.\n")
        player.tell_cc("             ^!whist^. on|off, ^!wh^.     Enable whist mode for trumps.\n")
        player.tell_cc("            ^!ready^., ^!done^., ^!r^., ^!d^.     End setup phase.\n")
        player.tell_cc("\nFORTY-ONE PLAY:\n\n")
        player.tell_cc("            ^!choose^. <suit>, ^!ch^.     Declare <suit> as trumps.  Hakem only.\n")
        player.tell_cc("                 ^!bid^. <num>, ^!b^.     Bid to win <num> tricks.\n")
        player.tell_cc("              ^!play^. <card>, ^!pl^.     Play <card> from your hand.\n")
        player.tell_cc("                 ^!hand^., ^!inv^., ^!i^.     Look at the cards in your hand.\n")

    def display(self, player):

        player.tell_cc("%s" % self.layout)

    def get_color_code(self, seat):
        if seat == self.north or seat == self.south:
            return "^R"
        else:
            return "^M"

    def get_sp_str(self, seat):

        return "^G%s^~ (%s%s^~)" % (seat.player_name, self.get_color_code(seat), seat)

    def get_player_num_str(self, seat, num):

        return "%s%s^~: %d" % (self.get_color_code(seat), seat.player_name, num)

    def get_score_str(self):
        return_str = "       "
#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:forty_one.py

示例11: Poison

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Poison(SeatedGame):
    """An implementation of 'Skull' by Herve Marly, without any of the
    gorgeous artwork, sadly.
    """

    def __init__(self, server, table_name):

        super(Poison, self).__init__(server, table_name)

        self.game_display_name = "Poison"
        self.game_name = "poison"
        self.seats = [
            Seat("Alpha"),
            Seat("Bravo"),
            Seat("Charlie"),
            Seat("Delta"),
            Seat("Echo"),
            Seat("Foxtrot"),
            Seat("Golf"),
            Seat("Hotel"),
            Seat("India"),
            Seat("Juliet")
        ]
        self.state = State("need_players")
        self.prefix = "(^RPoison^~) "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)
        self.min_players = 3
        self.max_players = 10

        # Default configuration.
        self.antidote_count = 3
        self.poison_count = 1
        self.goal = 2

        # Mutable information.
        self.turn = None
        self.highest_bidder = None

    def get_color_code(self, seat):
        color_index = self.seats.index(seat) % 4

        if color_index == 0:
            return "^R"
        elif color_index == 1:
            return "^Y"
        elif color_index == 2:
            return "^M"
        else:
            return "^C"

    def get_sp_str(self, seat):
        return "^G%s^~ (%s%s^~)" % (seat.player_name, self.get_color_code(seat), seat)

    def next_seat(self, seat, bidding=False):

        # Skip players that are dead and, if bidding, have passed.
        player_count = len(self.seats)
        index = self.seats.index(seat) % player_count
        done = False
        while not done:
            index = (index + 1) % player_count
            this_seat = self.seats[index]
            if not this_seat.data.is_dead:

                # Assume done.
                done = True

                # ...but if we're bidding, that might not be the case.
                if bidding and not this_seat.data.is_bidding:
                    done = False

        return self.seats[index]

    def prev_seat(self, seat):

        # This function is unused in the game, but the default prev_seat() is
        # misleading, so:
        return None

    def _count_live_players(self):
        return len([x for x in self.seats if not x.data.is_dead])

    def _count_racked_potions(self):

        count = 0
        for seat in self.seats:
            if not seat.data.is_dead:
                count += len(seat.data.potion_rack)

        return count

    def show(self, player):

        state = self.state.get()
        if state == "need_players":
            player.tell_cc("The game is not yet active.\n")
        else:
            for seat in self.seats:
                seat_str = "%s [^G%s^~, ^C%s^~]: " % (self.get_sp_str(seat), get_plural_str(seat.data.antidotes + seat.data.poisons, "potion"), get_plural_str(seat.data.score, "point"))
                if seat.data.is_dead:
#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:poison.py

示例12: CaptureGo

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class CaptureGo(SeatedGame):
    """A Capture Go game table implementation.  One-Capture Go was invented by
    Yasuda Yashutoshi.
    """

    def __init__(self, server, table_name):

        super(CaptureGo, self).__init__(server, table_name)

        self.game_display_name = "Capture Go"
        self.game_name = "capturego"
        self.seats = [
            Seat("Black"),
            Seat("White")
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RCapture Go^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Capture Go-specific stuff.
        self.turn = None
        self.seats[0].data.side = BLACK
        self.seats[1].data.side = WHITE
        self.seats[0].data.capture_list = []
        self.seats[1].data.capture_list = []
        self.capture_goal = 1
        self.resigner = None
        self.turn_number = 0
        self.goban = giles.games.goban.Goban()

    def show(self, player):

        if not self.goban.printable_board:
            self.goban.update_printable_board()
        for line in self.goban.printable_board:
            player.tell_cc(line)
        player.tell_cc(self.get_supplemental_str())

    def send_board(self):

        for player in self.channel.listeners:
            self.show(player)

    def get_stone_str(self, count):

        if count == 1:
            return "1 stone"
        return "%d stones" % count

    def get_supplemental_str(self):

        if not self.turn:
            return ("The game has not yet started.\n")

        if self.turn == BLACK:
            player = self.seats[0].player_name
            color_msg = "^KBlack^~"
        else:
            player = self.seats[1].player_name
            color_msg = "^WWhite^~"

        to_return = "It is ^Y%s^~'s turn (%s).\n" % (player, color_msg)
        to_return += "^KBlack^~ has captured %s. ^WWhite^~ has captured %s.\n" % (self.get_stone_str(len(self.seats[0].data.capture_list)), self.get_stone_str(len(self.seats[1].data.capture_list)))
        to_return += ("The goal is to capture %s.\n" % self.get_stone_str(self.capture_goal))
        return(to_return)

    def tick(self):

        # If both seats are full and the game is active, autostart.
        if (self.state.get() == "need_players" and self.seats[0].player
           and self.seats[1].player and self.active):
            self.state.set("playing")
            self.channel.broadcast_cc(self.prefix + "^KBlack^~: ^R%s^~; ^WWhite^~: ^Y%s^~\n" %
               (self.seats[0].player, self.seats[1].player))
            self.turn = BLACK
            self.turn_number = 1
            self.send_board()

    def set_size(self, player, size_bits):

        # Is there an 'x' in the middle of a single argument?
        if len(size_bits) == 1:
            size_bits[0] = size_bits[0].lower()
            if "x" in size_bits[0]:
                size_bits = size_bits[0].split("x")

        width = size_bits[0]
        # If there's a single element, height == width.
        if len(size_bits) == 1:
            height = width
        elif len(size_bits) == 2:
            width = size_bits[0]
            height = size_bits[1]
        else:
            player.tell_cc(self.prefix + "Invalid size command.\n")
            return

        if not width.isdigit() or not height.isdigit():
#.........这里部分代码省略.........
开发者ID:Cloudxtreme,项目名称:giles,代码行数:103,代码来源:capture_go.py

示例13: Tanbo

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]
class Tanbo(SeatedGame):
    """A Tanbo game table implementation.  Invented in 1993 by Mark Steere.
    This only implements the 2p version, although it does have the 9x9, 13x13,
    and 19x19 sizes.  There's also a 21x21 size that came from discussion with
    Mark, and 5x5 and 7x7 sizes that came naturally from the piece layouts.
    """

    def __init__(self, server, table_name):

        super(Tanbo, self).__init__(server, table_name)

        self.game_display_name = "Tanbo"
        self.game_name = "tanbo"
        self.seats = [
            Seat("Black"),
            Seat("White"),
        ]
        self.min_players = 2
        self.max_players = 2
        self.state = State("need_players")
        self.prefix = "(^RTanbo^~): "
        self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)

        # Tanbo-specific stuff.
        self.size = 19
        self.turn = None
        self.black = self.seats[0]
        self.black.data.seat_str = "^KBlack^~"
        self.black.data.root_list = []
        self.white = self.seats[1]
        self.white.data.seat_str = "^WWhite^~"
        self.white.data.root_list = []
        self.resigner = None
        self.layout = None

        # Initialize the starting layout.
        self.init_layout()

    def get_root_piece(self, seat, num):
        if seat == self.black:
            p = Piece("^K", "x", "X")
        else:
            p = Piece("^W", "o", "O")

        p.data.owner = seat
        p.data.num = num
        return p

    def init_layout(self):

        # Create the layout and fill it with pieces.
        self.layout = SquareGridLayout(highlight_color="^I")
        self.layout.resize(self.size)

        black_count = 0
        white_count = 0
        self.black.data.root_list = []
        self.white.data.root_list = []

        # There are three different layouts depending on the size.  All of them
        # alternate between black and white pieces; the two larger ones have 16
        # roots, whereas the smallest size has 4.  (There's a 5x5 grid for
        # testing as well.)
        if self.size == 5:
            jump_delta = 4
            extent = 2
            offset = 0
        elif self.size == 7:
            jump_delta = 6
            extent = 2
            offset = 0
        elif self.size == 9:
            jump_delta = 6
            extent = 2
            offset = 1
        elif self.size == 13:
            jump_delta = 4
            extent = 4
            offset = 0
        elif self.size == 19:
            jump_delta = 6
            extent = 4
            offset = 0
        else: # size == 21
            jump_delta = 4
            extent = 6
            offset = 0
        for i in range(extent):
            for j in range(extent):
                if (i + j) % 2:
                    p = self.get_root_piece(self.black, black_count)
                    self.black.data.root_list.append(p)
                    black_count += 1
                else:
                    p = self.get_root_piece(self.white, white_count)
                    self.white.data.root_list.append(p)
                    white_count += 1
                row = offset + i * jump_delta
                col = offset + j * jump_delta
                p.data.start = (row, col)
#.........这里部分代码省略.........
开发者ID:sunfall,项目名称:giles,代码行数:103,代码来源:tanbo.py

示例14: Y

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]

#.........这里部分代码省略.........
        for x in range(self.size):
            msg = " "
            color_char = "^W"
            if x % 2 == 0:
                color_char = "^K"
            slash_line += color_char + "/^~ "
            char_line += "%s " % COL_CHARACTERS[x]
            for spc in range(self.size - x):
                msg += " "
            for y in range(x + 1):
                piece = self.board[y][x]
                if (y, x) in self.last_moves:
                    msg += "^5"
                if piece == BLACK:
                    msg += "^Kx^~ "
                elif piece == WHITE:
                    msg += "^Wo^~ "
                elif y % 2 == 0:
                    msg += "^m,^~ "
                else:
                    msg += "^M.^~ "
            msg += "- " + str(x + 1) + "\n"
            self.printable_board.append(msg)
        self.printable_board.append(slash_line + "\n")
        self.printable_board.append(char_line + "\n")

    def print_board(self, player):

        if not self.printable_board:
            self.update_printable_board()
        for line in self.printable_board:
            player.tell_cc(line)

    def get_turn_str(self):
        if self.state.get() == "playing":
            if self.seats[0].data.color == self.turn:
                color_word = "^WWhite^~"
                name_word = "^R%s^~" % self.seats[0].player_name
            else:
                color_word = "^KBlack^~"
                name_word = "^Y%s^~" % self.seats[1].player_name
            return "It is %s's turn (%s).\n" % (name_word, color_word)
        else:
            return "The game is not currently active.\n"

    def send_board(self):

        for player in self.channel.listeners:
            self.print_board(player)

    def resign(self, seat):

        # Okay, this person can resign; it's their turn, after all.
        self.channel.broadcast_cc(self.prefix + "^R%s^~ is resigning from the game.\n" % seat.player_name)
        self.resigner = seat.data.color
        return True

    def show(self, player):
        self.print_board(player)
        player.tell_cc(self.get_turn_str())

    def show_help(self, player):

        super(Y, self).show_help(player)
        player.tell_cc("\nY SETUP PHASE:\n\n")
        player.tell_cc("          ^!setup^., ^!config^., ^!conf^.     Enter setup phase.\n")
开发者ID:Cloudxtreme,项目名称:giles,代码行数:70,代码来源:y.py

示例15: Hokm

# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import get [as 别名]

#.........这里部分代码省略.........

            self.west = self.seats[0]
            self.south = self.seats[1]
            self.east = self.seats[2]
            self.west.data.score = 0
            self.south.data.score = 0
            self.east.data.score = 0

            self.min_players = 3
            self.max_players = 3
            self.layout = ThreePlayerCardGameLayout()

        else:
            self.log_pre("MAJOR ERROR: Hokm initialization with invalid mode %s!" % self.mode)

    def show_help(self, player):

        super(Hokm, self).show_help(player)
        player.tell_cc("\nHOKM SETUP PHASE:\n\n")
        player.tell_cc("          ^!setup^., ^!config^., ^!conf^.     Enter setup phase.\n")
        player.tell_cc("            ^!goal^. <num>, ^!score^.     Set the goal score to <num>.\n")
        player.tell_cc("              ^!players^. 3|4, ^!pl^.     Set the number of players.\n")
        player.tell_cc("             ^!short^. on|off, ^!sh^.     Use a short deck (3p only).\n")
        player.tell_cc("            ^!ready^., ^!done^., ^!r^., ^!d^.     End setup phase.\n")
        player.tell_cc("\nHOKM PLAY:\n\n")
        player.tell_cc("            ^!choose^. <suit>, ^!ch^.     Declare <suit> as trumps.  Hakem only.\n")
        player.tell_cc("              ^!play^. <card>, ^!pl^.     Play <card> from your hand.\n")
        player.tell_cc("                 ^!hand^., ^!inv^., ^!i^.     Look at the cards in your hand.\n")

    def display(self, player):

        player.tell_cc("%s" % self.layout)

    def get_color_code(self, seat):
        if self.mode == 4:
            if seat == self.seats[0] or seat == self.seats[2]:
                return "^R"
            else:
                return "^M"
        else:
            if seat == self.west:
                return "^M"
            elif seat == self.south:
                return "^R"
            else:
                return "^B"

    def get_sp_str(self, seat):

        return "^G%s^~ (%s%s^~)" % (seat.player_name, self.get_color_code(seat), seat)

    def get_score_str(self):
        if self.mode == 4:
            return "          ^RNorth/South^~: %d    ^MEast/West^~: %d\n" % (self.ns.score, self.ew.score)
        else:
            return "          ^M%s^~: %d    ^R%s^~: %d    ^B%s^~: %d\n" % (self.west.player_name, self.west.data.score, self.south.player_name, self.south.data.score, self.east.player_name, self.east.data.score)

    def get_metadata(self):

        to_return = "\n\n"
        if self.turn:
            seat_color = self.get_color_code(self.turn)
            to_return += "%s is the hakem.\n" % (self.get_sp_str(self.hakem))
            if self.trump_suit:
                trump_str = "^C%s^~" % self.trump_suit
            else:
开发者ID:Cloudxtreme,项目名称:giles,代码行数:70,代码来源:hokm.py


注:本文中的giles.state.State.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。