From d39811d38e4fe4397130023d95c4406a0d7de41b Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Sun, 2 Jul 2023 23:55:20 -0700 Subject: [PATCH] Not entirely tested but I assume this is working... need tests lol --- gib-gab-gob/game.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gib-gab-gob/game.scm b/gib-gab-gob/game.scm index ccff0ce..65e66a3 100644 --- a/gib-gab-gob/game.scm +++ b/gib-gab-gob/game.scm @@ -5,6 +5,7 @@ #:use-module (goblins actor-lib sealers) #:use-module (goblins actor-lib selfish-spawn) #:use-module (ice-9 match) + #:use-module (srfi srfi-1) #:use-module (ice-9 rdelim) #:export (^ggg-controller)) @@ -62,3 +63,21 @@ (array->list x)) (format #t "\n")) board)) + +(define (board-winner? board mark) + (define idxs (iota ggg-size)) + (define (row-winner? y) + (apply eq? mark (map (lambda (x) (board-ref board (list x y))) idxs))) + (define (col-winner? x) + (apply eq? mark (map (lambda (y) (board-ref board (list x y))) idxs))) + (define (diag-winner?) + (or + (apply eq? mark (map (lambda (x) (board-ref board (list x x))) idxs)) + (apply eq? mark (map (lambda (x) (board-ref board (list x x))) idxs)))) + + (any (lambda (x) (eq? #t x)) + (cons + (diag-winner?) + (append + (map row-winner? idxs) + (map col-winner? idxs)))))