C
C#5d ago
rigamortus

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
rigamortus
rigamortusOP5d ago
No description
rigamortus
rigamortusOP5d ago
No description
rigamortus
rigamortusOP5d ago
here's the code
Buddy
Buddy5d ago
I suggest you check the suggestion if you hover
No description
Buddy
Buddy5d ago
= will set a variable to a value == will check whether something is equals to a value
rigamortus
rigamortusOP5d ago
oooh yeah yeah youre right fixed it
Buddy
Buddy5d ago
Also, you should not use semicolons after if-statements as that makes it ignore the if-statement, same with while-loops, etc.
rigamortus
rigamortusOP5d 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
Buddy5d 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
rigamortus
rigamortusOP5d 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
Buddy5d ago
I assume this is homework?
rigamortus
rigamortusOP5d ago
yeah... this is me attempting to not just copy from a youtube tutorial and do it myself
Buddy
Buddy5d 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
rigamortus
rigamortusOP5d ago
alright
Buddy
Buddy5d ago
Learning how to debug is the biggest and most helpful thing for a programmer $debug
MODiX
MODiX5d 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
Buddy5d ago
A debugger allows you to step through the code and inspect the values, and so much more
rigamortus
rigamortusOP5d ago
mk mk
rigamortus
rigamortusOP5d ago
so uh
No description
rigamortus
rigamortusOP5d 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
Buddy5d ago
Remember what I mentioned above No!! If you copy a tutorial blindly you will never learn
MODiX
MODiX5d 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.
rigamortus
rigamortusOP5d 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
Benxy5d ago
Why? You don't need to be checking if every combination wins when there's only 1 piece being placed at a time
rigamortus
rigamortusOP5d 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
Benxy5d ago
1 2 3 4 5 6 7 8 9 You place a piece in 8, what are the possible winning combinations?
rigamortus
rigamortusOP5d 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
Benxy5d 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
rigamortus
rigamortusOP5d 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
Anton5d 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
rigamortus
rigamortusOP4d ago
no time as in literally writing every single possible combination
Anton
Anton4d ago
what combination?
rigamortus
rigamortusOP4d ago
for every single position an X or an O could be in, it checks the 2 places next to it
Anton
Anton4d 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
rigamortus
rigamortusOP4d 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
Anton4d ago
well that's just a skill issue learn the basic syntax

Did you find this page helpful?