- 전에 있던 함수에서 컴퓨터가 더 똑똑하게 play하는 함수를 만든다.
[Lisp] Tic-Tac-Toe 게임 실습(1) (tistory.com)
1. squeeze-play와 two-on-one 상황
1) squeeze란 양 대각선에 상대말이 있고 내 말이 중간에 있는 상황을 이야기한다.
여기서 x가 이기 위해서는 대각선에 두면 안되고 변에 둬야한다.
2) two-on-on 상황은 대각선에서 연속으로 o(or x)가 두 개 있고 나머지에 x말이 있는 상황을 말한다.
여기서 x가 이기기 위해서는 변에두면 안되고 대각선에 둬야한다.
2. 함수
* 전역변수 선언
(defvar *Corners* '(1 3 7 9))
(defvar *Sides* '(2 4 6 8))
1) block-squeeze-play
(defun block-squeeze-play (Board)
"Defending against a squeeze play"
(sq-and-2 Board *Computer* *Sides* 12 "block squeeze play"))
2) block-two-on-one
(defun block-two-on-one (Board)
"Defending against a two-on-one attack"
(sq-and-2 Board *Opponent* *Corners* 12 "block two-on-one"))
3) sq-and-2
(defun sq-and-2 (Board Player Pool V Strategy)
"squeeze play and two-on-one"
(when (equal (nth 5 Board) Player)
(or (sq-helper Board 1 9 V Strategy Pool)
(sq-helper Board 3 7 V Strategy Pool))))
4) sq-helper
(defun sq-helper (Board C1 C2 Val Strategy Pool)
"squeeze play and two-on-one"
(when (equal Val (sum-triplet Board (list C1 5 C2)))
(let ((Pos (find-empty-position Board (or Pool (list C1 C2)))))
(and Pos (list Pos Strategy)))))
5) choose-best-move3
(defun choose-best-move3 (Board)
"3rd version"
(or (take-center Board)
(make-three Board)
(block-opponent-win Board)
(block-squeeze-play Board)
(block-two-on-one Board)
(random-move-strategy Board)))
=실행확인용=
;; squeeze play
(setf MyBoard (make-board))
(make-move *Opponent* 1 MyBoard)
(make-move *Computer* 5 MyBoard)
(make-move *Opponent* 9 MyBoard)
(print-board MyBoard)
(block-squeeze-play MyBoard)
(make-move *Computer* 2 MyBoard)
(print-board MyBoard)
;; two-on-one
(setf MyBoard (make-board))
(make-move *Opponent* 1 MyBoard)
(make-move *Computer* 9 MyBoard)
(make-move *Opponent* 5 MyBoard)
(print-board MyBoard)
(block-two-on-one MyBoard)
(make-move *Computer* 3 MyBoard)
(print-board MyBoard)
'Major > Lisp' 카테고리의 다른 글
[Lisp] Chapter 13 Arrays(배열)* (0) | 2021.06.09 |
---|---|
[Lisp] Chapter 12 구조체(Structures) (0) | 2021.06.09 |
[Lisp] Tic-Tac-Toe 게임 실습(1) (0) | 2021.06.09 |
[Lisp] Chapter 10 Assignment (0) | 2021.06.09 |
[Lisp] Ch 9 - Input/Output (0) | 2021.06.01 |