Category: Uncategorized

  • Fusion Cad assignment

    In this Fusion assignment I was assigned to do something not that complicated in CAD. I decided to do a water bottle brcause it was really easy and can show a decent amount of basic skill in CAD.

    Sketching

    The first step was to do a sketch of the bottle. The bottle is in two parts, the first part is the actual bottle and the second bart is the lid. I made a sketch of half of it not really regarding the sizes.

    Extruding

    Then I use the revolve tool to make the bottle shape. After that I had to worry about making a way the lit and bottle can fit together. So I started by using the helix tool and make a new sketch then use the sweep tool to create screw like teeths on the bottle.

    I did the same on the Lid but with the sweep I made it remove so it can perfectly fit onto the bottle. after making a hole that is the right size. in the cap I used a sketch and used the center point circle tool to make a circle then used the extrude tool to remove a hole through the original design.

    For the cap you may have noticed a small cylinder on top of it, it was mainly used as a point to recognize if I did my assembly right in the future.

    After these steps I still had to make a hole in the bottle. This time differently I used the shell tool because it was easy and also because the irregular shape of the bottle.

    Assembly

    The Last step was to do the assembling. First I created a fastened mate on the bottle to the origin point. After that I put a cylindrical mate on the cap to the bottle. Last I made used the screw motion tool to make the Lid act like a screw so it can go on the bottle as I designed it to. Now to explain why the cylinder on top of the Lid is added, the reason for that is because it is easy to see if the screw motion actually works because it it really hard to tell if the Lid is rotating in a circular motion without adding anything.

    Mechanical drawing

    BOM

    AI usage

    AI was not used at any point in this assignment

    Link to Project

    https://sgs.onshape.com/documents/55bbaac79922e521e3f190d0/w/b7286ad062cb23d4a43e1df4/e/eae1d7e77a2745ae59d8ddef?renderMode=0&uiState=68ef120c644af4ae71e0fde0

  • Fusion Coding Assignment

    This is the first assignment of the fusion course. We as students are assigned to work with AI to create a full stack block of code in python with AI without the AI directly giving you the code. A flowchart was also requested to show my thinking process through creating the code.

    Definition of some words

    Python:
    Python is a basic coding language that is able to create and proccess functions to run what you tell a computer to do, for example if you want to let it return “Hello World”. You can simply type this into your coding application(pycharm or other):

    print(“Hello World”)

    Flowcharts:
    Flowcharts are basically a mind map that shows your thought process before you create your code. In my case it also constructs my questions I ask to Google gemini in order for it to help me.

    My Flowchart

    I started with a flowchart to plan out how I am going to ask Gemini the questions and also how my code is going to be constructed.

    In my flowchart there are 3 big parts, the first part is defining the attributes a card, my plan was to use suits and ranks for cards and later on define the value of each rank. The second part is when I created the Deck with suits and ranks. in my flowchart I connected suits to term since there are only 4 different suits and they do not interfere with the outcome, but ranks on the other hand do, so I wanted to give them values too. The third part was how the game would function including shuffling, dealing, the ace count since it is a changing variable.

    My code

    My decision was to make a game of Black Jack using python

    Under here is my complete block of code:

    import random
    class Card:
        def __init__(self, suit, rank, value):
            self.suit = suit
            self.rank = rank
            self.value = value
    
        def __str__(self):
            return f"{self.rank} of {self.suit}"
    class Deck:
        def __init__(self):
            suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
            ranks = {
                "2": 2, "3": 3, "4": 4, "5": 5, "6": 6,
                "7": 7, "8": 8, "9": 9, "10": 10,
                "Jack": 10, "Queen": 10, "King": 10, "Ace": 11
            }
            self.cards = [Card(suit, rank, value) for suit in suits for rank, value in ranks.items()]
            random.shuffle(self.cards)
        def deal_card(self):
            return self.cards.pop()
    class Hand:
        def __init__(self):
            self.cards = []
        def add_card(self, card):
            self.cards.append(card)
        def get_value(self):
            total = 0
            aces = 0
            for card in self.cards:
                total += card.value
                if card.rank == "Ace":
                    aces += 1
            while total > 21 and aces:
                total -= 10
                aces -= 1
            return total
        def __str__(self):
            return ", ".join(str(card) for card in self.cards)
    def play_blackjack():
        deck = Deck()
        player_hand = Hand()
        dealer_hand = Hand()
        player_hand.add_card(deck.deal_card())
        player_hand.add_card(deck.deal_card())
        dealer_hand.add_card(deck.deal_card())
        dealer_hand.add_card(deck.deal_card())
        while True:
            print(f"\nYour hand: {player_hand} (value: {player_hand.get_value()})")
            print(f"Dealer shows: {dealer_hand.cards[0]}")
            if player_hand.get_value() > 21:
                print("You bust! Dealer wins.")
                return
            choice = input("Do you want to (h)it or (s)tand? ").lower()
            if choice == "h":
                player_hand.add_card(deck.deal_card())
            elif choice == "s":
                break
        print(f"\nDealer's hand: {dealer_hand} (value: {dealer_hand.get_value()})")
        while dealer_hand.get_value() < 17:
            dealer_hand.add_card(deck.deal_card())
            print(f"Dealer hits: {dealer_hand} (value: {dealer_hand.get_value()})")
        player_total = player_hand.get_value()
        dealer_total = dealer_hand.get_value()
        if dealer_total > 21 or player_total > dealer_total:
            print("You win!")
        elif player_total < dealer_total:
            print("Dealer wins!")
        else:
            print("It's a tie!")
    if __name__ == "__main__":
        play_blackjack()

    Description – (words in bold are parts of the code)

    Defining a Card

    The Card class represents a single playing card. Each card has a suit (like Hearts), a rank (like Ace or 7), and a value (the number it’s worth in Blackjack). The __str__ method is what makes the card print nicely, such as "Ace of Hearts".

    import random
    class Card:
        def __init__(self, suit, rank, value):
            self.suit = suit
            self.rank = rank
            self.value = value
    
        def __str__(self):
            return f"{self.rank} of {self.suit}"

    Creating a Deck

    The Deck class represents the whole 52-card deck. Inside the constructor, we define all four suits and the possible ranks with their values. Then we build every combination (suit + rank) into a list of Card objects. After that, we shuffle the deck using random.shuffle(). The deal_card method removes the top card from the deck and gives it to a player.

    class Deck:
        def __init__(self):
            suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
            ranks = {
                "2": 2, "3": 3, "4": 4, "5": 5, "6": 6,
                "7": 7, "8": 8, "9": 9, "10": 10,
                "Jack": 10, "Queen": 10, "King": 10, "Ace": 11
            }
            self.cards = [Card(suit, rank, value) for suit in suits for rank, value in ranks.items()]
            random.shuffle(self.cards)
        def deal_card(self):
            return self.cards.pop()

    Creating hands for player and dealer

    The Hand class represents the cards that a player or the dealer holds. It starts empty. The add_card method lets us add a card to the hand. The get_value method calculates the total Blackjack score of the hand, treating Aces as 11 but changing them to 1 if the total goes over 21. The __str__ method makes the hand print as a list of cards separated by commas.

    class Hand:
        def __init__(self):
            self.cards = []
        def add_card(self, card):
            self.cards.append(card)
        def get_value(self):
            total = 0
            aces = 0
            for card in self.cards:
                total += card.value
                if card.rank == "Ace":
                    aces += 1
            while total > 21 and aces:
                total -= 10
                aces -= 1
            return total
        def __str__(self):
            return ", ".join(str(card) for card in self.cards)

    Game Setup

    The play_blackjack function is the main game. It first makes a shuffled Deck, then creates empty Hand objects for the player and the dealer. Each of them is then dealt two cards to begin the game.

    def play_blackjack():
        deck = Deck()
        player_hand = Hand()
        dealer_hand = Hand()
        player_hand.add_card(deck.deal_card())
        player_hand.add_card(deck.deal_card())
        dealer_hand.add_card(deck.deal_card())
        dealer_hand.add_card(deck.deal_card())

    Player’s Turn

    During the player’s turn, the program shows the player’s full hand and one of the dealer’s cards. If the player’s hand is already over 21, they “bust” and lose immediately. Otherwise, the player can choose to hit (take another card) or stand (keep their current hand). Hitting adds a card, and standing moves to the dealer’s turn.

    while True:
            print(f"\nYour hand: {player_hand} (value: {player_hand.get_value()})")
            print(f"Dealer shows: {dealer_hand.cards[0]}")
            if player_hand.get_value() > 21:
                print("You bust! Dealer wins.")
                return
            choice = input("Do you want to (h)it or (s)tand? ").lower()
            if choice == "h":
                player_hand.add_card(deck.deal_card())
            elif choice == "s":
                break

    Dealer’s Turn

    Once the player is done, the dealer’s full hand is revealed. The dealer must follow Blackjack rules: keep hitting until the hand is worth at least 17. Each time the dealer takes a card, the program shows the new hand and its total.

        print(f"\nDealer's hand: {dealer_hand} (value: {dealer_hand.get_value()})")
        while dealer_hand.get_value() < 17:
            dealer_hand.add_card(deck.deal_card())
            print(f"Dealer hits: {dealer_hand} (value: {dealer_hand.get_value()})")

    Deciding the Winner

    After both turns are finished, the program compares the totals. If the dealer goes over 21, the player automatically wins. Otherwise, whoever has the higher total without going over 21 wins. If both totals are equal, the game ends in a tie.

    player_total = player_hand.get_value()
        dealer_total = dealer_hand.get_value()
        if dealer_total > 21 or player_total > dealer_total:
            print("You win!")
        elif player_total < dealer_total:
            print("Dealer wins!")
        else:
            print("It's a tie!")

    How to play

    When you run the game with the code, your console would pop up and it will show 3 lines. the first line shows your cards and the total count of your cards, the second line shows 1 of the dealer’s cards, and the third line would ask if you would like to hit or stand. To hit simply enter “h” and then click enter on your keyboard. To stand enter “s” and then click enter on your keyboard. The game will keep going if you keep hitting until you bust, and when you stand the dealer will process through hitting until his cards are either larger than yours in count, or until he busts.

    AI Transcript – (https://docs.google.com/document/d/1ycuqsLcK_CNEMFykyVAm08KaD53f2Z8QLlQ30SFKsBY/edit?usp=sharing)

  • Hello world!

    Welcome to User’s blog Sites. This is your first post. Edit or delete it, then start writing!