Discuss Scratch

marcelzietek2006
Scratcher
500+ posts

Tic Tac Toe vs AI

did you ever want to play Tic Tac Toe against like the worst model of machine learning (that still somehow works)
Well you can now!

Play it here and leave some feedback for me:
https://scratch.mit.edu/projects/447760686/



I hope you like it and can beat the computer!



(If you have any questions on how it works, feel free to ask me and I'll try my best to explain it!)


and you can also post your training codes (and maybe the time and what mode you trained) here.

Last edited by marcelzietek2006 (Nov. 12, 2020 18:05:08)

badgg1234
Scratcher
2 posts

Tic Tac Toe vs AI

spot_placeholders =
class Player():
def __init__(self, name, start = False):
self.values = {0:.5}
self.name = name
self.turn = start

def get_action(player1,player2):
while True:
if player1.turn == True:
action = int(input(player1.name + ‘, Where would you like to go?\n Move: ’))
if player2.turn == True:
action = int(input(player2.name + ‘, Where would you like to go?\n Move: ’))
if spot_placeholders == 0:
return action
else:
continue

def print_board():
board =
for spot in spot_placeholders:
if spot == 0:
board.append('_')
if spot == 1:
board.append('X')
if spot == 2:
board.append('O')
print(board,board,board)
print(board,board,board)
print(board,board,board)

def check_for_winner():
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
if spot_placeholders == spot_placeholders and spot_placeholders == spot_placeholders and spot_placeholders != 0:
return True
elif (spot_placeholders != 0 and spot_placeholders != 0 and
spot_placeholders != 0 and spot_placeholders != 0 and
spot_placeholders != 0 and spot_placeholders != 0 and
spot_placeholders != 0 and spot_placeholders != 0 and
spot_placeholders != 0):
return ‘CatGame’
else:
return False

def play_game(player1,player2):
global spot_placeholders

while True:
print_board()
if player1.turn == True:
a = get_action(player1,player2)
spot_placeholders = 1
if check_for_winner() == True:
print('Winner = ' + player1.name)
spot_placeholders =
break
if player2.turn == True:
a = get_action(player1,player2)
spot_placeholders = 2
if check_for_winner() == True:
print('Winner = ' + player2.name)
spot_placeholders =
break
if check_for_winner() == ‘CatGame’:
print('CatGame!')
spot_placeholders =
break

player1.turn = not player1.turn
player2.turn = not player2.turn



p1 = Player('Computer 1', True)
p2 = Player('Computer 2')

play_game(p1,p2)
badgg1234
Scratcher
2 posts

Tic Tac Toe vs AI

If you guys are interested in python programming.

Powered by DjangoBB