;; Connect5 Competiton Version ;; Version 11 ;; 12/10/2001 ;; DO NOT GRADE THIS CODE !!!!!!!!!!!!!!!! ;; If you are looking for the code to grade, it is at ;; ~eroseman/comp210/connect5/connect5_partner.ss ;; THIS IS THE PROJECT WRAPPED INTO A HUGE LOCAL ;; YOU GIVE THE CONNECT5 program a list and it does it!! ;; Made some changes to the VALUE make-eval-matrix returns when ;; it gets off the board... ;; Made some changes to recommend...Now searches for all solutions... ;; Now searches for one move that makes two groups of 3. ;; FIXED MAJOR REVERSE SEARCHING BUG...Now has 'diag up ;; FIXED ERROR IN COMBINE MATRIX ;; Added determinant betweent two different positions of equal value ;; by number of solutions they could be present in. ;; NEED TO WRITE FUNCTION THAT WILL CHOOSE A SPACE AT RANDOM (define-struct pmove (x y)) (define-struct pivot (across down diagd diagu)) ;; make-pivot-matrix: num -> matrix ;; Purpose: Returns a square matrix of size x filled with pivots (define (make-pivot-matrix x) (build-vector x (lambda (i) (build-vector x (lambda (i) (make-pivot 0 0 0 0) ))))) ;; make-matrix: num -> matrix ;; Purpose: Returns a square matrix of size x filled with zeros (define (make-matrix x) (build-vector x (lambda (i) (make-vector x 0 )))) ;; matrix-ref: num num matrix -> element-of-matrix ;; Purpose: Refrences the row and column of a matrix and returns ;; indicated element (define (matrix-ref r c mat) (vector-ref (vector-ref mat (sub1 r)) (sub1 c))) ;; matrix-set!: num num matrix value -> void ;; Purpose: Sets the value of an element in a matrix (define (matrix-set! r c mat value) (vector-set! (vector-ref mat (sub1 r)) (sub1 c) value)) ;; fori=: num num (num -> anything) -> (void) ;; Purpose: Runs the given function a number of times ;; and gives it ascending numbers from start ;; to stop. This function runs the function on ;; Both Start and Stop values. (define (fori= srt stp body) (cond [(> srt stp) (void)] [else (begin (body srt) (fori= (add1 srt) stp body))])) ;; list-ref: list num -> alpha ;; Purpose: Returns the nth item in a list (define (list-ref lst n) (cond [(= n 1) (first lst)] [else (list-ref (rest lst) (sub1 n))])) ;; lgb-set! (define (lgb-set! x y lgb val) (local [(define (lr-h lst n) (cond [(= n 1) lst] [else (lr-h (rest lst) (sub1 n))]))] (set-car! (lr-h (list-ref lgb x) y) val))) (define r1-5 (list '- '- '- '- '-)) (define r2-5 (list '- '- '- '- '-)) (define r3-5 (list '- '- '- '- '-)) (define r4-5 (list '- '- '- '- '-)) (define r5-5 (list '- '- '- '- '-)) ;(define lgb (list r1-5 r2-5 r3-5 r4-5 r5-5)) (define r1-6 (list '- '- '- '- '- '- )) (define r2-6 (list '- '- '- '- '- '-)) (define r3-6 (list '- '- '- '- '- '-)) (define r4-6 (list '- '- '- '- '- '-)) (define r5-6 (list '- '- '- '- '- '-)) (define r6-6 (list '- '- '- '- '- '-)) ;(define lgb (list r1-6 r2-6 r3-6 r4-6 r5-6 r6-6 )) (define r1-7 (list 'x '- '- '- '- '- '-)) (define r2-7 (list '- '- '- '- 'x '- '-)) (define r3-7 (list '- '- 'o 'o '- 'o 'o)) (define r4-7 (list '- '- 'o 'o 'o 'x '-)) (define r5-7 (list 'x 'o 'o 'o 'o 'x '-)) (define r6-7 (list '- '- 'x 'x '- '- '-)) (define r7-7 (list '- '- '- '- '- '- '-)) ;(define lgb (list r1-7 r2-7 r3-7 r4-7 r5-7 r6-7 r7-7)) (define r1-7 (list '- '- '- '- '- '- '-)) (define r2-7 (list '- '- '- '- '- '- '-)) (define r3-7 (list '- '- '- '- '- '- '-)) (define r4-7 (list '- '- 'x '- 'x '- '-)) (define r5-7 (list '- '- '- '- '- '- '-)) (define r6-7 (list '- '- 'x '- 'x '- '-)) (define r7-7 (list '- '- '- '- '- '- '-)) (define lgb (list r1-7 r2-7 r3-7 r4-7 r5-7 r6-7 r7-7)) (define r1-7 (list 'x 'x 'x 'x 'x 'x 'x)) (define r2-7 (list 'x 'x 'x 'x 'x 'x 'x)) (define r3-7 (list 'x 'x 'x 'x 'x 'x 'x)) (define r4-7 (list 'x 'x 'x 'x 'x 'x 'x)) (define r5-7 (list 'x 'x 'x 'x 'x 'x 'x)) (define r6-7 (list 'x 'x 'x 'x 'x 'x 'x)) (define r7-7 (list '- 'x 'x 'x 'x 'x 'x)) ;(define lgb (list r1-7 r2-7 r3-7 r4-7 r5-7 r6-7 r7-7)) (define r1-8 (list '- '- '- 'O '- '- '- '-)) (define r2-8 (list '- 'X '- '- 'O '- '- 'O)) (define r3-8 (list '- '- 'O 'X 'O 'X 'O 'X)) (define r4-8 (list '- 'O 'X 'X 'O 'O 'X 'X)) (define r5-8 (list '- 'O 'O 'O 'X 'O 'X '-)) (define r6-8 (list 'O 'O 'X 'O 'X 'O 'X '-)) (define r7-8 (list 'O 'X 'X 'X 'X 'X 'O '-)) (define r8-8 (list 'X '- '- '- 'O 'X '- '-)) ;(define lgb (list r1-8 r2-8 r3-8 r4-8 r5-8 r6-8 r7-8 r8-8)) (define r1-9 (list '- '- '- '- '- '- '- '- '-)) (define r2-9 (list '- '- '- '- '- '- '- '- '-)) (define r3-9 (list '- '- '- '- '- '- '- '- '-)) (define r4-9 (list '- '- '- '- '- '- '- '- '-)) (define r5-9 (list '- '- '- '- '- '- '- '- '-)) (define r6-9 (list '- '- '- '- '- '- '- '- '-)) (define r7-9 (list '- '- '- '- '- '- '- '- '-)) (define r8-9 (list '- '- '- '- '- '- '- '- '-)) (define r9-9 (list '- '- '- '- '- '- '- '- '-)) ;(define lgb (list r1-9 r2-9 r3-9 r4-9 r5-9 r6-9 r7-9 r8-9 r9-9)) (define r1-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r2-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r3-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r4-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r5-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r6-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r7-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r8-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r9-10 (list '- '- '- '- '- '- '- '- '- '-)) (define r10-10 (list '- '- '- '- '- '- '- '- '- '-)) ;(define lgb (list r1-10 r2-10 r3-10 r4-10 r5-10 r6-10 r7-10 r8-10 r9-10 r10-10)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CODE STARTS HERE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;(define (connect5 lgb WIN BLOCK5 BLOCK4 BLOCK2of3) ; (local [ (define BLOCK4 20) (define WIN 800) (define BLOCK5 100) (define BLOCK2of3 35) ;; create-game-board: List-of-list -> matrix ;; Purpose: Takes in a gameboard in list format and converts it ;; to a matrix with specified values for positions of pieces. (define (create-game-board lst) (local [(define size (length lst))] (build-vector size (lambda (i) (list-to-vector (list-ref lst (add1 i))))))) ;; list-to-vector: list ;; Purpose: Takes in a row (list) of a gameboard and converts it to a ;; vector and makes the appropriate representations of piece ;; position. (100 for an x, 1 for an o, and 0 for nothing) (define (list-to-vector lst) (local [(define size (length lst))] (build-vector size (lambda (i) (cond [(symbol=? 'X (list-ref lst (add1 i))) 100] [(symbol=? 'O (list-ref lst (add1 i))) 1] [(symbol=? '- (list-ref lst (add1 i))) 0]))))) ;; eval-search: num(1) num(2) num(3) num(4) symbol ;; Purpose: Searches for a given distance from a place on the game-board in a ;; given direction and returns the sum off all the pieces. ;; Parameters are as follows: ;; num(1) - The row number of the point to search from ;; num(2) - The column number of the point to search from ;; num(3) - Value, an accumulator of the current value. ;; Should be called with 0. ;; num(4) - Current Depth of search. ;; Should be called with 5. (define (eval-search x y value depth func) (cond [(zero? depth) value] [(or (> x size) (> y size)) 0] [(or (= x 0) (= y 0)) 0] [else (eval-search (cond [(symbol=? func 'across) x] [else (add1 x)]) (cond [(symbol=? func 'down) y] [(symbol=? func 'diagu) (sub1 y)] [else (add1 y)]) (+ value (matrix-ref x y gb)) (sub1 depth) func)])) ;;build-eval-matrix: symbol number -> gameboard ;;Purpose: Builds a gameboard with the positions replaced by the ;; sum of all of pieces in a given direction. Symbol must be either ;; 'diag (for downwards diagnal searches), 'across (for left searches), ;; or 'down (for downwards searches) or 'diagup. Number is the number of spaces ;; in given direction that the program should add for. (define (build-eval-matrix func num) (local [(define (build-across-row row) (build-vector size (lambda (i) (eval-search row (add1 i) 0 num func))))] (build-vector size (lambda (i) (build-across-row (add1 i)))))) ;(build-eval-matrix 'diag 1) ;;analyze-posn: gameboard(1) gameboard(2) gameboard(3) num(1) num(2) num(3) num(4) num(5) symbol boolean-> boolean or (void) ;;purpose: Determined if a specified position on the game board matched the selection criterion ;; given the eval-matrix and the appropriate direction. If it does match, recommend- ;; posn is called and told add importance to the move-matrix. ;; ;; Parameters: ;; gameboard(1) <- The real gameboard with the appropriate representations of the ;; pieces in it. ;; gameboard(2) <- The Evaluation matrix to analyze ;; gameboard(3) <- The suggested move matrix ;; num(1) <- The column of the position to analyze ;; num(2) <- The row of the position to analyze ;; num(3) <- Desired number of our pieces ;; num(4) <- Desired number of their pieces ;; num(5) <- Importance of the move that blocks this formation ;; symbol <- Direction of search matching eval-matrix ;; boolean <- Stop recommending after first find? (define (analyze-posn gb eval-gb move-mat c r desiredours desiredtheirs importance dir findfirst) (local [(define num (matrix-ref r c eval-gb)) (define theirs (remainder num 100)) (define ours (/ (- num theirs) 100))] (cond [(and (= ours desiredours) (= theirs desiredtheirs)) (recommend-position gb r c dir importance 5 move-mat findfirst)] [else false]))) ;; recommend-position: num num sybmol num ;; Purpose: Takes in a position this IS certainly involved in ;; an immediate loss or win and searches in given direction on the gameboard ;; from that position for the move that would create the win or loss. ;; Then places a recommedation of 'value' in the suggested move matrix (move-mat) ;; Params: gb <- Matrix game board ;; x y num a position ;; dir - direction to search (standard values) ;; value - the value that a blocking move is worth ;; depth - depth to search for a blocking move, usually 5 ;; suggestmat - Suggestion Matrix ;; findfirstonly - find only the first suggestion and stop? ;; boolean value ;; (define (recommend-position gb x y dir value depth suggestmat findfirstonly) (cond [(or (< size x) (< size y)) false] [(or (zero? x) (zero? y)) false] [(zero? depth) false] [(zero? (matrix-ref x y gb)) (begin (matrix-set! x y suggestmat (+ (matrix-ref x y suggestmat) value)) (cond [(not findfirstonly) (recommend-position gb (cond [(symbol=? dir 'across) x] [else (add1 x)]) (cond [(symbol=? dir 'down) y] [(symbol=? dir'diagu) (sub1 y)] [else (add1 y)]) dir value (sub1 depth) suggestmat findfirstonly)] [else false]))] [else (recommend-position gb (cond [(symbol=? dir 'across) x] [else (add1 x)]) (cond [(symbol=? dir 'down) y] [(symbol=? dir 'diagu) (sub1 y)] [else (add1 y)]) dir value (sub1 depth) suggestmat findfirstonly)])) ;;analyze-eval-mat: gameboard(1) gameboard(2) gameboard(3) num(1) num(2) num(3) symbol ;; Purpose: Analyzes a whole evuation matrix and makes suggestions to ;; the suggested-move matrix for every move that blocks the given ;; configuration. Value suggested to move-mat is given by ;; importance. ;; ;; Parameters: ;; gameboard(1) <- The real gameboard with the appropriate representations of the ;; pieces in it. ;; gameboard(2) <- The Evaluation matrix to analyze ;; gameboard(3) <- The suggested move matrix ;; num(1) <- Desired number of our pieces ;; num(2) <- Desired number of their pieces ;; num(3) <- Importance of the move that blocks this formation ;; symbol <- Direction of search matching eval-matrix ;; (define (analyze-eval-mat gb eval-gb move-mat desiredours desiredtheirs importance dir findfirst) (local [(define size (vector-length gb))] (fori= 1 size (lambda (x) (fori= 1 size (lambda (y) (analyze-posn gb eval-gb move-mat x y desiredours desiredtheirs importance dir findfirst))))))) ;; vect-zero?: vector num -> boolean ;; Determins in all elements in a vector are zero (define (vect-zero? vec size) (cond [(= size 0) true] [(= (vector-ref vec (sub1 size)) 0) (vect-zero? vec (sub1 size))] [else false])) ;; mat-zero?: matrix num num -> boolean ;; Determines if all elements in a matrix are zero (define (mat-zero? mat i size) (cond [(= i 0) true] [else (and (vect-zero? (vector-ref mat (sub1 i)) size) (mat-zero? mat (sub1 i) size))])) ;; make-move: nothing -> (void) ;; Purpose: Searches the suggested-move matrix for ;; the most favorable move and suggests that move. (define (make-move gb win-move-mat-win move-mat size) (local [(define maxmove 0) (define moves empty)] (begin (if (mat-zero? move-mat size size) (make-educated-move gb win-move-mat-win move-mat) false) (fori= 1 size (lambda (a) (fori= 1 size (lambda (b) (begin (if (> (matrix-ref a b move-mat) maxmove) (begin (set! maxmove (matrix-ref a b move-mat)) (set! moves (list (make-pmove a b)))) (if (= (matrix-ref a b move-mat) maxmove) (set! moves (cons (make-pmove a b) moves)) (void)) )))))) moves))) ;; combine-mat: matrix matrix num num ;; Comines two matrices with any value in mat 1 ;; greater than thresh getting the value value (define (combine-mat mat1 mat2 thresh value) (fori= 1 size (lambda (x) (fori= 1 size (lambda (y) (cond [(> (matrix-ref x y mat1) thresh) (matrix-set! x y mat2 (+ (matrix-ref x y mat2) value))] [else (void)])))))) ;;rmove: ;; Purpose Suggests a random move in the ;; Suggested move matrix (define (rmove gb move-mat size) (local [(define x (add1 (random size))) (define y (add1 (random size))) (define occupied (matrix-ref x y gb))] (cond [(zero? occupied) (matrix-set! x y move-mat (add1 (matrix-ref x y move-mat)))] [else (rmove gb move-mat size)]))) ;; Does matrix addition ;; mat3 = mat1 + mat2 (define (add-mat mat1 mat2 mat3 size) (fori= 1 size (lambda (x) (fori= 1 size (lambda (y) (matrix-set! x y mat3 (+ (matrix-ref x y mat2) (matrix-ref x y mat1)))))))) ;; make-winmove-matrix: win-move-mat ;; Purpose: Makes a matrix that starts at each of the positions of the opponents ;; and tracks all spaces that could be involved in a winning move if the ;; opponent is given an unlimited, unblocked amount of moves. ;; Each time a position is a candidate for being involved in a ;; winning move, its value in the win-move-mat is incremented by 1. ;; (define (make-winmove-matrix gb win-move-mat a5 d5 diagd5 diagu5) (fori= 1 size (lambda (x) (fori= 1 size (lambda (y) (winmove-pos gb x y win-move-mat a5 d5 diagd5 diagu5)))))) ;; winmove-pos: x y win-move-mat ;; Purpose: Takes in a position, and determines possible wins from that position ;; and increments the win-move-mat accordingly (!! Changed with v.7 ONLY IF ;; the move already contains at least 1 of the oponents pieces. (define (winmove-pos gb x y win-mat a5 d5 diagd5 diagu5) (local [(define size (vector-length win-mat)) (define theiracross (remainder (matrix-ref x y a5) 100)) (define ouracross (/ (- (matrix-ref x y a5) theiracross) 100)) (define theirdown (remainder (matrix-ref x y d5) 100)) (define ourdown (/ (- (matrix-ref x y d5) theirdown) 100)) (define theirdiagd (remainder (matrix-ref x y diagd5) 100)) (define ourdiagd (/ (- (matrix-ref x y diagd5) theirdiagd) 100)) (define theirdiagu (remainder (matrix-ref x y diagu5) 100)) (define ourdiagu (/ (- (matrix-ref x y diagu5) theirdiagu) 100))] (begin (if (and (> ouracross 0) (= theiracross 0)) (winmove-changemat gb x y win-mat 5 'across size) false) (if (and (> ourdown 0) (= theirdown 0)) (winmove-changemat gb x y win-mat 5 'down size) false) (if (and (> ourdiagd 0) (= theirdiagd 0)) (winmove-changemat gb x y win-mat 5 'diagd size) false) (if (and (> ourdiagu 0) (= theirdiagu 0)) (winmove-changemat gb x y win-mat 5 'diagu size) false)))) ;;winmove-changemat x y mat direction ;;Purpose: Takes in a position that is assured to be involved in a winning move and ;; appropriatly increments the win matrix until it reaches the end of the board ;; or it encounters one of our pieces. ;; ;;MAY WANT TO CHANGE THIS LATER ON TO ONLY GO A DEPTH OF 5 ;; (define (winmove-changemat gb x y mat depth dir size) (cond [(or (> x size) (> y size)) false] [(or (= x 0) (= y 0)) false] [(= (matrix-ref x y gb) 1) false] [(= depth 0) false] [else (begin (matrix-set! x y mat (add1 (matrix-ref x y mat))) (winmove-changemat gb (cond [(symbol=? dir 'across) x] [else (add1 x)]) (cond [(symbol=? dir 'down) y] [(symbol=? dir 'diagu) (sub1 y)] [else (add1 y)]) mat (sub1 depth) dir size))])) ;;mat-mat: matrix ;;Returns the max value in a matrix (define (mat-max mat) (local [(define max 0) (define size (vector-length mat))] (begin (fori= 1 size (lambda (x) (fori= 1 size (lambda (y) (cond [(> (matrix-ref x y mat) max) (set! max (matrix-ref x y mat))] [else false]))))) (cond [(>= max 1) (set! max (/ (+ max (remainder max 2)) 2))] [else false]) max))) ;; make-educated-move: gameboard matrix matrix ;; Makes an educated move and suggestes it to the move matrix (define (make-educated-move gb win-mat move-mat) (local [ (define list-of-ours empty) (define win-move-good (mat-max win-mat)) (define size (vector-length gb)) (define (create-list-of-ours) (fori= 1 size (lambda (x) (fori= 1 size (lambda (y) (if (= 100 (matrix-ref x y gb)) (set! list-of-ours (cons (make-pmove x y) list-of-ours)) (void))))))) (define (random-move) (local [(define x (add1 (random size))) (define y (add1 (random size)))] (cond [(= (matrix-ref x y gb) 0) (matrix-set! x y move-mat (add1 (matrix-ref x y move-mat)))] [else (random-move)]))) (define (non-random-move space times) (local [(define movx (- (random 5) 2)) (define movy (- (random 5) 2)) (define newx (+ (pmove-x space) movx)) (define newy (+ (pmove-y space) movy))] (cond [(zero? times) false] [(and (<= newx size) (<= newy size) (> newx 0) (> newy 0) (= 0 (matrix-ref newx newy gb))) (matrix-set! newx newy move-mat (+ (matrix-ref newx newy move-mat) 2))] [else (non-random-move space (sub1 times))]))) (define (select-good-space-to-move-from lst) (local [(define idx (add1 (random (length lst))))] (if (<= win-move-good (matrix-ref (pmove-x (list-ref lst idx)) (pmove-y (list-ref lst idx)) win-mat)) (list-ref lst idx) (select-good-space-to-move-from lst))))] (begin (create-list-of-ours) (cond [(zero? (length list-of-ours)) (random-move)] [else (begin (non-random-move (select-good-space-to-move-from list-of-ours) 10) (random-move))])))) ;; opposite-row: list -> list ;; Purpose: Takes in a list and switches which pieces go where. (define (opposite-row lst) (map (lambda (i) (cond [(symbol=? i 'x) 'o] [(symbol=? i 'o) 'x] [else '-])) lst)) ;; opposite: list-game-board ;; Takes in a game-board and switches which pieces are on it. (define (opposite lgb) (map (lambda (i) (opposite-row i)) lgb)) ;; make-final-move: list-of-pmoves matrix pmove num -> list of pmoves ;; Purpose Selects the best move from a list of pmoves (define (make-final-move list-of-moves win-moves-mat move maxval) (cond [(empty? list-of-moves) move] [(> maxval (matrix-ref (pmove-x (first list-of-moves)) (pmove-y (first list-of-moves)) win-moves-mat)) (make-final-move (rest list-of-moves) win-moves-mat move maxval)] [else (make-final-move (rest list-of-moves) win-moves-mat (first list-of-moves) (matrix-ref (pmove-x (first list-of-moves)) (pmove-y (first list-of-moves)) win-moves-mat))])) (define lgb (read)) (define moves (list)) (define mostblocked 0) (define move false) (define gb (create-game-board lgb)) (define ogb (create-game-board (opposite lgb))) (define size (vector-length gb)) (define move-defense-mat (make-matrix size)) (define move-offense-mat (make-matrix size)) (define move-mat (make-matrix size)) (define maxmove 0) (define move-3-defense-mat (make-matrix size)) (define move-3-offense-mat (make-matrix size)) (define win-move-mat-win (make-matrix size)) (define win-move-mat-loss (make-matrix size)) (define across5 (build-eval-matrix 'across 5)) (define down5 (build-eval-matrix 'down 5)) (define diagd5 (build-eval-matrix 'diagd 5)) (define diagu5 (build-eval-matrix 'diagu 5)) (define a3 (build-eval-matrix 'across 3)) (define u3 (build-eval-matrix 'down 3)) (define d3 (build-eval-matrix 'diag 3)) (make-winmove-matrix gb win-move-mat-win across5 down5 diagd5 diagu5) (make-winmove-matrix ogb win-move-mat-loss across5 down5 diagd5 diagu5) (analyze-eval-mat gb across5 move-offense-mat 4 0 800 'across false) (analyze-eval-mat gb down5 move-offense-mat 4 0 800 'down false) (analyze-eval-mat gb diagd5 move-offense-mat 4 0 800 'diagd false) (analyze-eval-mat gb diagu5 move-offense-mat 4 0 800 'diagu false) (analyze-eval-mat gb across5 move-offense-mat 3 0 25 'across false) (analyze-eval-mat gb down5 move-offense-mat 3 0 25 'down false) (analyze-eval-mat gb diagd5 move-offense-mat 3 0 25 'diagd false) (analyze-eval-mat gb diagu5 move-offense-mat 3 0 25 'diagu false) (analyze-eval-mat gb across5 move-3-offense-mat 2 0 1 'across false) (analyze-eval-mat gb down5 move-3-offense-mat 2 0 1 'down false) (analyze-eval-mat gb diagd5 move-3-offense-mat 2 0 1 'diagd false) (analyze-eval-mat gb diagu5 move-3-offense-mat 2 0 1 'diagu false) (combine-mat move-3-offense-mat move-offense-mat 3 37) (analyze-eval-mat gb across5 move-defense-mat 0 4 100 'across false) (analyze-eval-mat gb down5 move-defense-mat 0 4 100 'down false) (analyze-eval-mat gb diagd5 move-defense-mat 0 4 100 'diagd false) (analyze-eval-mat gb diagu5 move-defense-mat 0 4 100 'diagu false) (analyze-eval-mat gb across5 move-defense-mat 0 3 20 'across false) (analyze-eval-mat gb down5 move-defense-mat 0 3 20 'down false) (analyze-eval-mat gb diagd5 move-defense-mat 0 3 20 'diagd false) (analyze-eval-mat gb diagu5 move-defense-mat 0 3 20 'diagu false) (analyze-eval-mat gb across5 move-3-defense-mat 0 2 1 'across false) (analyze-eval-mat gb down5 move-3-defense-mat 0 2 1 'down false) (analyze-eval-mat gb diagd5 move-3-defense-mat 0 2 1 'diagd false) (analyze-eval-mat gb diagu5 move-3-defense-mat 0 2 1 'diagu false) (combine-mat move-3-defense-mat move-defense-mat 3 35) (add-mat move-defense-mat move-offense-mat move-mat size) ;(rmove gb move-mat size) (define fmoves (make-move gb win-move-mat-win move-mat size)) ;; Determines the final move (define (final-call) (cond [(mat-zero? move-defense-mat size size) (make-final-move fmoves win-move-mat-win 'no-move -1)] [(mat-zero? move-offense-mat size size) (make-final-move fmoves win-move-mat-loss 'no-move -1)] [else (first fmoves)])) (define final-move (final-call)) (define (printmove final-move) (printf "~s" (list (sub1 (pmove-y final-move)) (sub1 (pmove-x final-move))))) (printmove final-move)