r3182: *** empty log message ***
[reversi.git] / edge-table-storage.lisp
1 ;;;;***************************************************************************
2 ;;;;
3 ;;;; FILE IDENTIFICATION
4 ;;;; 
5 ;;;;  Name:           edge-table-storage.lisp
6 ;;;;  Purpose:        Store precompiled edge table for reversi
7 ;;;;  Programer:      Kevin Rosenberg
8 ;;;;  Date Started:   1 Nov 2001
9 ;;;;
10 ;;;; $Id: edge-table-storage.lisp,v 1.2 2002/10/25 09:23:39 kevin Exp $
11 ;;;;
12 ;;;; This file is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; Reversi users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;;***************************************************************************
18
19 (in-package :reversi)
20
21 (eval-when (:compile-toplevel :load-toplevel :execute)
22
23   (defparameter *et-path* nil)
24
25   (if *load-truename*
26       (setq *et-path* (make-pathname
27                        :directory (pathname-directory *load-truename*)
28                        :host (pathname-host *load-truename*)
29                        :device (pathname-device *load-truename*)
30                        :name "edge-table"
31                        :type "dat"))
32     (setq *et-path* (make-pathname
33                      :directory '(:absolute "usr" "share" "common-lisp"
34                                             "source" "reversi" "data")
35                      :name "edge-table"
36                      :type "dat")))
37
38   (defun store-edge-table (et &optional (path *et-path*)) 
39     (with-open-file (stream path :direction :output
40                             :if-exists :supersede)
41       (print (length et) stream)
42       (dotimes (i (length et))
43         (print (aref et i) stream))))
44   
45   (defun load-edge-table (&optional (path *et-path*))
46     (when (probe-file path)
47       (with-open-file (stream path :direction :input)
48         (let* ((length (read stream))
49                (et (make-array length :element-type 'fixnum)))
50                       (dotimes (i length)
51                         (setf (aref et i) (read stream)))
52                       et))))
53   
54   (unless (probe-file *et-path*)
55     (store-edge-table (make-edge-table)))
56   
57   (unless *edge-table*
58     (setq *edge-table* (load-edge-table))))
59
60
61
62
63