From c0c9dda25ea31a5d7320fe15facf83ef21134f5a Mon Sep 17 00:00:00 2001 From: nihilazo Date: Tue, 5 Apr 2022 14:58:30 +0100 Subject: [PATCH] changes for speed and getting things going for file writing --- gui.rkt | 1 - main.rkt | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gui.rkt b/gui.rkt index 6af8f28..e334928 100644 --- a/gui.rkt +++ b/gui.rkt @@ -69,5 +69,4 @@ (send frame show #t)) (define g (play-game (GameState (grid '() 6 6) 0 '(0 0) (list random-player random-player)))) -(print (GameState-grid g)) (analysis-gui g) \ No newline at end of file diff --git a/main.rkt b/main.rkt index 3c48e80..86606fa 100644 --- a/main.rkt +++ b/main.rkt @@ -26,6 +26,7 @@ ; Grid Number -> Line ; where the grid is the current board state, the Number is if the player is player 1 or 2, and it returns the move it will play that turn. ; name is the player's name. +; func can also be 0 (struct player (name func) #:transparent) ; size of one grid position in pixels @@ -52,6 +53,9 @@ (if (< x (- w 1)) (line (point x y) (point (+ x 1) y) 1) '()) (if (< y (- h 1)) (line (point x y) (point x (+ y 1)) 1) '()))))) w h)) +; stores the full grid +(define FULL-GRID (grid '() 0 0)) + ; Line Line -> Bool ; tests if two lines are in the same position (define (same-position? l1 l2) @@ -73,7 +77,7 @@ ; TODO optimise. This "filtering what is invalid out of all possible lines" method sucks. ; TODO write more tests (define (valid-moves g) - (filter (lambda (move) (valid-move? move g)) (grid-lines (full-grid (grid-width g) (grid-height g))))) + (filter (lambda (move) (valid-move? move g)) (grid-lines FULL-GRID))) ; Point Grid -> Number ; given a point that is the top-left corner of a square on the grid, returns the amount of edges surrounding that square. @@ -179,6 +183,7 @@ (define (play-game s) (let ([g (GameState-grid s)] [p (GameState-player s)]) + (set! FULL-GRID (full-grid (grid-width g) (grid-height g))) (cond [(= (length (grid-lines g)) (total-moves g)) s] ; end of the game when every possible line is played [else @@ -206,7 +211,7 @@ ; TODO color in squares (define (render-grid g dc) (define passed '()) - (for ([l (grid-lines g)]) ; reversed for fill-drawing malarkey. + (for ([l (grid-lines g)]) (if (empty? passed) (set! passed (list l)) (set! passed (append passed (list l)))) (cond [(= (line-player l) 0) (send dc set-pen "red" 4 'solid)] ; player 1 draws in red @@ -224,5 +229,4 @@ (+ 6 (* GRID-SCALE (point-x b))) (+ 3 (* GRID-SCALE (point-y b)))) 0)))) - (send dc draw-bitmap (grid-dots (grid-width g) (grid-height g)) 0 0)) ; overlay dot grid - + (send dc draw-bitmap (grid-dots (grid-width g) (grid-height g)) 0 0)) ; overlay dot grid \ No newline at end of file