Esempio n. 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')
Esempio n. 2
0
 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
     ))
Esempio n. 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))
Esempio n. 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))
Esempio n. 5
0
 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))
Esempio n. 6
0
 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
     ))
Esempio n. 7
0
 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
     ))
Esempio n. 8
0
 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))
Esempio n. 9
0
 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))
Esempio n. 10
0
 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))
Esempio n. 11
0
 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))
Esempio n. 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))
Esempio n. 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))
Esempio n. 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))
Esempio n. 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]
Esempio n. 16
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))
     self.set_dev_card_state(catan.states.DevCardPlayedState(self))
Esempio n. 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))
Esempio n. 18
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)
     )
     self.set_dev_card_state(catan.states.DevCardPlayedState(self))
Esempio n. 19
0
 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))