{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} -- | Chu Shogi AI for normal games. Mating problems use 'Mating' instead. -- Copyright 2009 Colin Adams -- -- This file is part of chu-shogi. -- -- Chu-shogi is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- Chu-shogi is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with chu-shogi. If not, see . module AI ( -- * Access recommended_move ) where import Data.Tree.Game_tree.Negascout import Data.Tree.Game_tree.Game_tree import Game_state import Generator import Evaluator import Move import Data.Maybe (fromJust) -- | Game trees are normal positions. -- Children are the full output from the move generator. -- Terminal nodes represent a won game. instance Game_tree (Non_interactive_state, Maybe Move) where is_terminal (ni_state, _) = case white_kings ni_state of 0 -> True _ -> case black_kings ni_state of 0 -> True _ -> is_bare_king ni_state node_value (ni_state, _) = value_for_black ni_state children = generate_moves recommended_move :: Non_interactive_state -> Move recommended_move initial_state = let (principal_variation, _score) = negascout (initial_state, Nothing) 4 in fromJust . snd . head . tail $ principal_variation