make save-game function use a file, consistentize terminology

This commit is contained in:
Nico 2022-04-05 22:23:56 +01:00
parent 087fec0cdd
commit d9d7a6ab49
1 changed files with 5 additions and 5 deletions

View File

@ -77,7 +77,7 @@
; 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.
(define (count-square p g)
(define (count-box p g)
; explanation:
; for every item in the grid (g), test it against every edge of the box for equality. if any are equal, it matches.
; then only those that match are kept and this list is checked for length to determine the matching lines.
@ -170,7 +170,7 @@
(let
([boxes (boxes-for l gr)]
[g (append-move gr l)])
(length (filter (lambda (b) (= (count-square b g) 4)) boxes))))
(length (filter (lambda (b) (= (count-box b g) 4)) boxes))))
; Grid -> Number
; returns the total amount of moves possible for grid g.
@ -227,7 +227,7 @@
(+ 4 (* GRID-SCALE (point-y (line-to l))))) ; draw the line
(let ([boxes (boxes-for l g)])
(for ([b boxes])
(if (= (count-square b (grid passed (grid-width g) (grid-height g))) 4)
(if (= (count-box b (grid passed (grid-width g) (grid-height g))) 4)
(send dc draw-text
(if (= (line-player l) 0) "R" "B")
(+ 6 (* GRID-SCALE (point-x b)))
@ -235,11 +235,11 @@
0))))
(send dc draw-bitmap (grid-dots (grid-width g) (grid-height g)) 0 0)) ; overlay dot grid
; GameState !
; GameState path !
; saves a game into the .dbn file format that I just made up.
; don't worry, it's sexpy.
; TODO write loader
(define (save-game s filename)
(define (save-game! s filename)
(let ([g (GameState-grid s)]
[f (open-output-file filename)])
(pretty-write