diff options
Diffstat (limited to 'console')
| -rw-r--r-- | console/test.py | 24 | ||||
| -rw-r--r-- | console/voerbak.c | 2 | ||||
| -rw-r--r-- | console/voerbak_connector.py | 48 | 
3 files changed, 74 insertions, 0 deletions
| diff --git a/console/test.py b/console/test.py new file mode 100644 index 0000000..8cc1db9 --- /dev/null +++ b/console/test.py @@ -0,0 +1,24 @@ +import subprocess + +w = 7 +h = 6 +column = 3 + +process = subprocess.Popen(["./voerbak"], +        stdin=subprocess.PIPE, +        stdout=subprocess.PIPE, +        stderr=None) + +process.stdin.write(bytearray(f"{w} {h}\n", "utf-8")) +process.stdin.flush() + +process.stdin.write(bytearray(f"{column}\n", "utf-8")) +process.stdin.flush() + +# process.stdin.write(b"0\n") +# process.stdin.flush() +# for c in iter(lambda: process.stdout.read(1), b''): +#     sys.stdout.write(c) + +print(process.stdout.readlines(5)) + diff --git a/console/voerbak.c b/console/voerbak.c index a7807b6..4ee20e4 100644 --- a/console/voerbak.c +++ b/console/voerbak.c @@ -11,6 +11,7 @@ void printBoard(int board[], int width, int height) {  	for (int i = 0; i < width * height; i++)  		printf("%d", board[i]);  	printf("\n"); +	fflush(stdout);  }  void printHumanBoard(int board[], int width, int height) { @@ -71,6 +72,7 @@ bool checkWin(int board[], int width, int height, int pos) {  			int start_pos = pos + directions[i+0] * values[i+0];  			int end_pos =   pos + directions[i+4] * values[i+4];  			printf("w:%d-%d\n", start_pos, end_pos); +			fflush(stdout);  		}  	} diff --git a/console/voerbak_connector.py b/console/voerbak_connector.py new file mode 100644 index 0000000..b300af0 --- /dev/null +++ b/console/voerbak_connector.py @@ -0,0 +1,48 @@ +from colorama import Fore +import subprocess +import os + +DISC_SHAPE = "o" +DISC_A = Fore.RED + DISC_SHAPE + Fore.RESET +DISC_B = Fore.BLUE + DISC_SHAPE + Fore.RESET +EMPTY = Fore.LIGHTBLACK_EX + "_" + Fore.RESET + +class bord: +    def __init__(self, w, h): +        self.width = w +        self.height = h +        self.process = subprocess.Popen(["./voerbak"], +                stdin=subprocess.PIPE, +                stdout=subprocess.PIPE, +                stderr=subprocess.PIPE) +        msg = bytearray(f"{w} {h}\n", "utf-8") +        print({"msg": msg}) +        self.process.stdin.write(msg) +        self.process.stdin.flush() + +    # def print(self): +    #     for y in range(self.height -1, -1, -1): +    #         for x in range(self.width): +    #             print(self.board[x + y * self.width], end="  ") +    #         print("\n", end="") + +    def drop_fisje(self, column): +        msg = bytearray(f"{column}\n", "utf-8") +        print({"msg": msg}) +        self.process.stdin.write(msg) +        self.process.stdin.flush() + +def main(): +    gert = bord(7, 6) +    while True: +        # gert.print() +        column = int(input("column?: ")) - 1 +        if column not in range(gert.width): +            continue +        # os.system("clear") +        gert.drop_fisje(column) +        print(gert.process.stdout.readline()) + +if __name__ == "__main__": +    main() + |