#๐Ÿ”’ how do i make my ai more advanced?

46 messages ยท Page 1 of 1 (latest)

celest mesaBOT
#

@toxic imp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

toxic imp
#
#imports
    import pygame
    import pygame.mouse
    from pygame.locals import *
    import random 

    #init
    pygame.init()

    #screen caption and size
    scr = pygame.display.set_mode((330,330))
    pygame.display.set_caption('tick tack toe')
    #screen color
    color = (0,0,255)
    start_x = 10
    start_y = 10
    rect_width = 100
    rect_height = 100
    margin_x = 5
    margin_y = 5
    cell_used = [[0,0,0],[0,0,0],[0,0,0]]
#

nvm half of the code does not sppear

civic sentinel
#

Uplaod it to a pastebin

fathom laurel
#

!paste

celest mesaBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

toxic imp
#

done

#

@fathom laurel

#

@civic sentinel

fathom laurel
#

somehow the upload is broken. there is no indentation.

toxic imp
#

try it again

fathom laurel
#

ah, i see. it's just a problem with the display because the whole code is indented except the first line.

#
#imports
    import pygame
    import pygame.mouse
    from pygame.locals import *
    import random ```
#

but still the code seems to have syntax errors.

        j = 
        while 
        for j in range (3):
            for i in range (3):
                if(cell_used[j][i] == 0):
                    cell_used[j][i] = -1;```
#

So what are you trying to do? Does the AI work already?

toxic imp
#

it does im trying to make it not go in the same place all the time

#

im making it smarter\

#

trying to

fathom laurel
#

Yes, currently it seems the AI always chooses the first free cell.

toxic imp
#

yes

#

every time i refresh the game and go on the same cell it goes on the same cell as its previous refresh

#

do you understand what i meen

fathom laurel
#

yes, so what would you like to do instead?

toxic imp
#

i would like to make it smarter so it goes anywhere on the map and make it block the 2 lines

#

the game is tick tack toe

#

so i want it to block the person gettting 3 lines

fathom laurel
#

yes, but you can't make it too smart. or it will never lose a game.

#

or you could make it smart. your choice.

civic sentinel
#

Make it sometimes do it? If you don't want it to be always smart

toxic imp
#

just smart enough to make it win sometimes and lose and it also blockes

toxic imp
#

also i can do that with a level thing

fathom laurel
#

it seems like randomness is important.

#

It has multiple functions for randomness.
For example
x = random.random() returns a number between 0.0 and 0.999.
x = random.randint(0, 3) returns either 0, 1, or 2.
random.shuffle(items) shuffles a list of items. (in-place)
samples = random.sample(items, k=3) returns 3 random items.

toxic imp
#

i have used radiant before

#

but it does not consist in my code

fathom laurel
#

oh, right. you already imported random.

toxic imp
#

but it is not in my code i did not add it anywhere

fathom laurel
#

for example, instead of py for i in range(3): for j in range(3):
you could try to check the cells in a random order.

#
options = [(i, j) for i in range(3) for j in range(3)]
random.shuffle(options)
for i, j in options:```
toxic imp
#

1 sec im chaning classes

celest mesaBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.