This repository was archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.lisp
More file actions
75 lines (50 loc) · 1.79 KB
/
ai.lisp
File metadata and controls
75 lines (50 loc) · 1.79 KB
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
#|***************************************************
AI Class
Description: Defines the AI class and its methods.
*****************************************************|#
(defvar load-count nil)
(defun ai-move ( game-st )
(let ((p-index nil))
(setf cutoffs 0)
(setf iteration 0)
(update-all-pieces game-st)
(update-player-moves (player1 current_game_state))
(update-player-moves (player1 current_game_state))
(setf root (make-root-node game-st))
(update-player-moves (player_turn root))
(setf load-count (length (player_moves (player_turn root))))
(format t "~% ~% Chisp is thinking:~%")
(alpha-beta-negasearch root 4 -10000000 10000000 root)
(setf p-index (cond
((eq (car (best_move root)) 'k) 0)
((eq (car (best_move root)) 'q) 1)
((eq (car (best_move root)) 'r) 2)
((eq (car (best_move root)) 'b) 3)
((eq (car (best_move root)) 'n) 4)
(t 5)))
(move-piece (nth p-index
(pieces (if (= (mod (turn_count current_game_state) 2) 0)
;;then
(player1 current_game_state)
;;else
(player2 current_game_state))))
(second (best_move root)) (third (best_move root)))
(terpri)
(terpri)
(terpri)
(print (best-move-combination root))
(terpri)
(terpri)
(terpri)
;;(if (eql print_debug t)
(format t "Iteration: ~d~%" iteration)
(format t "~%~%Cutoffs: ~d" cutoffs)))
(defun best-move-combination ( root )
(best-combination root nil))
(defun best-combination ( node lst )
(cond
((eq (best_node node) nil)
(append lst (list (move_from_parent node))))
(t (best-combination (best_node node) (if (eq lst nil)
(append lst (move_from_parent node))
(append lst (list (move_from_parent node))))))))