From df5909c22a771851ba73a42975f42fab9c7541af Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 13 Feb 2021 11:31:42 +0100 Subject: v2 -> voerbak in c --- .gitignore | 3 +++ console/input | 14 ++++++++++++++ console/v2.py | 2 ++ console/voerbak.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 console/input create mode 100644 console/voerbak.c diff --git a/.gitignore b/.gitignore index 3bb937a..67119f3 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ node_modules/ # next.js .next/ +# voerbak +console/voerbak + diff --git a/console/input b/console/input new file mode 100644 index 0000000..1243fe0 --- /dev/null +++ b/console/input @@ -0,0 +1,14 @@ +7 6 +4 +3 +3 +2 +1 +2 +2 +7 +1 +7 +1 +7 +1 diff --git a/console/v2.py b/console/v2.py index 6531fff..16fae64 100644 --- a/console/v2.py +++ b/console/v2.py @@ -75,6 +75,8 @@ def main(): while True: gert.print() column = int(input("column?: ")) - 1 + if column not in range(gert.width): + continue os.system("clear") gert.drop_fisje(column, DISC_A if disc_a else DISC_B) disc_a = not disc_a diff --git a/console/voerbak.c b/console/voerbak.c new file mode 100644 index 0000000..4eeabc5 --- /dev/null +++ b/console/voerbak.c @@ -0,0 +1,35 @@ +#include +#include + +#define DISC_A "\x1b[31mo\x1b[39m" +#define DISC_B "\x1b[34mo\x1b[39m" +#define EMPTY "\x1b[90m_\x1b[39m" + +void printBoard(int board[], int width, int height) { + for (int y = height - 1; y > -1; y--) { + for (int x = 0; x < width; x++) { + int val = board[x + y * width]; + char *print = + val == 0 ? EMPTY : + val == 1 ? DISC_A : + val == 2 ? DISC_B : + EMPTY; + printf("%s ", print); + } + printf("\n"); + } +} + +int main() { + int width, height; + scanf("%d %d", &width, &height); + + int board[width * height]; + memset(board, 0, sizeof board); + + board[2] = 1; + board[3] = 2; + printBoard(board, width, height); + + return 0; +} -- cgit v1.2.3