예제 #1
0
    def play_road_builder(self, edge1, edge2):
        self.catanlog.log_plays_road_builder(
            self.get_cur_player(), hexgrid.location(hexgrid.EDGE, edge1),
            hexgrid.location(hexgrid.EDGE, edge2))
        print(self.get_cur_player().name, 'plays a Road Builder')

        self.set_dev_card_state(catan.states.DevCardPlayedState(self))
        self.dev_hands[self.get_cur_player()].remove('Road Builder')
예제 #2
0
파일: catanlog.py 프로젝트: UIKit0/catanlog
 def log_player_plays_dev_road_builder(self, player, edge1, edge2):
     """
     syntax: $color plays dev card: road builder, builds at $location and $location
     """
     location1 = hexgrid.location(hexgrid.EDGE, edge1)
     location2 = hexgrid.location(hexgrid.EDGE, edge2)
     self.logln('{0} plays dev card: road builder, builds at {1} and {2}'.format(
         player.color,
         location1,
         location2
     ))
예제 #3
0
 def steal(self, victim):
     self.game.catanlog.log_plays_knight(
         self.game.get_cur_player(),
         hexgrid.location(hexgrid.TILE, self.game.robber_tile),
         victim
     )
     self.game.set_state(GameStateDuringTurnAfterRoll(self.game))
예제 #4
0
 def steal(self, victim):
     self.game.catanlog.log_plays_knight(
         self.game.get_cur_player(),
         hexgrid.location(hexgrid.TILE, self.game.robber_tile),
         victim
     )
     self.game.set_state(GameStateDuringTurnAfterRoll(self.game))
예제 #5
0
파일: game.py 프로젝트: kvudata/catan-py
 def buy_city(self, node):
     #self.assert_legal_city(node)
     piece = catan.pieces.Piece(catan.pieces.PieceType.city,
                                self.get_cur_player())
     self.board.place_piece(piece, node)
     self.catanlog.log_buys_city(self.get_cur_player(),
                                 hexgrid.location(hexgrid.NODE, node))
     self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #6
0
파일: catanlog.py 프로젝트: UIKit0/catanlog
 def log_player_buys_city(self, player, node):
     """
     syntax: $color buys city, builds at $location
     """
     location = hexgrid.location(hexgrid.NODE, node)
     self.logln('{0} buys city, builds at {1}'.format(
         player.color,
         location
     ))
예제 #7
0
파일: catanlog.py 프로젝트: UIKit0/catanlog
 def log_player_buys_road(self, player, edge):
     """
     syntax: $color buys road, builds at $location
     """
     location = hexgrid.location(hexgrid.EDGE, edge)
     self.logln('{0} buys road, builds at {1}'.format(
         player.color,
         location
     ))
예제 #8
0
파일: game.py 프로젝트: rosshamish/catan-py
 def buy_settlement(self, node):
     # self.assert_legal_settlement(node)
     piece = catan.pieces.Piece(catan.pieces.PieceType.settlement, self.get_cur_player())
     self.board.place_piece(piece, node)
     self.catanlog.log_buys_settlement(self.get_cur_player(), hexgrid.location(hexgrid.NODE, node))
     if self.state.is_in_pregame():
         self.set_state(catan.states.GameStatePreGamePlacingPiece(self, catan.pieces.PieceType.road))
     else:
         self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #9
0
파일: game.py 프로젝트: rosshamish/catan-py
 def buy_road(self, edge):
     # self.assert_legal_road(edge)
     piece = catan.pieces.Piece(catan.pieces.PieceType.road, self.get_cur_player())
     self.board.place_piece(piece, edge)
     self.catanlog.log_buys_road(self.get_cur_player(), hexgrid.location(hexgrid.EDGE, edge))
     if self.state.is_in_pregame():
         self.end_turn()
     else:
         self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #10
0
파일: game.py 프로젝트: kvudata/catan-py
 def buy_road(self, edge):
     #self.assert_legal_road(edge)
     piece = catan.pieces.Piece(catan.pieces.PieceType.road,
                                self.get_cur_player())
     self.board.place_piece(piece, edge)
     self.catanlog.log_buys_road(self.get_cur_player(),
                                 hexgrid.location(hexgrid.EDGE, edge))
     if self.state.is_in_pregame():
         self.end_turn()
     else:
         self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #11
0
파일: game.py 프로젝트: kvudata/catan-py
 def buy_settlement(self, node):
     #self.assert_legal_settlement(node)
     piece = catan.pieces.Piece(catan.pieces.PieceType.settlement,
                                self.get_cur_player())
     self.board.place_piece(piece, node)
     self.catanlog.log_buys_settlement(self.get_cur_player(),
                                       hexgrid.location(hexgrid.NODE, node))
     if self.state.is_in_pregame():
         self.set_state(
             catan.states.GameStatePreGamePlacingPiece(
                 self, catan.pieces.PieceType.road))
     else:
         self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #12
0
    def buy_city(self, node):
        # print('\nGame\'s buy_city method called with node={}\n'.format(node))
        #self.assert_legal_city(node)
        piece = catan.pieces.Piece(catan.pieces.PieceType.city,
                                   self.get_cur_player())
        self.board.place_piece(piece, node)

        # self.resources_owned[self._cur_player].append()
        # self.pregame_coords[self._cur_player].append()

        self.catanlog.log_buys_city(self.get_cur_player(),
                                    hexgrid.location(hexgrid.NODE, node))
        self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #13
0
 def steal(self, victim):
     self.game.catanlog.log_plays_knight(
         self.game.get_cur_player(),
         hexgrid.location(hexgrid.TILE, self.game.robber_tile), victim)
     try:
         card = random.choice(self.game.hands[victim])
         self.game.hands[victim].remove(card)
         self.game.hands[self.game.get_cur_player()].append(card)
         print(self.game.get_cur_player().name, 'steals a', card, 'from',
               victim.name)
     except IndexError:
         print('no cards to steal from', victim.name)
     except KeyError:
         print('no victim')
     self.game.set_state(GameStateDuringTurnAfterRoll(self.game))
예제 #14
0
    def buy_settlement(self, node):
        print('\nGame\'s buy_settlement method called with node={}\n'.format(
            node))
        #self.assert_legal_settlement(node)
        piece = catan.pieces.Piece(catan.pieces.PieceType.settlement,
                                   self.get_cur_player())
        # print('piece = {0} = catan.pieces.Piece({1}, {2})'.format(piece, catan.pieces.PieceType.settlement, self.get_cur_player()))
        # print('calling self.board.place_piece(piece={0}, node={1}'.format(piece, node))

        self.board.place_piece(piece, node)
        self.catanlog.log_buys_settlement(self.get_cur_player(),
                                          hexgrid.location(hexgrid.NODE, node))

        if self.state.is_in_pregame():
            self.set_state(
                catan.states.GameStatePreGamePlacingPiece(
                    self, catan.pieces.PieceType.road))
        else:
            self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))
예제 #15
0
def tiles_touching_node(node):
    """
    Get tile IDs touching a node coord, node is type str.
    Ex:
    >>> tiles_touching_node('(2 SW)')
    >>> [2, 3]
    """

    # Get node coord from the node string representation
    map_node_fmt2coord = {
        hexgrid.location(hexgrid.NODE, n_coord): n_coord
        for n_coord in hexgrid.legal_node_coords()
    }
    node_coord = map_node_fmt2coord[node]

    # map node to tile coordinates
    map_node2tile = defaultdict(list)
    for t in hexgrid.legal_tile_ids():
        nodes = hexgrid.nodes_touching_tile(t)
        for n in nodes:
            map_node2tile[n].append(t)

    return map_node2tile[node_coord]
예제 #16
0
파일: game.py 프로젝트: kvudata/catan-py
 def play_road_builder(self, edge1, edge2):
     self.catanlog.log_plays_road_builder(
         self.get_cur_player(), hexgrid.location(hexgrid.EDGE, edge1),
         hexgrid.location(hexgrid.EDGE, edge2))
     self.set_dev_card_state(catan.states.DevCardPlayedState(self))
예제 #17
0
 def play_road_builder(self, edge1, edge2):
     # print('\nGame\'s play_road_builder method called\n')
     self.catanlog.log_plays_road_builder(
         self.get_cur_player(), hexgrid.location(hexgrid.EDGE, edge1),
         hexgrid.location(hexgrid.EDGE, edge2))
     self.set_dev_card_state(catan.states.DevCardPlayedState(self))
예제 #18
0
파일: game.py 프로젝트: rosshamish/catan-py
 def play_road_builder(self, edge1, edge2):
     self.catanlog.log_plays_road_builder(
         self.get_cur_player(), hexgrid.location(hexgrid.EDGE, edge1), hexgrid.location(hexgrid.EDGE, edge2)
     )
     self.set_dev_card_state(catan.states.DevCardPlayedState(self))
예제 #19
0
파일: game.py 프로젝트: rosshamish/catan-py
 def buy_city(self, node):
     # self.assert_legal_city(node)
     piece = catan.pieces.Piece(catan.pieces.PieceType.city, self.get_cur_player())
     self.board.place_piece(piece, node)
     self.catanlog.log_buys_city(self.get_cur_player(), hexgrid.location(hexgrid.NODE, node))
     self.set_state(catan.states.GameStateDuringTurnAfterRoll(self))