Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
def __init__(self):
self.map=[[0,0,0],[0,0,0],[0,0,0]]
def getFreeSquares(self):
toRet=[]
for i in range(3):
for k in range(3):
if not self.map[i][k]:
toRet.append(str(k)+str(i))
return toRet
def put(self,x,y,player):
#print("Putting",x,",",y,",",player)
if self.map[y][x]:
print("Mossa invalida")
return False
self.map[y][x]=player
return True
def print(self):
for row in self.map:
for elem in row:
print(elem,sep="",end="")
print("")
def check(self,player):
for i in range(3):
if self.map[0][i]==self.map[1][i]==self.map[2][i]==player:
return True
if self.map[i][0]==self.map[i][1]==self.map[i][2]==player:
return True
if self.map[0][0]==self.map[1][1]==self.map[2][2]==player:
return True
if self.map[0][2]==self.map[1][1]==self.map[2][0]==player:
return True
return False
def nearCheck(self,player):
f=self.getFreeSquares()
if not f:
return False
for move in f:
#print("Provo",move)
self.put(int(move[0]),int(move[1]),player)
if self.check(player):
self.map[int(move[1])][int(move[0])]=0
#print("Annullo",move)
return move
self.map[int(move[1])][int(move[0])]=0
#print("Annullo",move)
return False
def evaluate(self,player=1):
#caso base
#print("Chiamata")
m = self.nearCheck(player)
if m:
#print("mate in 1")
return (m,player)
else:
#print("non mate in 1")
if self.getFreeSquares():
#print("Ci sono case libere")
#print("free:",self.getFreeSquares)
moves={}
for move in self.getFreeSquares():
#print("Move:",move)
self.put(int(move[0]),int(move[1]),player)
moves[move]=self.evaluate(1 if player==2 else 2)[1]
self.map[int(move[1])][int(move[0])]=0
for move in moves:
if moves[move]==player:
return (move,player)
for move in moves:
if moves[move]==0.5:
return (move,0.5)
for move in moves:
return (move,1 if player==2 else 2)
else:
return (None,0.5)
def ask(self,player):
print("-"*25)
self.print()
x=int(input("X: "))
y=int(input("Y: "))
if not self.put(x,y,player):
print("Mossa invalida...")
self.ask(player)
def playBest(self,player):
m=self.evaluate(player)
print("EVAL:",m)
self.put(int(m[0][0]),int(m[0][1]),player)
self.print()
b=Board()
b.print()
b.ask(1)
b.playBest(2)
b.ask(1)
b.playBest(2)
b.ask(1)
b.playBest(2)
b.ask(1)
b.playBest(2)
b.ask(1)
![]() |
Notes.io is a web-based application for 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 12 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