#UTTT with AI

67 messages · Page 1 of 1 (latest)

remote briar
#

you assign a value to boardIndex inside your forEach(). it is not in scope of the overall timeout. that said, boadIndex is not used anywhere else in the timeout, so 🤷🏼‍♂️

remote briar
#

re-read my comment. boardIndex only exists inside the forEach()

#

why do you need to use it outside of the forEach()? you aren't trying to in the code you've shown

#

essentially the error makes no sense with the code you've shown

leaden arrow
#

still not very clear , as in are trying to say that boardIndex needs to be used outside the forEach as well? if you can provide an example on how and what needs to be done..it'd be more clear to me

#

another thing- regarding this issue... is the debugger statement even in the correct spot?

remote briar
#

I'm saying you should not be getting that error message with the code you've shown. maybe show exactly where you added debugger and any other changes you made.

#

obligitory forEach() is bad, use for..of instead

#

okay, the boardIndex is not defined error has nothing to do with the debugger. the error also doesn't make sense at all. what else did you change?

leaden arrow
#

nothing else, i can assure you that.

#

also I just wanted to know, did you understand my initial issue or would you like me to explain it with an example?

remote briar
#

do you have a set of moves to play to encounter your error?

#

terrible AI. doesn't win when it can

leaden arrow
remote briar
#

ya your logic is busted

leaden arrow
#

gotta get the basics correct first

remote briar
#

I'm not about to reverse engineer your entire code base, but that doesn't look like the correct place to fix this. you are incorrectly setting the "next board" to a board that has already been won.

#

your giant O's are also overlapping other boards so you won't be able to click some cells

leaden arrow
#

o shi yeah

leaden arrow
# remote briar

where'd you find this btw? is it just the padding thing in inspect element?

remote briar
#

yes

#

looked at the element when I couldn't click on the cells below it

#
  // never see this run
  if (wonLargeBoardsX[boardIndex] || wonLargeBoardsO[boardIndex]) {
    nextBoardIndex = -1;
    return;
  }

why does that say "never see this run"?

leaden arrow
#

oh because I had an issue with that block of code before and I had put the comment and then after I fixed it..kinda forgot to remove the comment

remote briar
#
    if (!wonLargeBoardsX[cellIndex] && !wonLargeBoardsO[cellIndex] && gameActive) {
      nextBoardIndex = cellIndex;
    } else {
      nextBoardIndex = -1;
    }

that is the logic you need to copy to the ai move. you are not setting nextBoardIndex to -1 when the board at cellIndex is already won

#

at around line 358 is where you need to add it

leaden arrow
#

OHHH

remote briar
#

actually maybe after makeMove()?

leaden arrow
#

perhaps. let me try

remote briar
#

or where you already have a comment on line 393 🙃

leaden arrow
#

just tried at line 393, didn't resolve the issue..

#

I think I have to replace the code at line 370

#

yep that fixed the issue

#

thank you so much brother

#

and I'll definately take the suggestions you provided in consideration. will fix the giant O stuff now.

remote briar
#

just a UX thing, but it might be useful to somehow highlight the last cell that was played. right now it's hard to tell where the AI player clicked. changing the color or background color of the "last" cell might be nice.

leaden arrow
#

ah, that's a good idea. Sure I can do that.

#

would you want that for the human player too or just the AI?

remote briar
#

doesn't hurt to do it for both

remote briar
#

have not looked, but it sounds like you aren't cancelling the timeout I saw previously.

#

guess not. this code is ridiculous though. please fix your function names. how is anybody supposed to know what these do? checkForWin, checkForOverallWin, checkOverallGameWinner

leaden arrow
remote briar
#

fair enough but I'm far too lazy to try to grok all this, especially with poorly named variables/functions. so, no clue what you're missing.

leaden arrow
#

Faackk, ig in the mean time I might as well change functions and variable names

#

Actually nah I'll just find more bugs lmao

leaden arrow
remote briar
#

probably not. I have my own code to write. add some console.log() messages in key places (or use debuger) to determine what's going on.

leaden arrow
#

Ah all good, yeah Ill try to add conditions to the "debugger" as well

remote briar
#

i.e. is checkForOverallWin() ever being run? if so, what are the values of isXWinner and isOWinner? is it run before whatever sets the other message?

leaden arrow
#

Right I see

leaden arrow
#

Um U reacted with a thumbs down 🤔?

remote briar
#

no need for classes

leaden arrow
#

Ok, what about if I do without classes

#

Just confused how do I actually move the stuff out of the file and what stuff do I leave in script.js

remote briar
#

didn't I point you to docs on modules already?

remote briar
#

IMO, a "src" directory shouldn't be "published" (shouldn't be visible to users). Code in "src" is typical something that needs to be compiled/transpiled before it's usable on the web.

#

the reason it's failing for you is because you put "src" a level below "public", yet you're sharing "public" as the webroot.

#

essentially, you're at / but trying to go up a directory to ... this is not possible.

leaden arrow
#

Hmm so what could be a solution to this? Changing the webroot? And also the .. ?

remote briar
#

move "src" inside "public" (and rename it to "js" or something more appropriate)

#

and yes, remove the ..

leaden arrow
#

yep it worked. 2 things-

  1. is the name "public" fine or would you recommend to change that as well?
  2. does the code look more clean and organised now?
remote briar
#

public is fine. you haven't pushed any changes so I have no idea where you landed, but don't worry about clean/organised for now.

leaden arrow
#

alright cool, thank u so much again bud