# data[].attributes.body
https://youtube.com/@winmachines?si=pnMng9wsLX8ECG29

# data[].attributes.body
tiktok.com/@winmachiness

# data[].attributes.body
https://www.facebook.com/em.tung.549221?mibextid=9R9pXO

# data[].attributes.body
File tài liệu kiến thức cơ bản lịch sử 10 CTST

UPLOADED FILE 18/1/2024

21:08
WIN MACHINES

# data[].attributes.body
Code game python, để sử dụng đoạn code này đầu tiên thì bạn phải có điện thoại tiếp theo là có app python muốn có app python thì lênh ch play hoặc app store mà tải về sau đó dán đoạn code này rồi chạy thôi bạn đã có game cờ caro do tôi tạo chứ không phải bạn tạo 😂😂

WIN MACHINES

# data[].attributes.attachment_link.readable_text
import random
 
def drawBoard(board):
    #Th���c hi���n in ra b��n c���
    print(board[7] + '|' + board[8] + '|' + board[9])
    print('-+-+-')
    print(board[4] + '|' + board[5] + '|' + board[6])
    print('-+-+-')
    print(board[1] + '|' + board[2] + '|' + board[3])
 
def inputPlayerLetter():
    #Cho ph��p ng�����i ch��i nh���p k�� t��� m�� h��� mu���n s��� d���ng
    #Tr��� v��� t���p h���p ki���u List v���i k�� t��� m�� ng�����i ch��i ch���n l��m ph���n t��� �����u ti��n
    letter = ''
    while not (letter == 'X' or letter == 'O'):
        print('Do you want to be X or O?')
        letter = input().upper()
 
    if letter == 'X':
        return ['X', 'O']
    else:
        return ['O', 'X']
 
def whoGoesFirst():
    #Ch���n ng���u nhi��n b���t k��� cho ph��p ng�����i ch��i ��i tr�����c hay kh��ng
    if random.randint(0, 1) == 0:
        return 'computer'
    else:
        return 'player'
 
def makeMove(board, letter, move):
    board[move] = letter
 
def isWinner(bo, le):
    #Tr��� v��� True n���u ng�����i ch��i th���ng
    return ((bo[7] == le and bo[8] == le and bo[9] == le) or
    (bo[4] == le and bo[5] == le and bo[6] == le) or
    (bo[1] == le and bo[2] == le and bo[3] == le) or
    (bo[7] == le and bo[4] == le and bo[1] == le) or
    (bo[8] == le and bo[5] == le and bo[2] == le) or
    (bo[9] == le and bo[6] == le and bo[3] == le) or
    (bo[7] == le and bo[5] == le and bo[3] == le) or
    (bo[9] == le and bo[5] == le and bo[1] == le))
 
def getBoardCopy(board):
    #Sao ch��p b��n c���
    boardCopy = []
    for i in board:
        boardCopy.append(i)
    return boardCopy
 
def isSpaceFree(board, move):
    #Tr��� v��� True n���u n�����c ��i c��n ch��� tr���ng
    return board[move] == ' '
 
def getPlayerMove(board):
    #L���y n�����c ��i c���a ng�����i ch��i
    move = ' '
    while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):
        print('What is your next move? (1-9)')
        move = input()
    return int(move)
 
def chooseRandomMoveFromList(board, movesList):
    #Tr��� v��� m���t n�����c ��i h���p l���
    #Tr��� v��� None n���u kh��ng c��n n�����c ��i h���p l���
    possibleMoves = []
    for i in movesList:
        if isSpaceFree(board, i):
            possibleMoves.append(i)
 
    if len(possibleMoves) != 0:
        return random.choice(possibleMoves)
    else:
        return None
 
def getComputerMove(board, computerLetter):
    #X��c �����nh n�����c ��i cho m��y
    if computerLetter == 'X':
        playerLetter = 'O'
    else:
        playerLetter = 'X'
 
    #Gi���i thu���t cho m��y ch��i
    #Ki���m tra xem n�����c ��i ti���p theo c�� th���ng �������c hay kh��ng
    for i in range(1, 10):
        boardCopy = getBoardCopy(board)
        if isSpaceFree(boardCopy, i):
            makeMove(boardCopy, computerLetter, i)
            if isWinner(boardCopy, computerLetter):
                return i
 
    #Ki���m tra xem ng�����i ch��i c�� th��� th���ng trong n�����c ��i ti���p theo hay kh��ng
    for i in range(1, 10):
        boardCopy = getBoardCopy(board)
        if isSpaceFree(boardCopy, i):
            makeMove(boardCopy, playerLetter, i)
            if isWinner(boardCopy, playerLetter):
                return i
 
    #Ch���n m���t n�����c ��i ��� c��c g��c b��n c��� n���u tr���ng
    move = chooseRandomMoveFromList(board, [1, 3, 7, 9])
    if move != None:
        return move
 
    #Ch���n n�����c ��i ��� gi���a
    if isSpaceFree(board, 5):
        return 5
 
    #Ch���n m���t trong c��c n�����c ��i ��� c��c c���nh b��n c���a b��n c���
    return chooseRandomMoveFromList(board, [2, 4, 6, 8])
 
def isBoardFull(board):
    #Tr��� v��� True n���u c��c n�����c ��i kh��ng c��n, ng�����c l���i tr��� v��� False
    for i in range(1, 10):
        if isSpaceFree(board, i):
            return False
    return True
 
 
print('Welcome to Tic Tac Toe!')
 
while True:
    #Thi���t l���p l���i b��n c���
    theBoard = [' '] * 10
    playerLetter, computerLetter = inputPlayerLetter()
    turn = whoGoesFirst()
    print('The ' + turn + ' will go first.')
    gameIsPlaying = True
 
    while gameIsPlaying:
        if turn == 'player':
            drawBoard(theBoard)
            move = getPlayerMove(theBoard)
            makeMove(theBoard, playerLetter, move)
 
            if isWinner(theBoard, playerLetter):
                drawBoard(theBoard)
                print('Hooray! You have won the game!')
                gameIsPlaying = False
            else:
                if isBoardFull(theBoard):
                    drawBoard(theBoard)
                    print('The game is a tie!')
                    break
                else:
                    turn = 'computer'
 
        else:
            move = getComputerMove(theBoard, computerLetter)
            makeMove(theBoard, computerLetter, move)
 
            if isWinner(theBoard, computerLetter):
                drawBoard(theBoard)
                print('The computer has beaten you! You lose.')
                gameIsPlaying = False
            else:
                if isBoardFull(theBoard):
                    drawBoard(theBoard)
                    print('The game is a tie!')
                    break
                else:
                    turn = 'player'
 
    print('Do you want to play again? (yes or no)')
    if not input().lower().startswith('y'):
        break