本文整理汇总了Python中giles.state.State.set方法的典型用法代码示例。如果您正苦于以下问题:Python State.set方法的具体用法?Python State.set怎么用?Python State.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类giles.state.State
的用法示例。
在下文中一共展示了State.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Talpa
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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:
#.........这里部分代码省略.........
示例2: Breakthrough
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
#.........这里部分代码省略.........
# Okay, this is actually (gasp) a potentially legitimate move. If
# it's a move forward, it only works if the forward space is empty.
if src_c == dst_c and self.layout.grid[dst_r][dst_c]:
self.tell_pre(player, "A straight-forward move can only be into an empty space.\n")
return False
# Otherwise, it must not have one of the player's own pieces in it.
dst_loc = self.layout.grid[dst_r][dst_c]
if src_loc == dst_loc:
self.tell_pre(player, "A diagonal-forward move cannot be onto your own piece.\n")
return False
additional_str = ""
opponent = self.seats[0]
if seat == self.seats[0]:
opponent = self.seats[1]
if dst_loc:
# It's a capture.
additional_str = ", capturing one of ^R%s^~'s pieces" % (opponent.player)
opponent.data.piece_count -= 1
self.bc_pre("^Y%s^~ moves a piece from ^C%s^~ to ^G%s^~%s.\n" % (seat.player, src_str, dst_str, additional_str))
# Make the move on the layout.
self.layout.move(src_r, src_c, dst_r, dst_c, True)
return ((src_r, src_c), (dst_r, dst_c))
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.bc_pre("^KBlack^~: ^R%s^~; ^WWhite^~: ^Y%s^~\n" %
(self.seats[0].player, self.seats[1].player))
self.turn = self.black
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:
self.tell_pre(player, "Invalid size command.\n")
return
if not width.isdigit() or not height.isdigit():
self.tell_pre(player, "Invalid size command.\n")
return
w = int(width)
h = int(height)
if w < MIN_WIDTH or w > MAX_WIDTH:
示例3: Crossway
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
#.........这里部分代码省略.........
col, row = play
# Make sure they're all in range.
if not self.is_valid(row, col):
player.tell_cc(self.prefix + "Your move is out of bounds.\n")
return False
# Is the space empty?
if self.board[row][col]:
player.tell_cc(self.prefix + "That space is already occupied.\n")
return False
# Does the move violate the no-checkerboard rule?
if self.is_checkerboard(self.turn, row, col):
player.tell_cc(self.prefix + "That move creates a checkerboard.\n")
return False
# This is a valid move. Apply, announce.
self.board[row][col] = self.turn
play_str = "%s%s" % (COLS[col], row + 1)
self.channel.broadcast_cc(self.prefix + "^Y%s^~ places a piece at ^C%s^~.\n" % (seat.player, play_str))
self.last_r = row
self.last_c = col
self.turn_number += 1
return True
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/Vertical^~: ^R%s^~; ^WWhite/Horizontal^~: ^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):
if not size_bits.isdigit():
player.tell_cc(self.prefix + "Invalid size command.\n")
return
size = int(size_bits)
if size < MIN_SIZE or size > MAX_SIZE:
player.tell_cc(self.prefix + "Size must be between %d and %d inclusive.\n" % (MIN_SIZE, MAX_SIZE))
return
# Valid!
self.size = size
self.channel.broadcast_cc(self.prefix + "^R%s^~ has set the board size to ^C%d^~.\n" % (player, size))
self.init_board()
self.update_printable_board()
def resign(self, player):
seat = self.get_seat_of_player(player)
if not seat:
player.tell_cc(self.prefix + "You can't resign; you're not playing!\n")
return False
if self.turn != seat.data.side:
示例4: RockPaperScissors
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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
#.........这里部分代码省略.........
示例5: Ataxx
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
#.........这里部分代码省略.........
if not self.color_has_move(RED) or not self.color_has_move(BLUE):
player.tell_cc(self.prefix + "Players must have a valid move.\n")
self.board[row][col] = thing_there
return
loc_list = [(row, col)]
edge = self.size - 1
# In either mode, we place another pit across the center line,
# but not if that's the same location as the one we just placed
# (on the center line on odd-sized boards).
if (edge - row) != row:
self.board[edge - row][col] = new_thing
loc_list.append((edge - row, col))
# Handle the 4p down-reflection if necessary.
if self.player_mode == 4 and (edge - col) != col:
self.board[edge - row][edge - col] = new_thing
loc_list.append((edge - row, edge - col))
# Handle the 4p right-reflection if necessary.
if self.player_mode == 4 and (edge - col) != col:
self.board[row][edge - col] = new_thing
loc_list.append((row, edge - col))
# Generate the list of locations.
loc_str = ", ".join(["^C%s^~" % self.loc_to_str(x[0], x[1]) for x in loc_list])
# Finally, send the string detailing what just happened.
self.channel.broadcast_cc(self.prefix + "^Y%s^~ has %s a pit at: %s\n" % (player, action_str, loc_str))
self.update_printable_board()
def set_size(self, player, size_bits):
if not size_bits.isdigit():
player.tell_cc(self.prefix + "Invalid size command.\n")
return
size = int(size_bits)
if size < MIN_SIZE or size > MAX_SIZE:
player.tell_cc(self.prefix + "Size must be between %d and %d inclusive.\n" % (MIN_SIZE, MAX_SIZE))
return
# Valid!
self.size = size
self.channel.broadcast_cc(self.prefix + "^R%s^~ has set the board size to ^C%d^~.\n" % (player, size))
self.init_board()
self.update_printable_board()
def set_player_mode(self, player, mode_bits):
if not mode_bits.isdigit():
player.tell_cc(self.prefix + "Invalid player mode command.\n")
return
mode = int(mode_bits)
if mode != 2 and mode != 4:
player.tell_cc(self.prefix + "This game only supports two or four players.\n")
return
elif mode == self.player_mode:
player.tell_cc(self.prefix + "This table is already in that mode.\n")
return
示例6: Metamorphosis
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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:
#.........这里部分代码省略.........
示例7: Hex
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
class Hex(SeatedGame):
"""A Hex game table implementation. Invented independently by Piet
Hien and John Nash. Adapted from both my Giles Y implementation and
my Volity Hex implementation.
"""
def __init__(self, server, table_name):
super(Hex, self).__init__(server, table_name)
self.game_display_name = "Hex"
self.game_name = "hex"
self.seats = [
Seat("White"),
Seat("Black"),
]
self.min_players = 2
self.max_players = 2
self.state = State("need_players")
self.prefix = "(^RHex^~): "
self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)
# Hex-specific guff.
self.seats[0].data.color = WHITE
self.seats[0].data.color_code = "^W"
self.seats[1].data.color = BLACK
self.seats[1].data.color_code = "^K"
self.board = None
self.printable_board = None
self.size = 14
self.turn = None
self.turn_number = 0
self.move_list = []
self.resigner = None
self.last_x = None
self.last_y = None
self.is_quickstart = False
self.adjacency = None
self.found_winner = False
# Hex requires both seats, so may as well mark them active.
self.seats[0].active = True
self.seats[1].active = True
self.init_board()
def init_board(self):
self.board = []
for x in range(self.size):
self.board.append([None] * self.size)
def set_size(self, player, size_str):
if not size_str.isdigit():
player.tell_cc(self.prefix + "You didn't even send a number!\n")
return False
new_size = int(size_str)
if new_size < HEX_MIN_SIZE or new_size > HEX_MAX_SIZE:
player.tell_cc(self.prefix + "Too small or large. Must be %s to %s inclusive.\n" % (HEX_MIN_SIZE, HEX_MAX_SIZE))
return False
# Got a valid size.
self.size = new_size
self.init_board()
self.update_printable_board()
self.channel.broadcast_cc(self.prefix + "^M%s^~ has changed the size of the board to ^C%s^~.\n" % (player, str(new_size)))
return True
def move(self, seat, move):
x, y = move
move_str = "%s%s" % (COL_CHARACTERS[x], y + 1)
# Check bounds.
if (x < 0 or x >= self.size or y < 0 or y >= self.size):
seat.player.tell_cc(self.prefix + "That move is out of bounds.\n")
return None
if self.board[x][y]:
seat.player.tell_cc(self.prefix + "That space is already occupied.\n")
return None
# Okay, it's an unoccupied space! Let's make the move.
self.board[x][y] = seat.data.color
self.channel.broadcast_cc(self.prefix + seat.data.color_code + "%s^~ has moved to ^C%s^~.\n" % (seat.player_name, move_str))
self.last_x = x
self.last_y = y
return (x, y)
def swap(self):
# In Hex, to get the equivalent piece for the other player, it
# must be swapped along the x = y axis. That is, x <-> y for
# the piece. Easy enough!
self.board[self.move_list[0][0]][self.move_list[0][1]] = None
self.board[self.move_list[0][1]][self.move_list[0][0]] = BLACK
self.last_x, self.last_y = self.last_y, self.last_x
#.........这里部分代码省略.........
示例8: Redstone
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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)
#.........这里部分代码省略.........
示例9: Expeditions
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
#.........这里部分代码省略.........
print_str += hand_to_str(seat.data.hand)
print_str += "\n"
self.tell_pre(player, print_str)
def send_layout(self, show_metadata=True):
for player in self.channel.listeners:
self.show(player, show_metadata)
for seat in self.seats:
if seat.player:
self.show_hand(seat.player)
def deal(self):
# Deal cards until each player has hand_size cards.
self.bc_pre("A fresh hand is dealt to both players.\n")
for i in range(self.hand_size):
self.left.data.hand.add(self.draw_pile.discard())
self.right.data.hand.add(self.draw_pile.discard())
# Sort hands.
self.left.data.hand = sorted_hand(self.left.data.hand)
self.right.data.hand = sorted_hand(self.right.data.hand)
# Clear scores.
self.left.data.curr_score = 0
self.right.data.curr_score = 0
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.state.set_sub("play")
self.bc_pre("^CLeft^~: ^Y%s^~; ^MRight^~: ^Y%s^~\n" %
(self.left.player_name, self.right.player_name))
self.turn = self.left
self.first_player = self.left
self.deal()
self.send_layout()
def calculate_deck_size(self, suits, agrees):
# Eventually this will depend on just what cards are in the deck,
# but for now there are 9 point cards per suit plus the agreements.
return (9 + agrees) * suits
def set_suits(self, player, suit_str):
if not suit_str.isdigit():
self.tell_pre(player, "You didn't even send a number!\n")
return False
new_suit_count = int(suit_str)
if new_suit_count < MIN_SUITS or new_suit_count > MAX_SUITS:
self.tell_pre(player, "The number of suits must be between %d and %d inclusive.\n" % (MIN_SUITS, MAX_SUITS))
return False
# Does this give too few cards for the hand size?
if self.calculate_deck_size(new_suit_count, self.agreement_count) <= self.hand_size * 2:
self.tell_pre(player, "That number of suits is too small for the hand size.\n")
return False
# Valid.
self.suit_count = new_suit_count
示例10: FortyOne
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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 = " "
#.........这里部分代码省略.........
示例11: Poison
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
#.........这里部分代码省略.........
seat_str += " ^C[choosing]^~"
elif state == "bidding":
seat_str += " ^Y[bidding]^~"
elif state == "quaffing":
seat_str += " ^R[quaffing]^~"
elif state == "bidding":
if seat.data.is_bidding == False:
seat_str += " ^M[passed]^~"
elif seat.data.bid:
seat_str += " [bid ^G%d^~]" % seat.data.bid
player.tell_cc("%s\n" % seat_str)
player.tell_cc("\nThe racks currently hold ^G%s^~.\n" % get_plural_str(self._count_racked_potions(), "potion"))
player.tell_cc("\n\nThe goal score for this game is ^C%s^~.\n" % get_plural_str(self.goal, "point"))
def winnow_seats(self):
# Peels off seats that aren't actually being used once the game starts.
self.seats = [x for x in self.seats if x.player]
def new_round(self, starting_seat):
# Initialize the values that reset per-round.
for seat in self.seats:
seat.data.is_bidding = True
seat.data.bid = 0
seat.data.quaffed = 0
seat.data.potion_rack = []
self.turn = starting_seat
# Shift to initial placement mode.
self.bc_pre("Players, place your initial potions.\n")
self.state.set("initial_placement")
def start_game(self):
# Configure all necessary data once a game starts.
self.winnow_seats()
for seat in self.seats:
seat.data.is_dead = False
seat.data.score = 0
seat.data.antidotes = self.antidote_count
seat.data.poisons = self.poison_count
# Pick a random starting player.
first_player = random.choice(self.seats)
self.bc_pre("Fate has chosen, and the starting player is %s!\n" % self.get_sp_str(first_player))
self.new_round(first_player)
def set_antidote_count(self, player, antidote_str):
if not antidote_str.isdigit():
self.tell_pre(player, "You didn't even send a number!\n")
return False
new_count = int(antidote_str)
if new_count < MIN_ANTIDOTE_COUNT or new_count > MAX_ANTIDOTE_COUNT:
self.tell_pre(player, "Too small or large. Must be %s to %s inclusive.\n" % (MIN_ANTIDOTE_COUNT, MAX_ANTIDOTE_COUNT))
return False
# Valid choice.
self.antidote_count = new_count
self.channel.broadcast_cc(self.prefix + "^M%s^~ has changed the antidote count to ^C%s^~.\n" % (player, str(new_count)))
return True
示例12: CaptureGo
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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():
#.........这里部分代码省略.........
示例13: Tanbo
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [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)
#.........这里部分代码省略.........
示例14: Y
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
class Y(SeatedGame):
"""A Y game table implementation. Invented by Claude Shannon.
Adapted from my Volity implementation.
"""
def __init__(self, server, table_name):
super(Y, self).__init__(server, table_name)
self.game_display_name = "Y"
self.game_name = "y"
self.seats = [
Seat("White"),
Seat("Black"),
]
self.min_players = 2
self.max_players = 2
self.state = State("need_players")
self.prefix = "(^RY^~): "
self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)
# Y-specific guff.
self.seats[0].data.color = WHITE
self.seats[0].data.color_code = "^W"
self.seats[1].data.color = BLACK
self.seats[1].data.color_code = "^K"
self.board = None
self.printable_board = None
self.size = 19
self.empty_space_count = None
self.master = False
self.turn = None
self.turn_number = 0
self.move_list = []
self.last_moves = []
self.resigner = None
self.adjacency = None
self.found_winner = False
# Y requires both seats, so may as well mark them active.
self.seats[0].active = True
self.seats[1].active = True
self.init_board()
def init_board(self):
self.board = []
self.empty_space_count = 0
# We're going to be lazy and build a square board, then fill the
# half that doesn't make the proper shape with invalid marks.
# The number of empty spaces on a Y board is equal to the sizeth
# triangular number; we abuse that to get the right empty space
# count while we're at it.
for x in range(self.size):
self.board.append([None] * self.size)
self.empty_space_count += x + 1
# Looking at the grid above, you can see that for a given column,
# all row values less than that value are invalid.
for y in range(x):
self.board[x][y] = INVALID
# That's it!
def set_size(self, player, size_str):
if not size_str.isdigit():
player.tell_cc(self.prefix + "You didn't even send a number!\n")
return False
new_size = int(size_str)
if new_size < Y_MIN_SIZE or new_size > Y_MAX_SIZE:
player.tell_cc(self.prefix + "Too small or large. Must be %s to %s inclusive.\n" % (Y_MIN_SIZE, Y_MAX_SIZE))
return False
# Got a valid size.
self.size = new_size
self.init_board()
self.update_printable_board()
self.channel.broadcast_cc(self.prefix + "^M%s^~ has changed the size of the board to ^C%s^~.\n" % (player, str(new_size)))
return True
def set_master(self, player, master_str):
master_bool = booleanize(master_str)
if master_bool:
if master_bool > 0:
self.master = True
display_str = "^Con^~"
else:
self.master = False
display_str = "^coff^~"
self.channel.broadcast_cc(self.prefix + "^R%s^~ has turned ^GMaster Y^~ mode %s.\n" % (player, display_str))
else:
player.tell_cc(self.prefix + "Not a valid boolean!\n")
def move(self, seat, move_list):
#.........这里部分代码省略.........
示例15: Hokm
# 需要导入模块: from giles.state import State [as 别名]
# 或者: from giles.state.State import set [as 别名]
class Hokm(SeatedGame):
"""A Hokm game table implementation. Hokm is a Persian trick-taking
card game of unknown provenance. This implementation doesn't
currently rearrange the seats at the start, but does support both the
standard 4p partnership game and the quirky 3p mode. In addition, 3p
mode can use both a short deck (13 cards per hand) or a long deck (17).
"""
def __init__(self, server, table_name):
super(Hokm, self).__init__(server, table_name)
self.game_display_name = "Hokm"
self.game_name = "hokm"
self.state = State("need_players")
self.prefix = "(^RHokm^~): "
self.log_prefix = "%s/%s: " % (self.table_display_name, self.game_display_name)
# Hokm-specific stuff.
self.goal = 7
self.trick = None
self.trump_suit = None
self.led_suit = None
self.turn = None
self.dealer = None
self.hakem = None
self.winner = None
# Default to four-player mode.
self.mode = 4
self.short = True
self.setup_mode()
def setup_mode(self):
# Sets up all of the structures that depend on the mode of Hokm
# we're playing: seats, layouts, and (in 4p mode) partnerships.
# Remember that seats in Hokm go the opposite direction of the
# American/European standard.
if self.mode == 4:
self.seats = [
Seat("North"),
Seat("West"),
Seat("South"),
Seat("East"),
]
self.seats[0].data.who = NORTH
self.seats[1].data.who = WEST
self.seats[2].data.who = SOUTH
self.seats[3].data.who = EAST
self.min_players = 4
self.max_players = 4
self.layout = FourPlayerCardGameLayout()
# Set up the partnership structures.
self.ns = Struct()
self.ew = Struct()
self.ns.score = 0
self.ew.score = 0
elif self.mode == 3:
self.seats = [
Seat("West"),
Seat("South"),
Seat("East"),
]
self.seats[0].data.who = WEST
self.seats[1].data.who = SOUTH
self.seats[2].data.who = EAST
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")
#.........这里部分代码省略.........