C
C#2mo ago
rigger

small issue

im making a game of tic tac toe but i have 0 idea as to how i implement the system that checks whether 3 crosses or zeroes have been added..
37 Replies
rigger
riggerOP2mo ago
No description
rigger
riggerOP2mo ago
No description
rigger
riggerOP2mo ago
here's the code
Buddy
Buddy2mo ago
I suggest you check the suggestion if you hover
No description
Buddy
Buddy2mo ago
= will set a variable to a value == will check whether something is equals to a value
rigger
riggerOP2mo ago
oooh yeah yeah youre right fixed it
Buddy
Buddy2mo ago
Also, you should not use semicolons after if-statements as that makes it ignore the if-statement, same with while-loops, etc.
rigger
riggerOP2mo ago
oh thank you do you know how i could add like an actual system of winning tic tac toe??? like i know theoretically i just check to see if 3 of the same value has been added in a row or in a column or diagonally but i dont actually know how to implement that
Buddy
Buddy2mo ago
Just check the neighbouring tiles or the whole board if it's small For such a small board, I'd just check the whole board
rigger
riggerOP2mo ago
so i just run a for loop that checks the entire board and um if it has the same value diagonally, horizontally or vertically that person wins? i mean i guess i can try it
Buddy
Buddy2mo ago
I assume this is homework?
rigger
riggerOP2mo ago
yeah... this is me attempting to not just copy from a youtube tutorial and do it myself
Buddy
Buddy2mo ago
I highly suggest to read the logic out loud for yourself That might make you understand what you are doing and what you are going to do to implement said thing
rigger
riggerOP2mo ago
alright
Buddy
Buddy2mo ago
Learning how to debug is the biggest and most helpful thing for a programmer $debug
MODiX
MODiX2mo ago
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Buddy
Buddy2mo ago
A debugger allows you to step through the code and inspect the values, and so much more
rigger
riggerOP2mo ago
mk mk
rigger
riggerOP2mo ago
so uh
No description
rigger
riggerOP2mo ago
i tried something but there r a lot of issues nvm this is horribly unoptimised and wont rlly work i rlly do need a tutorial
Buddy
Buddy2mo ago
Remember what I mentioned above No!! If you copy a tutorial blindly you will never learn
MODiX
MODiX2mo ago
Buddy
= will set a variable to a value == will check whether something is equals to a value
Quoted by
<@203166497198047232> from #small issue (click here)
React with ❌ to remove this embed.
rigger
riggerOP2mo ago
oh i forgot to add the == for the 0 part mb im trying a few different ways its just all rlly bad id have to manually check every single combination for every row and every column and then check for each diagonal combination and then repeat that for 0, after I do it for X
Benxy
Benxy2mo ago
Why? You don't need to be checking if every combination wins when there's only 1 piece being placed at a time
rigger
riggerOP2mo ago
oh how did i not think of that but wait how would the program know im going for a row and not a column evene if its only 1 piece at a time id still have to check for both right?? and in order to check for a row id have to check every row because there could be any piece in any of the three rows
Benxy
Benxy2mo ago
1 2 3 4 5 6 7 8 9 You place a piece in 8, what are the possible winning combinations?
rigger
riggerOP2mo ago
258 and 789 but like lets say i pick 8 on the first round then 5 then 2 havent the winning combinations now been opened up to every piece on the board??? because all the program knows is that there are values in each one
Benxy
Benxy2mo ago
456 isn't going to win as a result of placing ap iece on 2 no matter what the configuration of the board is, if 456 was a winner it would have won when the last piece out of 4, 5, or 6 was placed
rigger
riggerOP2mo ago
so only the last piece matters? if the last piece entered is, as an example, 1, i only check 147 and 123 i mean that might work but wouldnt it still be very cluttered? because each combination for each number would still take a very long time to check over manually even if there are only two yeah im gonna leave this for another day im literally losing sleep i started this at 1am and its 4am
Anton
Anton2mo ago
Time as in having to write the code for going through the row, the column and the diagonal? That's complexity inherent to the problem, you will have to write that code
rigger
riggerOP2mo ago
no time as in literally writing every single possible combination
Anton
Anton2mo ago
what combination?
rigger
riggerOP2mo ago
for every single position an X or an O could be in, it checks the 2 places next to it
Anton
Anton2mo ago
use a loop but yes that's right you need to do that maybe going by rows and by columns separately would be easier to think about
rigger
riggerOP2mo ago
ive tried a few but they all like required a minimum of like 20+ lines and well that would be fine but each line is riddled with errors that i dont know how to fix but idk i havent touched it since last night ill prob just restart
Anton
Anton2mo ago
well that's just a skill issue learn the basic syntax

Did you find this page helpful?