about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/downloads/simply/newttt.scm
blob: 368472ee6edb6e73e664db9d6c054c55f702d5e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;;; 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))) ))
org/International/">HTML Internationalization</a></li> <li><a href="http://www.w3.org/">WWW Consortium: home page</a></li> </ul> <h2>Help with HTML:</h2> <ul> <li><a href="http://www.htmlhelp.com/reference/html40/">HTML 4.0 Reference</a></li> <li><a href= "http://www.w3schools.com/html/default.asp">W3Schools</a></li> <li><a href="http://www.htmlgoodies.com/primers/html/">HTML Goodies</a></li> <li><a href="http://www.htmlcodetutorial.com/">HTML Code Tutorial</a></li> <li><a href= "http://www.simplehtmlguide.com/cheatsheet.php">HTML Cheat Sheet &ndash; A Simple Guide to HTML</a></li> </ul> <h2>HTML validation services:</h2> <ul> <li><a href="http://validator.w3.org/">W3C HTML Validation Service</a></li> <li><a href="http://www.htmlhelp.com/tools/validator/">WDG HTML Validator</a></li> </ul> <h2>Other browsing software:</h2> <ul> <li><a href="http://wget.addictivecode.org/">GNU wget</a> &mdash; powerful &amp; flexible non-interactive downloader</li> <li><a href="http://www.pavuk.org/">Pavuk</a> &mdash; powerful &amp; an even more-featured downloader</li> <li><a href="http://curl.haxx.se/">cURL</a> &mdash; non-interactive downloader which supports HTTPS</li> <li><a href="http://www.xach.com/snarf/">snarf</a> &mdash; small simple 1-file non-interactive downloader</li> </ul> <h2>Historical interest</h2> <ul> <li><a href= "http://web.archive.org/web/2005050785333/http://archive.ncsa.uiuc.edu/SDG/Software/Mosaic/MetaIndex.html"> NCSA Mosaic</a></li> </ul> <h2>Search engines:</h2> <p>These work with <strong>Lynx</strong> as of 2014/01/10:</p> <ul> <li><a href="http://www.ask.com/">Ask.com</a></li> <li><a href="http://www.baidu.com/">Baidu</a> (Chinese)</li> <li><a href="http://www.bing.com/">Bing</a></li> <li><a href="http://www.dogpile.com/">Dogpile</a></li> <li><a href="http://labs.goo.ne.jp/">goo</a> (Japanese)</li> <li><a href="http://www.google.com/">Google</a></li> <li><a href="http://hakia.com/">Hakia</a></li> <li><a href="http://www.icerocket.com/">IceRocket</a></li> <li><a href="http://www.indeed.com/">Indeed</a></li> <li><a href="http://www.lexxe.com/">Lexxe</a></li> <li><a href="http://www.rambler.ru/">Rambler</a> (Russian)</li> <li><a href="http://www.search.com/">Search.com</a></li> <li><a href="http://www.webcrawler.com/">WebCrawler</a></li> <li><a href="http://www.yahoo.com/">Yahoo!</a></li> </ul> </body> </html>