Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import random
#A . Variables
x = 'x'
o = 'o'
isXTurn = True
StateMap = {} # []
RSM = {}
moveList=[]
stateList=[]
def placePiece():
if isXTurn:
response = input("Where would you like to move? (1-9):")
response = int(response) - 1
board[response] = x
else:
aiMove = findAiMove()
stateList.append(boardToString())
moveList.append(aiMove)
board[aiMove] = o
def printBoard():
loop = 0
while loop < 3:
print(board[loop*3], "|", board[1+loop*3], "|", board[2+loop*3])
loop += 1
def gameLoop():
global isXTurn
global board
print("site map: {}".format(StateMap))
print("Move List: {}".format(moveList))
print("State List {}".format(stateList))
printBoard()
placePiece()
if isWin():
printBoard()
if isXTurn:
print("X won!")
train(False)
else:
print("O won!")
train(True)
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
input()
if isDraw():
printBoard()
print("It's a draw")
train(True)
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
input()
isXTurn = not isXTurn
def isDraw():
count = 0
while count < 9:
if board[count] == ' ':
return False
count += 1
return True
def isWin():
# Check horizontral rows
if board[0] == board[1] and board[1] == board[2] and board[0] != ' ':
return True
if board[3] == board[4] and board[4] == board[5] and board[3] != ' ':
return True
if board[6] == board[7] and board[7] == board[8] and board[6] != ' ':
return True
# Check Vertical rows
if board[0] == board[3] and board[3] == board[6] and board[0] != ' ':
return True
if board[1] == board[4] and board[4] == board[7] and board[1] != ' ':
return True
if board[2] == board[5] and board[5] == board[8] and board[2] != ' ':
return True
# Check Diagonals
if board[0] == board[4] and board[4] == board[8] and board[0] != ' ':
return True
if board[2] == board[4] and board[4] == board[6] and board[2] != ' ':
return True
#no winners
return False
def train(isWin):
global stateList
global stateMap
global moveList
if isWin:
for i, state in enumerate(stateList):
stateMap[state] = stateMap[state] + [moveList[i], moveList[i], moveList[i]]
else:
for i, state in enumerate(stateList):
stateMap[state].remove(moveList[i])
moveList=[]
stateList=[]
def boardString():
global board
board_stri = ''
board_stri = board_stri.join(str(x) for x in board)
return board_stri
def ai_moves():
global StateMap, RSM, board
current_board = boardString()
if (current_board in StateMap):
move_index = random.randint(0, len(StateMap[current_state])-1)
RSM[current_board] = move_index
board[StateMap[current_board][move_index]] = 'O'
else:
StateMap[current_board] = what_is_available()
ai_moves()
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team