more rearranging
This commit is contained in:
		
							parent
							
								
									40040c4461
								
							
						
					
					
						commit
						b5081c7f72
					
				
							
								
								
									
										62
									
								
								board.lisp
								
								
								
								
							
							
						
						
									
										62
									
								
								board.lisp
								
								
								
								
							| 
						 | 
					@ -45,7 +45,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defclass  board ()
 | 
					(defclass  basic-board ()
 | 
				
			||||||
  ((boardsize
 | 
					  ((boardsize
 | 
				
			||||||
    :initarg boardsize
 | 
					    :initarg boardsize
 | 
				
			||||||
   ; :initform *boardsize*
 | 
					   ; :initform *boardsize*
 | 
				
			||||||
| 
						 | 
					@ -57,10 +57,66 @@
 | 
				
			||||||
   (board
 | 
					   (board
 | 
				
			||||||
    :accessor board)))
 | 
					    :accessor board)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defmethod initialize-instance :after ((board board) &key (from-board nil))
 | 
					(defmethod initialize-instance :after ((board basic-board) &key (from-board nil))
 | 
				
			||||||
  (if (eql from-board nil)
 | 
					  (if (eql from-board nil)
 | 
				
			||||||
      (setf (board-def-type board) (make-board (boardsize board) (board-def-type board)))
 | 
					      (setf (board-def-type board) (make-2d-board (boardsize board) (board-def-type board)))
 | 
				
			||||||
      (progn
 | 
					      (progn
 | 
				
			||||||
	(setf (boardsize board) (boardsize from-board))
 | 
						(setf (boardsize board) (boardsize from-board))
 | 
				
			||||||
	(setf (board-def-type board) (board-def-type from-board))
 | 
						(setf (board-def-type board) (board-def-type from-board))
 | 
				
			||||||
	(setf (board board) (copy-2d-board (board from-board))))))
 | 
						(setf (board board) (copy-2d-board (board from-board))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defgeneric prune (board)
 | 
				
			||||||
 | 
					  ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defmethod genmove ((board basic-board) player)
 | 
				
			||||||
 | 
					  (prune board player)
 | 
				
			||||||
 | 
					  ;(focus board player)
 | 
				
			||||||
 | 
					  (minmax board player)
 | 
				
			||||||
 | 
					  (select-move board player))
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;(defun make-move (board player)
 | 
				
			||||||
 | 
					;  (select-move (score board player)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;(defun score (board player)
 | 
				
			||||||
 | 
					;  (let ((score-board (make-board (length board) 0)))
 | 
				
			||||||
 | 
					;    (dolist (slist *score-functions*)
 | 
				
			||||||
 | 
					;      (merge-score-board score-board (funcall (first slist) board player) (second slist)))
 | 
				
			||||||
 | 
					;    score-board))
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					;(defun merge-score-board (score-board scores weight)
 | 
				
			||||||
 | 
					;  (dotimes (x (length score-board))
 | 
				
			||||||
 | 
					;    (dotimes (y (length score-board))
 | 
				
			||||||
 | 
					;      (set-stone score-board `(,x ,y) (+ (get-stone score-board `(,x ,y)) (* weight (get-stone scores `(,x ,y))))))))
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;(defun select-move (board)
 | 
				
			||||||
 | 
					;  (let ((highest (get-stone board '(0 0)))
 | 
				
			||||||
 | 
					;	(coords (make-array 10 :fill-pointer 0 :adjustable t)))
 | 
				
			||||||
 | 
					;    (do ((x 0 (1+ x)))
 | 
				
			||||||
 | 
					;	((>= x (length board)) (aref coords (random (length coords))))
 | 
				
			||||||
 | 
					;      (do ((y 0 (1+ y)))
 | 
				
			||||||
 | 
					;	  ((>= y (length board)))
 | 
				
			||||||
 | 
					;	(let ((score (get-stone board `(,x ,y))))
 | 
				
			||||||
 | 
					;	  (if (> score highest)
 | 
				
			||||||
 | 
					;	      (progn
 | 
				
			||||||
 | 
					;		(setf highest score)
 | 
				
			||||||
 | 
					;		(setf coords (make-array 10 :fill-pointer 0 :adjustable t ))
 | 
				
			||||||
 | 
					;		(vector-push-extend `(,x ,y) coords))
 | 
				
			||||||
 | 
					;	      (if (= score highest)
 | 
				
			||||||
 | 
					;		  (if (= (random 2) 1)
 | 
				
			||||||
 | 
					;		      (vector-push-extend `(,x ,y) coords)))))))))
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;(defun score-unused (board player)
 | 
				
			||||||
 | 
					;  (let ((scores (make-board (length board) 0)))
 | 
				
			||||||
 | 
					;    (dotimes (x (length board))
 | 
				
			||||||
 | 
					;      (dotimes (y (length board))
 | 
				
			||||||
 | 
					;	;body
 | 
				
			||||||
 | 
					;	(if (eql (get-stone board `(,x ,y)) nil)
 | 
				
			||||||
 | 
					;	    (set-stone scores `(,x ,y) 1))
 | 
				
			||||||
 | 
					;	;end
 | 
				
			||||||
 | 
					;	))
 | 
				
			||||||
 | 
					;    scores))
 | 
				
			||||||
							
								
								
									
										1
									
								
								env.lisp
								
								
								
								
							
							
						
						
									
										1
									
								
								env.lisp
								
								
								
								
							| 
						 | 
					@ -20,3 +20,4 @@
 | 
				
			||||||
;(load (concatenate 'string *src-root* "packages.lisp"))
 | 
					;(load (concatenate 'string *src-root* "packages.lisp"))
 | 
				
			||||||
;(load (concatenate 'string *src-root* "gobot.lisp"))
 | 
					;(load (concatenate 'string *src-root* "gobot.lisp"))
 | 
				
			||||||
;(load (concatenate 'string *src-root* "gtp.lisp"))
 | 
					;(load (concatenate 'string *src-root* "gtp.lisp"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defparameter *src-root* "/home/dan/src/my/gobot/")
 | 
					(defparameter *src-root* "/home/dan/src/my/gobot/")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					asdas asd asd ad  asd 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(load (concatenate 'string *src-root* "packages.fasl"))
 | 
					(load (concatenate 'string *src-root* "packages.fasl"))
 | 
				
			||||||
(load (concatenate 'string *src-root* "netpipe.fasl"))
 | 
					(load (concatenate 'string *src-root* "netpipe.fasl"))
 | 
				
			||||||
(load (concatenate 'string *src-root* "board.fasl"))
 | 
					(load (concatenate 'string *src-root* "board.fasl"))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										59
									
								
								gobot.lisp
								
								
								
								
							
							
						
						
									
										59
									
								
								gobot.lisp
								
								
								
								
							| 
						 | 
					@ -24,7 +24,7 @@
 | 
				
			||||||
  (setf *boardsize* newsize))
 | 
					  (setf *boardsize* newsize))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun init-board ()
 | 
					(defun init-board ()
 | 
				
			||||||
  (setf *board* (make-board *boardsize*))
 | 
					  (setf *board* (make-instance 'board :boardsize *boardsize*))
 | 
				
			||||||
  (setf *passed* nil)
 | 
					  (setf *passed* nil)
 | 
				
			||||||
  (setf *player* nil))
 | 
					  (setf *player* nil))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,63 +34,22 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defmethod play ((board board) coords player)
 | 
				
			||||||
 | 
					  (set-stone (board board) coords player))
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defun do-play (player coord-str)
 | 
				
			||||||
(defun play (player coord-str)
 | 
					 | 
				
			||||||
  (setf *last-player* player)
 | 
					  (setf *last-player* player)
 | 
				
			||||||
  (if (string= coord-str "PASS")
 | 
					  (if (string= coord-str "PASS")
 | 
				
			||||||
      (setf *passed* t)
 | 
					      (setf *passed* t)
 | 
				
			||||||
      (set-stone *board* (str-to-coord coord-str) player)))
 | 
					      ;(set-stone *board* (str-to-coord coord-str) player)))
 | 
				
			||||||
 | 
					      (play *board* (str-to-coord coord-str) player)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun genmove (player)
 | 
					(defun do-genmove (player)
 | 
				
			||||||
  (setf *player* player)
 | 
					  (setf *player* player)
 | 
				
			||||||
  (if (or (eql *passed* t) (eql *last-player* player))
 | 
					  (if (or (eql *passed* t) (eql *last-player* player))
 | 
				
			||||||
      "pass"
 | 
					      "pass"
 | 
				
			||||||
      (let ((move (coord-to-str (make-move *board* player))))
 | 
					      (let ((move (coord-to-str (genmove *board* player))))
 | 
				
			||||||
	(play player move)
 | 
						(do-play player move)
 | 
				
			||||||
	move)))
 | 
						move)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun make-move (board player)
 | 
					 | 
				
			||||||
  (select-move (score board player)))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defun score (board player)
 | 
					 | 
				
			||||||
  (let ((score-board (make-board (length board) 0)))
 | 
					 | 
				
			||||||
    (dolist (slist *score-functions*)
 | 
					 | 
				
			||||||
      (merge-score-board score-board (funcall (first slist) board player) (second slist)))
 | 
					 | 
				
			||||||
    score-board))
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
(defun merge-score-board (score-board scores weight)
 | 
					 | 
				
			||||||
  (dotimes (x (length score-board))
 | 
					 | 
				
			||||||
    (dotimes (y (length score-board))
 | 
					 | 
				
			||||||
      (set-stone score-board `(,x ,y) (+ (get-stone score-board `(,x ,y)) (* weight (get-stone scores `(,x ,y))))))))
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defun select-move (board)
 | 
					 | 
				
			||||||
  (let ((highest (get-stone board '(0 0)))
 | 
					 | 
				
			||||||
	(coords (make-array 10 :fill-pointer 0 :adjustable t)))
 | 
					 | 
				
			||||||
    (do ((x 0 (1+ x)))
 | 
					 | 
				
			||||||
	((>= x (length board)) (aref coords (random (length coords))))
 | 
					 | 
				
			||||||
      (do ((y 0 (1+ y)))
 | 
					 | 
				
			||||||
	  ((>= y (length board)))
 | 
					 | 
				
			||||||
	(let ((score (get-stone board `(,x ,y))))
 | 
					 | 
				
			||||||
	  (if (> score highest)
 | 
					 | 
				
			||||||
	      (progn
 | 
					 | 
				
			||||||
		(setf highest score)
 | 
					 | 
				
			||||||
		(setf coords (make-array 10 :fill-pointer 0 :adjustable t ))
 | 
					 | 
				
			||||||
		(vector-push-extend `(,x ,y) coords))
 | 
					 | 
				
			||||||
	      (if (= score highest)
 | 
					 | 
				
			||||||
		  (if (= (random 2) 1)
 | 
					 | 
				
			||||||
		      (vector-push-extend `(,x ,y) coords)))))))))
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defun score-unused (board player)
 | 
					 | 
				
			||||||
  (let ((scores (make-board (length board) 0)))
 | 
					 | 
				
			||||||
    (dotimes (x (length board))
 | 
					 | 
				
			||||||
      (dotimes (y (length board))
 | 
					 | 
				
			||||||
	;body
 | 
					 | 
				
			||||||
	(if (eql (get-stone board `(,x ,y)) nil)
 | 
					 | 
				
			||||||
	    (set-stone scores `(,x ,y) 1))
 | 
					 | 
				
			||||||
	;end
 | 
					 | 
				
			||||||
	))
 | 
					 | 
				
			||||||
    scores))
 | 
					 | 
				
			||||||
							
								
								
									
										8
									
								
								gtp.lisp
								
								
								
								
							
							
						
						
									
										8
									
								
								gtp.lisp
								
								
								
								
							| 
						 | 
					@ -57,10 +57,10 @@
 | 
				
			||||||
      (komi (go-bot:set-komi (read-from-string (second commands))) 
 | 
					      (komi (go-bot:set-komi (read-from-string (second commands))) 
 | 
				
			||||||
	    "")
 | 
						    "")
 | 
				
			||||||
      (clear_board (go-bot:init) "")
 | 
					      (clear_board (go-bot:init) "")
 | 
				
			||||||
      (play (go-bot:play (char (second commands) 0) (third commands)) "")
 | 
					      (play (go-bot:do-play (char (second commands) 0) (third commands)) "")
 | 
				
			||||||
      (genmove (go-bot:genmove (char (second commands) 0)))
 | 
					      (genmove (go-bot:do-genmove (char (second commands) 0)))
 | 
				
			||||||
      (genmove_black (go-bot:genmove #\b))
 | 
					      (genmove_black (go-bot:do-genmove #\b))
 | 
				
			||||||
      (genmove_white (go-bot:genmove #\w))
 | 
					      (genmove_white (go-bot:do-genmove #\w))
 | 
				
			||||||
      ;(get_random_seed "0")
 | 
					      ;(get_random_seed "0")
 | 
				
			||||||
      ;(known_command)
 | 
					      ;(known_command)
 | 
				
			||||||
      ;(list_commands)
 | 
					      ;(list_commands)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,10 +20,9 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defpackage board
 | 
					(defpackage board
 | 
				
			||||||
  (:use :common-lisp)
 | 
					  (:use :common-lisp)
 | 
				
			||||||
  (:export :board
 | 
					  (:export :basic-board
 | 
				
			||||||
	   :get-stone
 | 
						   :get-stone
 | 
				
			||||||
	   :set-stone
 | 
						   :set-stone
 | 
				
			||||||
	   :make-board
 | 
					 | 
				
			||||||
	   :coord-to-str
 | 
						   :coord-to-str
 | 
				
			||||||
	   :str-to-coord))
 | 
						   :str-to-coord))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +37,6 @@
 | 
				
			||||||
	    :set-boardsize
 | 
						    :set-boardsize
 | 
				
			||||||
	    :init-board
 | 
						    :init-board
 | 
				
			||||||
	    :init
 | 
						    :init
 | 
				
			||||||
	    :play
 | 
						    :do-play
 | 
				
			||||||
	    :genmove
 | 
						    :do-genmove
 | 
				
			||||||
	    ))
 | 
						    ))
 | 
				
			||||||
		Loading…
	
		Reference in New Issue