-
Notifications
You must be signed in to change notification settings - Fork 0
/
F1&F2-ImmersiveFuncts.rkt
114 lines (91 loc) · 3.74 KB
/
F1&F2-ImmersiveFuncts.rkt
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(require racket/trace)
;;; immersion version of replace indicies
(define (replace-indices lst ind ele)
( define (replace-indicesI lst ind ele acc str max) ;;recursivly compares whether the index of the car of lst equals to the car of the ind var
(cond
[(and (empty? lst) (empty? ind) ) ;; break point : if the lst is empty and the ind list is empty
(string->list str) ;; converts the str to list
]
[(and (not(equal? acc max)) (empty? ind) ) ;;; this case insures that even when ind is empty the func will continue to add "*" char
(replace-indicesI (rest lst) '() ele (+ acc) (string-append str (string(car lst))) max) ;; calls func again with cdr of lst and empty ind
]
[(equal? acc (car ind)) ;; if the counter (acc) is equal to the car of ind then the ele is appended to the str var
(replace-indicesI (rest lst) (cdr ind) ele (+ acc 1) (string-append str (string ele)) max) ;; function is called with the cdr of lst and ind
]
[else ;; function is called with the cdr of lst and ind
(replace-indicesI (rest lst) ind ele (+ acc 1) (string-append str (string(car lst))) max)
]
)
)
(trace replace-indicesI)
;;; extra arguments : 0 (counter/acc) "" (string where the final output is stored) length of list (the maximum ammount of times the function should reccur)
(replace-indicesI lst ind ele 0 "" (length lst))
)
;;(replace-indices '(#\a #\* #\* ) '(1 2) #\b)
;;(replace-indices '(#\a #\* #\* #\a ) '(1 2) #\b)
;;(replace-indices '(#\a #\* #\* #\a ) '(1 2 3) #\b)
;;; immersive function of find word to guess
(define glossary '("woard" "anot" " Staat" "otahe" "suaare"))
(define word-to-guess null)
(define (findwtg wrdlist) ;; remade
(define (findwtgI wrdlist rndind acc wrd)
(cond
[(not(empty? wrd)) ;;; if word contains a value then return that value
(string->list wrd)
]
[(equal? acc rndind) ;; if acc is the same value as the random number then pass the car of the list into wrd
(findwtgI wrdlist 0 0 (car wrdlist))
]
[else
(findwtgI (cdr wrdlist) rndind (+ acc 1) null) ;; add 1 to acc and pass cdr through the reccured function
]
)
)
;;; extra arguments : wrdlist (glossary) rndind (random number in the range of the length of the glossary) acc (counter) wrd (a null value to be set to the final output)
(findwtgI wrdlist (random (length glossary)) 0 null)
)
(set! word-to-guess(findwtg glossary))
;;word-to-guess
;;; immersive function of findind
(define indexlst null)
(define (findind char lst)
(define (findindI char lst acc indlst)
(cond
[(equal? (length lst) 0)
indlst
]
[(equal? (car lst) char)
(findindI char (cdr lst) (+ acc 1) (append indlst (list acc)))
]
[else
(findindI char (cdr lst) (+ acc 1) indlst)
]
)
)
(findindI char lst 0 '())
)
(set! indexlst (findind #\a word-to-guess ))
indexlst
;;; immersive function of solve
(define (solve word) ;;; CURRENTLY NOT WORKING
(define (solveI word acc guessedwrd wtg)
(cond
[(equal? acc (length word-to-guess))
(game-status)
]
[(equal? (car guessedwrd) (car wtg))
(solveI word (+ acc 1) (cdr guessedwrd)(cdr wtg))
]
[else
(game-status)
]
)
)
(solveI word 0 (string->list word) word-to-guess)
)
(display word-to-guess)
(guess #\a)
(guess #\b)
(guess #\c)
(guess #\d)
(guess #\e)