aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-22 18:57:11 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-22 18:57:11 +0100
commitde129262cb640d18b85bf83abcdbdf7cf81381d0 (patch)
tree9314bc1cd7eeb65629ba668ab9c8753c2e982e01
parent582d78d60f43846f2beed6a6b9d17c8edf72115c (diff)
voerbak fix
-rwxr-xr-xapi/game/voerbakbin16624 -> 16624 bytes
-rw-r--r--api/game/voerbak.c18
-rw-r--r--console/v2.py33
3 files changed, 34 insertions, 17 deletions
diff --git a/api/game/voerbak b/api/game/voerbak
index e474172..595a610 100755
--- a/api/game/voerbak
+++ b/api/game/voerbak
Binary files differ
diff --git a/api/game/voerbak.c b/api/game/voerbak.c
index 5674f5e..0161726 100644
--- a/api/game/voerbak.c
+++ b/api/game/voerbak.c
@@ -10,16 +10,14 @@ void printBoard(int board[], int width, int height) {
fflush(stdout);
}
-int recursiveSolve(int board[], int width, int height, int pos, int checkFor, int direction, int currentLength) {
- int overflow = (pos % width) + direction;
- if (overflow == width || overflow == -1)
- return currentLength;
+int recursiveSolve(int board[], int width, int height, int pos, int checkFor, int direction, int d_index, int currentLength) {
int newPos = pos + direction;
- if (newPos < 0 || newPos > width * height - 1)
- return currentLength;
- if (board[newPos] != checkFor)
- return currentLength;
- return recursiveSolve(board, width, height, newPos, checkFor, direction, currentLength + 1);
+ if (newPos > width * height - 1 || newPos < 0) return currentLength;
+ int row = pos % width;
+ if (row == width && d_index >= 1 && d_index <= 3) return currentLength;
+ if (row == 0 && d_index >= 5 && d_index <= 7) return currentLength;
+ if (board[newPos] != checkFor) return currentLength;
+ return recursiveSolve(board, width, height, newPos, checkFor, direction, d_index, currentLength + 1);
}
bool checkWin(int board[], int width, int height, int pos) {
@@ -36,7 +34,7 @@ bool checkWin(int board[], int width, int height, int pos) {
int values[8];
for (int i = 0; i < 8; i++)
- values[i] = recursiveSolve(board, width, height, pos, board[pos], directions[i], 0);
+ values[i] = recursiveSolve(board, width, height, pos, board[pos], directions[i], i, 0);
int joinedValues[4] = {
values[0] + values[4],
diff --git a/console/v2.py b/console/v2.py
index 16fae64..69e61aa 100644
--- a/console/v2.py
+++ b/console/v2.py
@@ -1,5 +1,6 @@
from colorama import Fore
import os
+import time
DISC_SHAPE = "o"
DISC_A = Fore.RED + DISC_SHAPE + Fore.RESET
@@ -60,6 +61,26 @@ class bord:
self.board[end_pos] = "x"
return won
+ def debug(self, pos):
+ self.board[pos] = "x"
+ directions = [
+ self.width, # 0: north
+ self.width + 1, # 1: northeast
+ 1, # 2: east
+ -self.width + 1, # 3: southeast
+ -self.width, # 4: south
+ -self.width - 1, # 5: southwest
+ -1, # 6: west
+ self.width - 1, # 7: northwest
+ ]
+
+ for index, direction in enumerate(directions):
+ new_position = pos + direction
+ if new_position > len(self.board) - 1 or new_position < 0: continue
+ if index in range(1, 4) and pos % self.width == self.width -1: continue
+ if index in range(5, 8) and pos % self.width == 0: continue
+ self.board[new_position] = "o"
+
def drop_fisje(self, column, disc):
for row in range(self.height):
pos = column + row * self.width
@@ -72,14 +93,12 @@ class bord:
def main():
disc_a = True
gert = bord(7, 6)
- while True:
+ for x in range(len(gert.board)):
+ gert = bord(7, 6)
+ gert.debug(x)
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
+ print("\n\n", end='')
+ time.sleep(0.1)
if __name__ == "__main__":
main()