--- freecell.scm 2006-02-20 14:33:31.000000000 -0500 +++ /tmp/freecell.scm 2006-02-22 10:19:46.000000000 -0500 @@ -39,7 +39,6 @@ ;;; Code: -(use-modules (ice-9 threads)) ;; ;; Game Options @@ -367,7 +366,6 @@ (set! board-hash (make-hash-table hash-size)) - (start-hint-thread) (list 8 3.5) ) @@ -386,7 +384,6 @@ (else #f)))) (define (button-released start-slot card-list end-slot) - (kill-hint-thread) (and (not (= start-slot end-slot)) (cond @@ -396,7 +393,6 @@ ) (move-low-cards 0) ) - (start-hint-thread) ) (define (button-clicked slot) @@ -404,7 +400,6 @@ #f) (define (button-double-clicked slot) - (kill-hint-thread) (and (not (empty-slot? slot)) (let ((card (get-top-card slot))) @@ -416,7 +411,6 @@ ) ) ) - (start-hint-thread) ) ;; Condition for fail -- no more cards to move @@ -554,7 +548,7 @@ ; These constants affect the hash table and search algorithm (define hash-size (- (expt 2 17) 1)) ; A Mersenne prime (2^17 - 1) ~128k (define board-node-max 50) ; number of board positions to visit each time. -(define traverse-node-max 10000) ; prevents stack overflow +(define traverse-node-max 1000) ; prevents stack overflow ; These constants define values used in constructing the board value. (define weight-factor 100) ; effect of weight on final score @@ -576,16 +570,12 @@ (define visited-nodes 0) ; Number of board positions created for this search. (define traversed-nodes 0) ; Number of board positions traversed through -(define hint-return '()) ; The hint, updated by the hint thread -(define kill-thread #f) ; Tell the hint thread to die -(define kill-thread-mutex (make-mutex)) -(define hint-thread '()) ;;----------------------------------------------------------------------------- ;; Functions ; Returns the best move found by the search algorithm -(define (find-hint) +(define (get-hint) (if debug (display "get-hint\n")) (set! visited-nodes 0) (set! traversed-nodes 0) @@ -604,39 +594,6 @@ (display-best-move-trace board moves))) (create-help-list board moves)))) -; Start the hint thread on its way -(define (start-hint-thread) - (if debug (display "Starting hint thread\n")) - (set! hint-return (list 0 (_"No hint available right now"))) - (set! kill-thread #f) ; No locking, we haven't started the thread yet - (set! hint-thread - (begin-thread - (set! hint-return (find-hint))))) - -; Test the kill-thread flag -(define (kill-thread?) - (lock-mutex kill-thread-mutex) - (let ((result kill-thread)) - (unlock-mutex kill-thread-mutex) - result)) - -; Kill the hint thread and ignore the result -(define (kill-hint-thread) - (if debug (display "Killing hint thread\n")) - (lock-mutex kill-thread-mutex) - (set! kill-thread #t) ; Signal the kill - (unlock-mutex kill-thread-mutex) - (join-thread hint-thread)) ; and wait for the code to unwind - -; The hint callback. It stops the hint thread and gets the current best -; result. Note that the thread is not restarted since we let the hint code -; unwind and we would therefore have to start at the beginning. In practise -; the hint code is faster than the time it takes for the player to click the -; hint button so it doesn't matter. -(define (get-hint) - (kill-hint-thread) - hint-return) - ; Displays the sequence of best moves found so far by the search. (Debug only) ; Note that the best sequence is occasionally not available depending on ; how the hint function terminates the search. In these cases, this function @@ -736,8 +693,7 @@ (not (eq? (vector-ref (cdaar moves) index-outcome) outcome-lose))) ; Determine whether to traverse deeper, or to go back up the tree - (if (and (kill-thread?) - (eq? (vector-ref (cdaar moves) index-outcome) #f) + (if (and (eq? (vector-ref (cdaar moves) index-outcome) #f) (< visited-nodes board-node-max) (< traversed-nodes traverse-node-max) (>= (vector-ref (cdaar moves) index-value) prev-best))