Solution of Nevzat Onur DOMANIC
(define (cnt s hand)
(count
(keep
(lambda (x) (equal? (first x) s))
hand)
)
)
(define (count_s hand) (cnt 's hand))
(define (count_h hand) (cnt 'h hand))
(define (count_d hand) (cnt 'd hand))
(define (count_c hand) (cnt 'c hand))
(define (calc_points c hand)
(cond
((equal? (last c) 'a) 4)
((equal? (last c) 'k)
(if (> (cnt (first c) hand) 1) 3 0)
)
((equal? (last c) 'q)
(if (> (cnt (first c) hand) 2) 2 0)
)
((equal? (last c) 'j)
(if (> (cnt (first c) hand) 3) 1 0)
)
(else 0)
)
)
(define (balanced? hand)
(and
(or (> (count_s hand) 2) (= (count_s hand) 0))
(or (> (count_h hand) 2) (= (count_h hand) 0))
(or (> (count_d hand) 2) (= (count_d hand) 0))
(or (> (count_c hand) 2) (= (count_c hand) 0))
)
)
(define (stp s c sl)
(if (equal? (first c) s)
(cond
((or (equal? (last c) 'a) (equal? (last c) 'k))
(if (> sl 1) 1 0)
)
((equal? (last c) 'q)
(if (> sl 2) 1 0)
)
(else 0)
)
0
)
)
(define (stoppers? s hand)
(> (accumulate
+ (every (lambda (x) (stp s x (cnt s hand))) hand)
) 0)
)
(define (has_stoppers? hand)
(and
(stoppers? 's hand)
(stoppers? 'h hand)
(stoppers? 'd hand)
(stoppers? 'c hand)
)
)
(define (longest_suit hand)
((lambda (s h d c)
(cond
((and (>= c d) (>= c h) (>= c s)) 'c)
((and (>= d h) (>= d s) (>= d c)) 'd)
((and (>= h s) (>= h c) (>= h d)) 'h)
((and (>= s c) (>= s d) (>= s h)) 's)
)
)(count_s hand) (count_h hand) (count_d hand) (count_c hand))
)
(define (calc_points_of_hand hand)
((lambda (sl hl dl cl)
(+ (accumulate +
(every (lambda (x) (calc_points x hand)) hand)
)
(if (= sl 0) 3 (if (= sl 1) 2 0))
(if (= hl 0) 3 (if (= hl 1) 2 0))
(if (= dl 0) 3 (if (= dl 1) 2 0))
(if (= cl 0) 3 (if (= cl 1) 2 0))
)
) (count_s hand) (count_h hand) (count_d hand) (count_c hand))
)
(define (openbid hand)
((lambda (ls lsc b hs p)
(cond
((and (< p 13) (< lsc 7)) 'PASS)
((and (< p 16) (> p 12)) (se 1 ls))
((and (< p 20) (> p 15) (or (not hs) (not b))) (se 1 ls))
((and (< p 20) (> p 15) hs b) '(1 NO TRUMP))
((and (>= p 20) (or (not hs) (not b))) (se 2 ls))
((and (>= p 20) hs b) '(2 NO TRUMP))
((and (< p 13) (> p 6) (> lsc 6)) (se 3 ls))
(else 'PASS)
)
)(longest_suit hand)
(cnt (longest_suit hand) hand)
(balanced? hand)
(has_stoppers? hand)
(calc_points_of_hand hand)
)
)