- 
                Notifications
    You must be signed in to change notification settings 
- Fork 7.3k
Improved System Information Output #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            Roshmita-viswa
  wants to merge
  23
  commits into
  AntonOsika:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
Roshmita-viswa:main
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 15 commits
      Commits
    
    
            Show all changes
          
          
            23 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e8acb0d
              
                first commit
              
              
                Roshmita-viswa 3a4b005
              
                FIX: Apply automatic code formatting via pre-commit/black
              
              
                Roshmita-viswa c5ff4f8
              
                Update pyproject.toml
              
              
                Roshmita-viswa 0e3ec89
              
                Update pyproject.toml
              
              
                Roshmita-viswa 309e77d
              
                Update ci.yaml
              
              
                Roshmita-viswa e9aeba8
              
                Update tox.ini
              
              
                Roshmita-viswa 9a43702
              
                Update ci.yaml
              
              
                Roshmita-viswa 162cf70
              
                Update pyproject.toml
              
              
                Roshmita-viswa a473261
              
                Update ci.yaml
              
              
                Roshmita-viswa e9f9d0f
              
                Update ci.yaml
              
              
                Roshmita-viswa 9f2da69
              
                Update pyproject.toml
              
              
                Roshmita-viswa 66927c8
              
                Update projects/example-improve/main.py
              
              
                Roshmita-viswa 0226e9f
              
                Update ci.yaml
              
              
                Roshmita-viswa e93924a
              
                Update ci.yaml
              
              
                Roshmita-viswa ca3bcda
              
                Update ci.yaml
              
              
                Roshmita-viswa 7ceea41
              
                Update test_install.py
              
              
                Roshmita-viswa 0abaefd
              
                Update ci.yaml
              
              
                Roshmita-viswa 08b06ed
              
                Update test_install.py
              
              
                Roshmita-viswa 05c63d8
              
                Update test_install.py
              
              
                Roshmita-viswa d6e8737
              
                Update test_install.py
              
              
                Roshmita-viswa 0231e12
              
                Update test_install.py
              
              
                Roshmita-viswa 825857c
              
                Update ci.yaml
              
              
                Roshmita-viswa ec39e91
              
                Update test_install.py
              
              
                Roshmita-viswa File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,21 +1,37 @@ | ||
| # --- controller.py --- | ||
| import keyboard | ||
|  | ||
| from model import Point # Import Point to define directions | ||
|  | ||
|  | ||
| class Controller: | ||
| def __init__(self, game, view): | ||
| self.game = game | ||
| self.view = view | ||
|  | ||
| def handle_input(self): | ||
| if keyboard.is_pressed("up") and not hasattr(self, "last_key_pressed"): | ||
| self.game.move("down") | ||
| self.last_key_pressed = "up" | ||
| elif hasattr(self, "last_key_pressed") and self.last_key_pressed == "up": | ||
| self.game.move("right") | ||
| del self.last_key_pressed | ||
| # We need a reference to the snake to change its direction | ||
| snake = self.game.snake | ||
|  | ||
| # Check for key presses and set the snake's direction using Point objects. | ||
| # Note: We must call set_direction on the snake object. | ||
|  | ||
| # UP: Change Y by -1 | ||
| if keyboard.is_pressed("up"): | ||
| snake.set_direction(Point(0, -1)) | ||
|  | ||
| # DOWN: Change Y by +1 | ||
| elif keyboard.is_pressed("down"): | ||
| self.game.move("up") | ||
| snake.set_direction(Point(0, 1)) | ||
|  | ||
| # LEFT: Change X by -1 | ||
| elif keyboard.is_pressed("left"): | ||
| self.game.move("right") | ||
| snake.set_direction(Point(-1, 0)) | ||
|  | ||
| # RIGHT: Change X by +1 | ||
| elif keyboard.is_pressed("right"): | ||
| self.game.move("left") | ||
| snake.set_direction(Point(1, 0)) | ||
|  | ||
| # Optional: Add an exit key | ||
| elif keyboard.is_pressed("esc"): | ||
| self.game.is_running = False | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,32 +1,88 @@ | ||
| # --- model.py --- | ||
| import random | ||
|  | ||
| from dataclasses import dataclass | ||
|  | ||
|  | ||
| # ------------------------------ | ||
| # Data Structures | ||
| # ------------------------------ | ||
| @dataclass | ||
| class Point: | ||
| x: int | ||
| y: int | ||
|  | ||
|  | ||
| # ------------------------------ | ||
| # Snake Class | ||
| # ------------------------------ | ||
| class Snake: | ||
| def __init__(self, initial_position: Point): | ||
| self.body: list[Point] = [initial_position] # Snake starts with one segment | ||
| self.direction = Point(1, 0) # Moving right initially | ||
| self.grow_next_move = False # Flag to handle growth | ||
|  | ||
| @property | ||
| def head(self) -> Point: | ||
| """Return the current head of the snake.""" | ||
| return self.body[0] | ||
|  | ||
| def set_direction(self, new_direction: Point): | ||
| """Change direction if not opposite to current.""" | ||
| if ( | ||
| self.direction.x + new_direction.x != 0 | ||
| or self.direction.y + new_direction.y != 0 | ||
| ): | ||
| self.direction = new_direction | ||
|  | ||
| def move(self): | ||
| """Move the snake in the current direction.""" | ||
| new_head = Point(self.head.x + self.direction.x, self.head.y + self.direction.y) | ||
| self.body.insert(0, new_head) # Add new head | ||
| if self.grow_next_move: | ||
| self.grow_next_move = False # Growth applied, reset flag | ||
| else: | ||
| self.body.pop() # Remove tail if not growing | ||
|  | ||
| def grow(self): | ||
| """Trigger growth on the next move.""" | ||
| self.grow_next_move = True | ||
|  | ||
|  | ||
| # ------------------------------ | ||
| # Game Class | ||
| # ------------------------------ | ||
| class Game: | ||
| def __init__(self): | ||
| self.snake = [Point(5, 5)] | ||
| def __init__(self, size: int = 10): | ||
| self.size = size # Board size (size x size) | ||
| self.snake = Snake(initial_position=Point(size // 2, size // 2)) | ||
| self.food = self.generate_food() | ||
| self.is_running = True | ||
|  | ||
| def generate_food(self): | ||
| return Point(random.randint(0, 10), random.randint(0, 10)) | ||
| """Generate food not overlapping with the snake.""" | ||
| while True: | ||
| food_point = Point( | ||
| random.randint(0, self.size - 1), random.randint(0, self.size - 1) | ||
| ) | ||
| if food_point not in self.snake.body: | ||
| return food_point | ||
|  | ||
| def update(self): | ||
| # Move the snake | ||
| """Update the game state: move snake, handle collisions.""" | ||
| self.snake.move() | ||
|  | ||
| # Check for collision with food | ||
| # Check for food collision | ||
| if self.snake.head == self.food: | ||
| self.snake.grow() | ||
| self.food = self.generate_food() | ||
|  | ||
| # Check for collision with boundaries | ||
| if not (0 <= self.snake.head.x < 10 and 0 <= self.snake.head.y < 10): | ||
| # Check for wall collisions | ||
| if not ( | ||
| 0 <= self.snake.head.x < self.size and 0 <= self.snake.head.y < self.size | ||
| ): | ||
| self.is_running = False | ||
|  | ||
| # Check for self-collision | ||
| if self.snake.head in self.snake.body[1:]: | ||
| self.is_running = False | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.