summary refs log blame commit diff stats
path: root/README
blob: f978daf4750ed45416dbaf6a6dae2d59c7c473f3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11





                                                                      
                                                                    



                                                               
== Ranger v.1

Ranger is a filemanager that integrates well into the linux shell and
gives you a quick way of doing operations that would otherwise require
a lot of typing, without starting up a bloated environment.

Ranger is written in Python and uses ncurses for the user interface.

The version 1 is a rewrite from scratch and offers very limited
functionality as of now.
.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
;;; ttt.scm
;;; Tic-Tac-Toe program

(define (ttt position me)
  (one-okay-move (number-squares position) me))

(define (one-okay-move position me)
  (find-one (lambda (sq) (no-lose? (plug-in me sq position) me))
	    (free-squares position)))

(define (no-lose? position me)
  (cond ((already-lost? position me) #f)
	((already-won? position me) #t)
	(else (not (find-one (lambda (pos) (not (one-okay-move pos me)))
			     (extend position (opponent me)) )))))

(define (free-squares pos)
  (keep number? pos))

(define (number-squares pos)
  (ns-help pos 1))

(define (ns-help pos num)
  (cond ((empty? pos) "")
	((equal? (first pos) '_) (word num (ns-help (bf pos) (+ num 1))))
	(else (word (first pos) (ns-help (bf pos) (+ num 1)))) ))

(define (plug-in letter sq pos)
  (cond ((empty? pos) "")
	((= sq 1) (word letter (bf pos)))
	(else (word (first pos) (plug-in letter (- sq 1) (bf pos)))) ))

(define (find-one pred stuff)
  (cond ((empty? stuff) #f)
	((pred (first stuff)) (first stuff))
	(else (find-one pred (bf stuff))) ))

(define (extend pos who)
  (every (lambda (sq) (plug-in who sq pos))
	 (free-squares pos)))

(define (opponent letter)
  (if (equal? letter 'x) 'o 'x))

(define (already-won? pos me)
  (find-one (lambda (win) (match-win? pos me win))
	    '(yyynnnnnn nnnyyynnn nnnnnnyyy ynnynnynn nynnynnyn nnynnynny
			ynnnynnny nnynynynn)))

(define (already-lost? pos me)
  (already-won? pos (opponent me)))

(define (match-win? pos me win)
  (cond ((empty? win) #t)
	((equal? (first win) 'y)
	 (if (equal? (first pos) me)
	     (match-win? (bf pos) me (bf win))
	     #f))
	(else (match-win? (bf pos) me (bf win))) ))