From b2a03b851ccf5d4d2f17b88c98c2fc6feb10e715 Mon Sep 17 00:00:00 2001 From: Ewen Date: Fri, 22 Sep 2023 07:24:53 +0200 Subject: [PATCH] wip --- .../src/routes/ma_chaeliou/[id]/+page.svelte | 4 +-- grids/models.py | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/ma_chaeliou/[id]/+page.svelte b/frontend/src/routes/ma_chaeliou/[id]/+page.svelte index 4076581..ae0a204 100644 --- a/frontend/src/routes/ma_chaeliou/[id]/+page.svelte +++ b/frontend/src/routes/ma_chaeliou/[id]/+page.svelte @@ -18,8 +18,8 @@ height: "", }, validationSchema: yup.object().shape({ - width: yup.number().positive().moreThan(0), - heigt: yup.number().positive().moreThan(0), + width: yup.number().positive().moreThan(3), + heigt: yup.number().positive().moreThan(3), }), onSubmit: (values) => { submitPopulate(values); diff --git a/grids/models.py b/grids/models.py index ba2f6d4..a4ebe1a 100644 --- a/grids/models.py +++ b/grids/models.py @@ -12,6 +12,29 @@ class Word(models.Model): level = models.ForeignKey(Level, on_delete=models.CASCADE, related_name="words") +def place_word(width, height, placements, words): + # Base case + if placements == []: + return + + # Other cases + else: + return + + +# Helper functions +def get_case(width, height, placements, x, y): + # todo + return None + + +def print_grid(width, height, placements): + for i in range(0, height): + for j in range(0, width): + print(i, j) + print + + class Grid(models.Model): level = models.ForeignKey(Level, on_delete=models.CASCADE, related_name="grids") words = models.ManyToManyField(Word, through="Placement") @@ -27,10 +50,16 @@ class Grid(models.Model): print(self.width) print(self.height) + tmp_placements = [] + + place_word(self.width, self.height, tmp_placements, Word.objects.all()) + class Direction: RIGHT = 1 BOTTOM = 2 + RIGHT_BOTTOM = 3 + BOTTOM_RIGHT = 4 class Placement(models.Model):