jeffqian345 / github-slideshow

A robot powered training repository :robot:
https://lab.github.com/githubtraining/introduction-to-github
MIT License
0 stars 0 forks source link

Getting Started with GitHub #1

Open github-learning-lab[bot] opened 4 years ago

github-learning-lab[bot] commented 4 years ago

:wave: Welcome to GitHub Learning Lab's "Introduction to GitHub"

To get started, I’ll guide you through some important first steps in coding and collaborating on GitHub.

:point_down: This arrow means you can expand the window! Click on them throughout the course to find more information.

What is GitHub?
## What is GitHub? I'm glad you asked! Many people come to GitHub because they want to contribute to open source [:book:](https://help.github.com/articles/github-glossary/#open-source) projects, or they're invited by teammates or classmates who use it for their projects. Why do people use GitHub for these projects? **At its heart, GitHub is a collaboration platform.** From software to legal documents, you can count on GitHub to help you do your best work with the collaboration and security tools your team needs. With GitHub, you can keep projects completely private, invite the world to collaborate, and streamline every step of your project. **GitHub is also a powerful version control tool.** GitHub uses Git [:book:](https://help.github.com/articles/github-glossary/#git), the most popular open source version control software, to track every contribution and contributor [:book:](https://help.github.com/articles/github-glossary/#contributor) to your project--so you know exactly where every line of code came from. **GitHub helps people do much more.** GitHub is used to build some of the most advanced technologies in the world. Whether you're visualizing data or building a new game, there's a whole community and set of tools on GitHub that can get you to the next step. This course starts with the basics, but we'll dig into the rest later! :tv: [Video: What is GitHub?](https://www.youtube.com/watch?v=w3jLJU7DT5E)

Exploring a GitHub repository
## Exploring a GitHub repository :tv: [Video: Exploring a repository](https://www.youtube.com/watch?v=R8OAwrcMlRw) ### More features The video covered some of the most commonly-used features. Here are a few other items you can find in GitHub repositories: - Project boards: Create Kanban-style task tracking board within GitHub - Wiki: Create and store relevant project documentation - Insights: View a drop-down menu that contains links to analytics tools for your repository including: - Pulse: Find information about the work that has been completed and the work that’s in-progress in this project dashboard - Graphs: Graphs provide a more granular view of the repository activity including who contributed to the repository, who forked it, and when they completed the work ### Special Files In the video you learned about a special file called the README.md. Here are a few other special files you can add to your repositories: - CONTRIBUTING.md: The `CONTRIBUTING.md` is used to describe the process for contributing to the repository. A link to the `CONTRIBUTING.md` file is shown anytime someone creates a new issue or pull request. - ISSUE_TEMPLATE.md: The `ISSUE_TEMPLATE.md` is another file you can use to pre-populate the body of an issue. For example, if you always need the same types of information for bug reports, include it in the issue template, and every new issue will be opened with your recommended starter text.
### Using issues This is an issue [:book:](https://help.github.com/articles/github-glossary/#issue): a place where you can have conversations about bugs in your code, code review, and just about anything else. Issue titles are like email subject lines. They tell your collaborators what the issue is about at a glance. For example, the title of this issue is Getting Started with GitHub.
Using GitHub Issues ## Using GitHub issues Issues are used to discuss ideas, enhancements, tasks, and bugs. They make collaboration easier by: - Providing everyone (even future team members) with the complete story in one place - Allowing you to cross-link to other issues and pull requests [:book:](https://help.github.com/articles/github-glossary/#pull-request) - Creating a single, comprehensive record of how and why you made certain decisions - Allowing you to easily pull the right people and teams into a conversation with @-mentions :tv: [Video: Using issues](https://www.youtube.com/watch?v=Zhj46r5D0nQ)
Managing notifications
## Managing notifications :tv: [Video: Watching, notifications, stars, and explore](https://www.youtube.com/watch?v=ocQldxF7fMY) Once you've commented on an issue or pull request, you'll start receiving email notifications when there's activity in the thread. ### How to silence or unmute specific conversations 1. Go to the issue or pull request 2. Under _"Notifications"_, click the **Unsubscribe** button on the right to silence notifications or **Subscribe** to unmute them You'll see a short description that explains your current notification status. ### How to customize notifications in Settings 1. Click your profile icon 2. Click **Settings** 3. Click **Notifications** from the menu on the left and [adjust your notification preferences](https://help.github.com/articles/managing-notification-delivery-methods/) ### Repository notification options * **Watch**: You'll receive a notification when a new issue, pull request or comment is posted, and when an issue is closed or a pull request is merged * **Not watching**: You'll no longer receive notifications unless you're @-mentioned * **Ignore**: You'll no longer receive any notifications from the repository ### How to review notifications for the repositories you're watching 1. Click your profile icon 2. Click **Settings** 3. Click **Notification** from the menu on the left 4. Click on the [things you’re watching](https://github.com/watching) link 5. Select the **Watching** tab 6. Click the **Unwatch** button to disable notifications, or **Watch** to enable them

Keep reading below to find your first task

github-learning-lab[bot] commented 4 years ago

Step 1: Assign yourself

Unassigned issues don't have owners to look after them. When you’re assigned to an issue or pull request, it tells repository visitors and contributors that you'll be facilitating the conversation or task :muscle:.

:keyboard: Activity

  1. On the right side of the screen, under the "Assignees" section, click the gear icon and select yourself

For a printable version of the steps in this course, check out the Quick Reference Guide.


I'll respond when I detect you've assigned yourself to this issue.

Sometimes I respond too fast for the page to update! If you perform an expected action and don't see a response from me, wait a few seconds and refresh the page for your next steps.

jeffqian345 commented 4 years ago

Reversegam: a clone of Othello/Reversi

import random import sys WIDTH = 8 # Board is 8 spaces wide. HEIGHT = 8 # Board is 8 spaces tall. def drawBoard(board):

Print the board passed to this function. Return None.

print('  12345678')
print(' +--------+')
for y in range(HEIGHT):
    print('%s|' % (y+1), end='')
    for x in range(WIDTH):
        print(board[x][y], end='')
    print('|%s' % (y+1))
print(' +--------+')
print('  12345678')

def getNewBoard():

Create a brand-new, blank board data structure.

board = []
for i in range(WIDTH):
    board.append([' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '])
return board

def isValidMove(board, tile, xstart, ystart):

Return False if the player's move on space xstart, ystart is invalid.

# If it is a valid move, return a list of spaces that would become the player's if they made a move there.
if board[xstart][ystart] != ' ' or not isOnBoard(xstart, ystart):
    return False

if tile == 'X':
    otherTile = '0'
else:
    otherTile = 'X'

tilesToFlip = []
for xdirection, ydirection in [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]]:
    x, y = xstart, ystart
    x += xdirection # First step in the x direction
    y += ydirection # First step in the y direction
    while isOnBoard(x, y) and board[x][y] == otherTile:
        # Keep moving in this x & y direction.
        x += xdirection
        y += ydirection
        if isOnBoard(x, y) and board[x][y] == tile:
            # There are pieces to flip over. Go in the reverse direction until we reach the original space, noting all the tiles along the way.
            while True:
                x -= xdirection
                y -= ydirection
                if x == xstart and y == ystart:
                    break
                tilesToFlip.append([x, y])

if len(tilesToFlip) == 0: # If not tiles were flipped, this is not a valid move.
    return False
return tilesToFlip

def isOnBoard(x, y):

Return True if the coordinates are located on the board.

return x >= 0 and x <= WIDTH - 1 and y >= 0 and y <= HEIGHT - 1

def getBoardWithValidMoves(board, tile):

Return a new board with periods marking the valid moves the player can make.

boardCopy = getBoardCopy(board)

for x, y in getValidMoves(boardCopy, tile):
    boardCopy[x][y] = '.'
return boardCopy

def getValidMoves(board, tile):

Return a list of [x,y] lists of valid moves for the given player on the given board.

validMoves = []
for x in range(WIDTH):
    for y in range(HEIGHT):
        if isValidMove(board, tile, x, y) != False:
            validMoves.append([x, y])
return validMoves

def getScoreOfBoard(board):

Determine the score by counting the tiles. Return a dictionary with keys 'X' and '0'.

xscore = 0
oscore = 0
for x in range(WIDTH):
    for y in range(HEIGHT):
        if board[x][y] == 'X':
            xscore += 1
        if board[x][y] == '0':
            oscore += 1
return {'X':xscore, '0':oscore}

def enterPlayerTile():

Let the player enter which tile they want to be.

# Return a list with the player's tile as the first item and the computer's tile as the second.
tile = ''
while not (tile == 'X' or tile == '0'):
    print('Do you want to be X or 0?')
    tile = input().upper()

# The first element in the list is the player's tile, and the second is the computer's tile.
if tile == 'X':
    return ['X', '0']
else:
    return ['0', 'X']

def whoGoesFirst():

Randomly choose who goes first.

if random.randint(0, 1) == 0:
    return 'computer'
else:
    return 'player'

def makeMove(board, tile, xstart, ystart):

Place the tile on the board at xstart, ystart and flip any of the opponent's pieces.

# Return False if this is an invalid move; True if it is valid.
tilesToFlip = isValidMove(board, tile, xstart, ystart)

if tilesToFlip == False:
    return False

board[xstart][ystart] = tile
for x, y in tilesToFlip:
    board[x][y] = tile
return True

def getBoardCopy(board):

Make a duplicate of the board list and return it.

boardCopy = getNewBoard()

for x in range(WIDTH):
    for y in range(HEIGHT):
        boardCopy[x][y] = board[x][y]

return boardCopy

def isOnCorner(x, y):

Return True if the position is in one of the four corners.

return (x == 0 or x == WIDTH - 1) and (y == 0 or y == HEIGHT - 1)

def getPlayerMove(board, playerTile):

Let the player enter their move.

# Return the move as [x, y] (or return the strings 'hints' or 'quit').
DIGITS1T08 = '1 2 3 4 5 6 7 8'.split()
while True:
    print('Enter your move, "quit" to end the game, or "hints" to toggle hints.')
    move = input().lower()
    if move == 'quit' or move == 'hints':
        return move

    if len(move) == 2 and move[0] in DIGITS1T08 and move[1] in DIGITS1T08:
        x = int(move[0]) - 1
        y = int(move[1]) - 1
        if isValidMove(board, playerTile, x, y) == False:
            continue
        else:
            break
    else:
        print('That is not a valid move. Enter the column (1-8) and then the row (1-8).')
        print('For example, 81 will move on the top-right corner.')

return [x, y]

def getComputerMove(board, computerTile):

Given a board and the computer's tile, determine where to

# move and return that move as an [x, y] list.
possibleMoves = getValidMoves(board, computerTile)
random.shuffle(possibleMoves) # Randomize the order of the moves.

# Always go for a corner if available.
for x, y in possibleMoves:
    if isOnCorner(x, y):
        return [x, y]

# Find the highest-scoring move possible.
bestScore = -1
for x, y in possibleMoves:
    boardCopy = getBoardCopy(board)
    makeMove(boardCopy, computerTile, x, y)
    score = getScoreOfBoard(boardCopy)[computerTile]
    if score > bestScore:
        bestMove = [x, y]
        bestScore = score
return bestMove

def printScore(board, playerTile, computerTile): scores = getScoreOfBoard(board) print('You: %s points. Computer: %s points.' % (scores[playerTile], scores[computerTile]))

def playGame(playerTile, computerTile): showHints = False turn = whoGoesFirst() print('The ' + turn + ' will go first.')

# Clear the board and place starting pieces.
board = getNewBoard()
board[3][3] = 'X'
board[3][4] = '0'
board[4][3] = '0'
board[4][4] = 'X'

while True:
    playerValidMoves = getValidMoves(board, playerTile)
    computerValidMoves = getValidMoves(board, computerTile)

    if playerValidMoves == [] and computerValidMoves == []:
        return board # No one can move, so end the game.

    elif turn == 'player': # Player's turn
        if playerValidMoves != []:
            #if showHints:
            #    validMovesBoard = getBoardWithValidMoves(board, playerTile)
            #    drawBoard(validMovesBoard)
            #else:
            #    drawBoard(board)
            #printScore(board, playerTile, computerTile)

            move = getComputerMove(board, playerTile)
            #if move == 'quit':
            #    print('Thanks for playing!')
            #    sys.exit() # Terminate the program.
            #elif move == 'hints':
            #    showHints = not showHints
            #    continue
            #else:
            makeMove(board, playerTile, move[0], move[1])
        turn = 'computer'

    elif turn == 'computer': # Computer's turn
        if computerValidMoves != []:
            #drawBoard(board)
            #printScore(board, playerTile, computerTile)

            #input('Press Enter to see the computer\'s move.')
            move = getComputerMove(board, computerTile)
            makeMove(board, computerTile, move[0], move[1])
        turn = 'player'

print('Welcome to Reversegam!')

playerTile, computerTile = ['X', '0'] #enterPlayerTile()

while True: finalBoard = playGame(playerTile, computerTile)

# Display the final score.
drawBoard(finalBoard)
scores = getScoreOfBoard(finalBoard)
print('X scored %s points. 0 scored %s points.' % (scores['X'], scores['0']))
if scores[playerTile] > scores[computerTile]:
    print('You beat the computer by %s points! Congratulations!' % (scores[playerTile] - scores[computerTile]))
elif scores[playerTile] < scores[computerTile]:
    print('You lost. The computer beat you by %s points.' % (scores[computerTile] - scores[playerTile]))
else:
    print('The game was a tie!')

print('Do you want to play again? (yes or no)')
if not input.lower().startswith('y'):
    break