C
C#10mo ago
wolf 301

needing help for a console game

https://paste.mod.gg/eovangifthsv/0 in this code m is a solution i used for debugging so that it prints the point of the code it reaches, but it reaches only the m = 3 step. a person told me to use a debugging tool but i don't know what that is
BlazeBin - eovangifthsv
A tool for sharing your source code with the world!
35 Replies
Pobiega
Pobiega10mo ago
What do you code in? VS? Rider?
wolf 301
wolf 301OP10mo ago
VS
Pobiega
Pobiega10mo ago
No description
Pobiega
Pobiega10mo ago
see that white dot? hover your mouse in that location on the line you want to pause the code at click it. it will turn red and stay there
wolf 301
wolf 301OP10mo ago
i don't have any dot
No description
Pobiega
Pobiega10mo ago
next time you run your code in debug mode (see below) the execution of your program will pause at that location
No description
wolf 301
wolf 301OP10mo ago
oh now i see it
Pobiega
Pobiega10mo ago
No description
Pobiega
Pobiega10mo ago
should look like this you can have as many of these as you want
wolf 301
wolf 301OP10mo ago
if you use different dots what do they do?
Pobiega
Pobiega10mo ago
same thing: the code will stop at that point
wolf 301
wolf 301OP10mo ago
one stops the program, the others?
Pobiega
Pobiega10mo ago
they all do but they dont "stop" stop it they halt it
wolf 301
wolf 301OP10mo ago
ok gotcha
Pobiega
Pobiega10mo ago
you can resume, or step stepping is SUPER POWERFUL it lets you move one statement at a time and see exactly what your code does, and what variables change to what values etc as you go
wolf 301
wolf 301OP10mo ago
using the m i found anyway where the code stops working i just don't know what's the problem i guess it's something with the switch
Pobiega
Pobiega10mo ago
your switch only has one case so uh I dont see what else it would do?
wolf 301
wolf 301OP10mo ago
i wanted to add the second one later on
Pobiega
Pobiega10mo ago
btw, I highly suggest you invert your code what you have now is unreadable as hell
wolf 301
wolf 301OP10mo ago
it doesn't work with the first one in the first place invert? wdym?
Pobiega
Pobiega10mo ago
1 sec
wolf 301
wolf 301OP10mo ago
yeah sure
Pobiega
Pobiega10mo ago
public void MovePiece(int startingColumn, int startingRow, string leftRightDirection, string upDownDirection)
{
if ((startingRow >= 8 || startingRow <= -1) || (startingColumn >= 8 || startingColumn <= -1))
{
return;
}

if (grid[startingRow, startingColumn] == 0)
{
return;
}

if ((!player1turn || (grid[startingRow, startingColumn] <= 0)) &&
(player1turn || (grid[startingRow, startingColumn] >= 0)))
{
return;
}

switch (Math.Abs(grid[startingRow, startingColumn]))
{

case 1:
if (grid[startingRow, startingColumn] < 0)
{
if (leftRightDirection == "Right" && startingColumn < 7)
{
grid[startingRow - 1, startingColumn + 1] = grid[startingRow, startingColumn];
grid[startingRow, startingColumn] = 0;
}
else if (leftRightDirection == "Left" && startingColumn > 0)
{
grid[startingRow - 1, startingColumn - 1] = grid[startingRow, startingColumn];
grid[startingRow, startingColumn] = 0;
}
}
break;
}
}
public void MovePiece(int startingColumn, int startingRow, string leftRightDirection, string upDownDirection)
{
if ((startingRow >= 8 || startingRow <= -1) || (startingColumn >= 8 || startingColumn <= -1))
{
return;
}

if (grid[startingRow, startingColumn] == 0)
{
return;
}

if ((!player1turn || (grid[startingRow, startingColumn] <= 0)) &&
(player1turn || (grid[startingRow, startingColumn] >= 0)))
{
return;
}

switch (Math.Abs(grid[startingRow, startingColumn]))
{

case 1:
if (grid[startingRow, startingColumn] < 0)
{
if (leftRightDirection == "Right" && startingColumn < 7)
{
grid[startingRow - 1, startingColumn + 1] = grid[startingRow, startingColumn];
grid[startingRow, startingColumn] = 0;
}
else if (leftRightDirection == "Left" && startingColumn > 0)
{
grid[startingRow - 1, startingColumn - 1] = grid[startingRow, startingColumn];
grid[startingRow, startingColumn] = 0;
}
}
break;
}
}
instead of nesting 3 ifs, you can just invert the if and return this keeps indentation levels down and makes it easier to see whats going on
wolf 301
wolf 301OP10mo ago
why should you return nothing?
Pobiega
Pobiega10mo ago
it stops the method look at your current code, this does the exact same thing except it doesnt have 4 levels of nested ifs
wolf 301
wolf 301OP10mo ago
okk ty i’ll study this
Pobiega
Pobiega10mo ago
good as for why your code doesnt work.. use the debugger to go through the execution and see where it goes the wrong way
wolf 301
wolf 301OP10mo ago
okk thank you dude also, what’s “indendation levels”? i am not british/american as you can guess
Pobiega
Pobiega10mo ago
No description
Pobiega
Pobiega10mo ago
these vertical lines indicate an indentation level it gets really hard to read code when its ~10 levels indented
wolf 301
wolf 301OP10mo ago
makes sense, thank you again so basically if those conditions are not satisfied the code stops, if instead they do the code runs the last statement
Pobiega
Pobiega10mo ago
yeah, code is very straight forward it will do what you ask. so if you instead of saying...
if a
if b
if c
if d
if a
if b
if c
if d
you can say
if not a: stop
if not b: stop
if not c: stop
if not d: stop
if not a: stop
if not b: stop
if not c: stop
if not d: stop
wolf 301
wolf 301OP10mo ago
gotcha seems much better @Pobiega after debugging i found out that the value of the element in the array becomes 0 before the switch statement i don't get how tho
wolf 301
wolf 301OP10mo ago
https://paste.mod.gg/vsipyolkpise/0 i stopped the code after every console.writeline function in the MovePiece() function
BlazeBin - vsipyolkpise
A tool for sharing your source code with the world!
wolf 301
wolf 301OP10mo ago
using "1" and "7" as the column index and row index this is the output 10101010 01010101 10101010 00000000 00000000 0-10-10-10-1 -10-10-10-10 0-10-10-10-1 1 1 0 10101010 01010101 10101010 00000000 00000000 0-10-10-10-1 -10-10-10-10 0-10-10-10-1 and you can see it's 1 two times and then it becomes 0
Want results from more Discord servers?
Add your server