--file      : CliminalO.hs
--date      : 17/02/01
--author    : mi-na
--rational  :



--export module
module CliminalO ( doCliminalTurnWithAI
                 ) where



--outer module(self-defined)
import FieldD
import CharacterD
import StatusO
import AlgorithmO

--outer module(public)
import Data.Maybe


--constant
serchDepth :: Int
serchDepth = 5



--implementation(CliminalO)
doCliminalTurnWithAI :: StatusEntity -> StatusM StatusEntity
doCliminalTurnWithAI (pList, nList, meta) =
  let climinal                = pList !! 0
      arroundNodes            = nexts $ getMyNode climinal
      policePositions         = [myId (getMyNode p) | p <- pList]
      estimateDistanceList    = map (\x -> minimum $ map (measureDistance nList serchDepth 1 x) policePositions) arroundNodes
      nextDistination         = arroundNodes !! (getMaxOrder estimateDistanceList)
      --make new climinal to replace
      processedCliminalMaybe  = move False nextDistination nList climinal
  in if processedCliminalMaybe == Nothing
          then Clash
          else let processedCliminal = fromJust processedCliminalMaybe
                   newPlist          = processedCliminal : (tail pList)
                 in return (newPlist, nList, meta) >>= checkGameStatus
