예제 #1
0
    def make_move(self, piece_coord, move_coord):
        """
        Perform a move of a single piece.
        :param piece_coord: X and Y coordinates of the piece's location.
        :type piece_coord: list
        :param move_coord: X and Y coordinates where to move the piece.
        :type move_coord: list   
        :return: If the turn is successful.
        :rtype: bool
        """        
        x = piece_coord[0]
        y = piece_coord[1]
        # Check to make sure the chosen piece exists.
        piece_found = False
        for piece in self.board.pieces:
            if piece.x is x and piece.y is y:
                piece_found = True
                break

        if piece_found is False:
            logger.error("Could not find piece for player=%u at (%u,%u).",
                         self.active_player.id, x, y)
            return False

        if piece.player != self.active_player:
            logger.error("Piece owned by player=%u not player=%u at (%u,%u).",
                         piece.player.id, self.active_player.id, x, y)
            return False

        # Handle the suggested move.
        if len(move_coord) is not 2:
            logger.error("Invalid move selection for player=%u. Need two coordinates not %u.",
                         self.active_player.id, len(move_coord))
            return False
        x = move_coord[0]
        y = move_coord[1]

        # Check for piece collision.
        if self.does_cause_collision(x, y):
            logger.error("Invalid move selection for player=%u. Element exists at (%u,%u).",
                         self.active_player.id, x, y)
            return False

        # When move is made, attempt it.
        if piece.is_jump_distance(x, y):
            piece.jump(x, y)
        elif piece.is_clone_distance(x, y):
            new_piece = piece.clone(x, y)
            self.board.pieces.append(new_piece)
            piece = new_piece
        else:
            logger.error("Piece owned by player=%u not in range of jump or clone at (%u,%u).",
                         piece.player.id, x, y)
            return False

        self.check_for_capture(piece)
        return True
예제 #2
0
 def take_turn(self):
     """
     Takes the current player's turn.
     :return: If the turn is successful.
     :rtype: bool
     """
     # Obtain the move from the current player.
     piece_coord, move_coord = self.active_player.make_move()
     if len(piece_coord) is not 2:
         logger.error("Invalid piece selection for player=%u. Need two coordinates not %u.",
                      self.active_player.id, len(piece_coord))
         return False
     
     return self.make_move(piece_coord, move_coord);
예제 #3
0
파일: main.py 프로젝트: Wilfcastle/colonies
def main(argv):
    """
    Method that gets executed to run a game of colonies.
    :param argv: Passed argument list to program. File to parse.
    :type argv: list
    """
    if len(argv) < 2:
        logger.error("ERROR - Need to supply file as input.")
        return

    # Parse the provided file into a Board object.
    sample_game_board = Board()
    Parser.parse_file(argv[1], sample_game_board)

    # Play a game of Colonies with the newly created board.
    console = Console(sample_game_board)
    console.play()
예제 #4
0
 def evaluate_board(self):
     """ Handles any updates on board state. Exits if there is a winner. """
     if self.is_winner() is True:
         logger.error("Player=%u has won!.", self.active_player.id)
         exit()