#UTTT with AI
67 messages · Page 1 of 1 (latest)
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
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?
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?
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?
do you have a set of moves to play to encounter your error?
terrible AI. doesn't win when it can
Well not really since the AI is decide's the next move and I can't really encounter that as of now
ya your logic is busted
bro I just coded the AI, I'll improve it later
gotta get the basics correct first
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
o shi yeah
where'd you find this btw? is it just the padding thing in inspect element?
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"?
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
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
OHHH
actually maybe after makeMove()?
perhaps. let me try
or where you already have a comment on line 393 🙃
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.
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.
ah, that's a good idea. Sure I can do that.
would you want that for the human player too or just the AI?
doesn't hurt to do it for both
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
Don't worry, I will change all of those later, for now I'm just finding bugs in the program and trying to address them
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.
Faackk, ig in the mean time I might as well change functions and variable names
Actually nah I'll just find more bugs lmao
Surely you try to grok this later tho
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.
Ah all good, yeah Ill try to add conditions to the "debugger" as well
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?
Right I see
Um U reacted with a thumbs down 🤔?
no need for classes
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
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.
Hmm so what could be a solution to this? Changing the webroot? And also the .. ?
move "src" inside "public" (and rename it to "js" or something more appropriate)
and yes, remove the ..
yep it worked. 2 things-
- is the name "public" fine or would you recommend to change that as well?
- does the code look more clean and organised now?
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.
alright cool, thank u so much again bud