changes for speed and getting things going for file writing

This commit is contained in:
Nico 2022-04-05 14:58:30 +01:00
parent a9a34af605
commit c0c9dda25e
2 changed files with 8 additions and 5 deletions

View File

@ -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)

View File

@ -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