Ask coding questions

← Back to all posts
QUESTION
h
JacobMcPherson1 (196)

Does anyone know a more efficient way to do my movement?

Answered by Coder100 (17136) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (17136)

Yes, very very much more efficient.

first, you have an array:

char[][] pos = {
  {' ',' ',' '},
  {' ','#',' '},
  {' ','#',' '},
};

and then you can just draw it with loops instead of trying to do every single case (this scales exponentially!!!!!!)

SixBeeps (5067)

@Coder100 Idk man, his method is O(1), whereas yours is O(n²) for a square board. Might wanna rethink your algorithm a little.

/s

Coder100 (17136)

alright fine
a flat array @SixBeeps

JacobMcPherson1 (196)

@Coder100 Uh, could you possibly explain in a little more detail?

Coder100 (17136)
foreach (char[] arr in pos) {
  foreach(char c in arr) {
    Console.Write(c);
  }
  Console.WriteLine();
}

@JacobMcPherson1