예시: Tic-Tac-Toe 게임 트리

게임 트리 탐색 목표: 승리에 해당하는 리프 노드 탐색
Min-Max 기본 원리
일반 탐색 알고리즘과 달리 상대방이 최선의 수를 둔다고 가정

내 차례: 최대 이득을 선택
상대 차례: 내 손해를 최소화하는 수를 선택

예시

재귀적 구현
function minimax(node, depth, maxPlayer)
if depth == 0 or node가 단말 노드면
return node의 휴리스틱 값
if maxPlayer then
value ← -∞
for each child of node do
value ← max(value, **minimax(child, depth-1, FALSE)**)
return value
else
value ← +∞
for each child of node do
value ← min(value, **minimax(child, depth-1, TRUE)**)
return value
특성
Min-Max 알고리즘의 시간 복잡도를 줄이기 위해 고안
루트 노드(현재 내 턴)의 최적 선택만 필요하다.
서브트리(후속 게임들)는 최적 수를 찾기 위한 계산 수단일 뿐이다.
모든 노드를 평가할 필요 없음 ⇒ 시간 복잡도 O(b^(m/2))

핵심 아이디어
function alphabeta(node, depth, α, β, maxPlayer)
if depth == 0 or node가 단말 노드면
return node의 휴리스틱 값
if maxPlayer then
value ← -∞
for each child of node do
value ← max(value, alphabeta(child, depth-1, α, β, FALSE))
α ← max(α, value)
**if α ≥ β then
break // β 컷**
return value
else
value ← +∞
for each child of node do
value ← min(value, alphabeta(child, depth-1, α, β, TRUE))
β ← min(β, value)
**if α ≥ β then
break // α 컷**
return value