Discuss Scratch

rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

PLEASE I WANTED TO MAKE A TIC TAC TOE GAME WITHOUT LISTS AND IT WORKED FOR THE TWO PLAYER PART BUT NOW I WANT THE COMP TO PLAY I TRIED USING PICK RANDOM AND IT DIDN'T TURN OUT WELL .NOW I WANT TO USE LISTS AND I'M BLANK ..I NEED HELP FROM ANYONE WHO CAN USE EITHER BLOCKS TO HELP ME(I HAVE DONE THIS PREVIOUSLY USING RANDOM POSITIONS)
HenriStar8
Scratcher
100+ posts

TIC TAC TOE AI

ok, since it's an AI, it shouldn't be random positions. to make an AI in a game, you need it to calculate every win% to each movement it can take, and choose the one which has the best chance to win, so tic tac toe has a lot of movements possibles at the same time, so you need a lot of calculations to work as a real AI
deck26
Scratcher
1000+ posts

TIC TAC TOE AI

If you search in Scratch there are lots of projects. Here's one I made that might be useful for spotting winning positions. https://scratch.mit.edu/projects/45243244/

Last edited by deck26 (Aug. 24, 2021 11:34:30)

rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

@Henristar8

I really understand what you mean but I just need a bot that can find random empty slots and play there it isn't really thinking and i tried using both random blocks and lists and I still can't pass through that obstacle ….can anyone help
deck26
Scratcher
1000+ posts

TIC TAC TOE AI

rocketblastgames wrote:

@Henristar8

I really understand what you mean but I just need a bot that can find random empty slots and play there it isn't really thinking and i tried using both random blocks and lists and I still can't pass through that obstacle ….can anyone help
So how do you store the grid? If it's a list you presumably have a 0 or something in empty slots. So you could choose a random item from the list until you find an unused slot but that's inefficient.

A better methoud would be a list which initially contains 1 to 9. Each time you play in one cell remove its number from the list so you can then choose a random item number from the list.

use the item# of item in list block for this. If you're list currently contains 1, 3, 7, 9 and you're playing in cell 3 it is important that you remove the 3 and not item 3 which is the 7.
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

how then can i pick a random item from a list …trust me i have tried but it dosen't work on the online editor ,can you teach me
HenriStar8
Scratcher
100+ posts

TIC TAC TOE AI

(item (pick random (1) to (length of [numbers v] :: list)) of [numbers v] :: list)
I think that will work
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

not to pick the number of the item but the name …ok what if the player plays on box3 ..the comp will have to choose a random of 1,2,4,5,6,7,8,9 and so on
.Will this block of code still work.thanks anyway
deck26
Scratcher
1000+ posts

TIC TAC TOE AI

rocketblastgames wrote:

not to pick the number of the item but the name …ok what if the player plays on box3 ..the comp will have to choose a random of 1,2,4,5,6,7,8,9 and so on
.Will this block of code still work.thanks anyway
Not sure why you think it won't. It's choosing a random item from the list. What do you mean by ‘not the number but the name’?
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

Well im gonna try .thanks alot .I'm going to follow both of you right now (and if you don't mind may i know your age)i'm 16
deck26
Scratcher
1000+ posts

TIC TAC TOE AI

rocketblastgames wrote:

Well im gonna try .thanks alot .I'm going to follow both of you right now (and if you don't mind may i know your age)i'm 16
60+ as it says on my profile.
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

I AM HONOURED TO MEET YOU
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

BUT STILL HOW THEN WILL I BE ABLE TO ADD THE SAME ITEMS TO THE LIST AFTER THE GREEN FLAG IS PRESSED ..IT'S REALLY MESSED UP
HenriStar8
Scratcher
100+ posts

TIC TAC TOE AI

rocketblastgames wrote:

BUT STILL HOW THEN WILL I BE ABLE TO ADD THE SAME ITEMS TO THE LIST AFTER THE GREEN FLAG IS PRESSED ..IT'S REALLY MESSED UP
whaddya mean?
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

after deleting from the list how then will i be able to lets say refresh the list with the same value e.g. 1,2,3,4 .i hope you understand
HenriStar8
Scratcher
100+ posts

TIC TAC TOE AI

oh I see, you could broadcast it, like that:
when I receive [reset v]
delete all of [numbers v]
set [# v] to [1]
repeat (9)
add [#] to [numbers v]
change [# v] by (1)
end
or
...
add [1] to [numbers v]
add [2] to [numbers v]
...
deck26
Scratcher
1000+ posts

TIC TAC TOE AI

Or

delete (all v) of [list v]
repeat [9]
add ((length of [list v] :: list) + [1]) to [list]
HenriStar8
Scratcher
100+ posts

TIC TAC TOE AI

deck26 wrote:

Or

delete (all v) of [list v]
repeat [9]
add ((length of [list v] :: list) + [1]) to [list]
that's actually big brain
rocketblastgames
Scratcher
15 posts

TIC TAC TOE AI

@ decky26
i need to meet you in person your like the bill gates of scratch(but i can't i am from nigeria)
orangetheory
Scratcher
500+ posts

TIC TAC TOE AI

You can clone the slots, sort of like a grid, like so
when green flag clicked
hide
go to x:(100) y: (100)
Clone Grid

define Clone Grid
repeat (3)
create clone of myself
change x by (size of the costume)
end
change y by (-size of the costume)
repeat (3)
create clone of myself
change x by (-size of the costume)
end
change y by (-size of the costume)
repeat (3)
create clone of myself
change x by (size of the costume)
end
Then
when I start as a clone
show
set [Grid Grid Status v] to (0) // for this sprite only
forever
if <touching [mouse pointer v]> then
if <mouse down?> then
set [Grid Status v] to ( taken ) // taken should not be a variable
end
end
end
Then make the computer act by whichever slot is taken.

Powered by DjangoBB