diff --git a/gui.rkt b/gui.rkt index e334928..d33a0bc 100644 --- a/gui.rkt +++ b/gui.rkt @@ -68,5 +68,5 @@ [label (format "Final Score: R: ~a, B: ~a" (first (GameState-scores game)) (last (GameState-scores game)))])) (send frame show #t)) -(define g (play-game (GameState (grid '() 6 6) 0 '(0 0) (list random-player random-player)))) +(define g (load-game! "/tmp/test.dbn")) (analysis-gui g) \ No newline at end of file diff --git a/main.rkt b/main.rkt index 3e351d6..f313b7b 100644 --- a/main.rkt +++ b/main.rkt @@ -17,7 +17,7 @@ ; represents the state of a game in play ; grid is the grid -; player is the current player +; player is the current player (ignored when the game is over) ; scores is a list of numbers for the score of each player. ; players is a list of two players who are playing in the game (struct GameState (grid player scores players) #:transparent) @@ -255,4 +255,23 @@ (lines (unquote (for/list ([l (grid-lines g)]) (list (point-x (line-from l)) (point-y (line-from l)) (point-x (line-to l)) (point-y (line-to l)) (line-player l))))))) f) - (close-output-port f))) \ No newline at end of file + (close-output-port f))) + +; path -> GameState +; loads a game from a .dbn file into a GameState structure +; TODO lines, scores, etc +(define (load-game! p) + (let* ([f (open-input-file p)] + [data (read f)]) + (close-input-port f) + (GameState + (grid + (for/list ([i (last (assoc 'lines data))]) + (line (point (first i) (second i)) (point (third i) (fourth i)) (fifth i))) + (second (assoc 'grid data)) (last (assoc 'grid data))) + 0 ; assumed, the game is over + (list (second (assoc 'score data)) (last (assoc 'score data))) + `( + ,(player (last (assoc 'player0 data)) 0) + ,(player (last (assoc 'player1 data)) 0) + ))))