-- | Non-interactive representation of a Chu Shogi move -- 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 Move ( -- * Types Move (..), -- * Status report is_lion_capture, -- Output print_move ) where import Coordinate import Piece -- | Non-interactive representation of a Chu Shogi move data Move = Pass Piece Coordinate -- ^ Double move to empty square and back to origin | Igui Piece Coordinate -- Capture without moving Piece Coordinate -- Captured piece | Double_move Piece -- Other double moves Coordinate -- Initial location Coordinate -- First destination (Maybe Piece) -- Capture? Coordinate -- Second destination (Maybe Piece) -- Capture? | Capture Piece Coordinate Piece Coordinate -- Single move captures Bool -- Promote? Bool -- Declined to promote | Move Piece Coordinate Coordinate Bool Bool -- Single move non-captures -- | Does move involve a non-lion capturing a lion? is_lion_capture :: Move -> Bool is_lion_capture move = case move of Pass _ _ -> False Igui _ _ _ _ -> False Move _ _ _ _ _ -> False Capture p _ p2 _ _ _ -> case is_lion (piece_type p2) of True -> not (is_lion (piece_type p)) False -> False Double_move p _ _ p2 _ p3 -> case is_lion (piece_type p) of True -> False False -> case (p2, p3) of (Nothing, Nothing) -> False (Just p2', Nothing) -> is_lion (piece_type p2') (Nothing, Just p3') -> is_lion (piece_type p3') (Just p2', Just p3') -> is_lion (piece_type p2') || is_lion (piece_type p3') -- | Produce standard Chu Shogi notation of move (actually, not quite TSF standard - see program documentation). print_move :: Move -> String print_move move = case move of Pass p c -> (abbreviation $ piece_type p) ++ " " ++ (print_coordinate c) ++ " !" Igui p c _ c2 -> (abbreviation $ piece_type p) ++ " " ++ (print_coordinate c) ++ " x! " ++ (print_coordinate c2) Capture p c _ c2 pr dec -> let ind = case pr of True -> "+" False -> case dec of True -> "=" False -> "" in (abbreviation $ piece_type p) ++ " " ++ (print_coordinate c) ++ " x " ++ (print_coordinate c2) ++ ind Move p c c2 pr dec -> let ind = case pr of True -> "+" False -> case dec of True -> "=" False -> "" in (abbreviation $ piece_type p) ++ " " ++ (print_coordinate c) ++ " - " ++ (print_coordinate c2) ++ ind Double_move p c c2 p2 c3 p3 -> let sep' = case p2 of Nothing -> " - " Just _ -> " x " sep'' = case p3 of Nothing -> " - " Just _ -> " x " in (abbreviation $ piece_type p) ++ " " ++ (print_coordinate c) ++ sep' ++ (print_coordinate c2) ++ sep'' ++ (print_coordinate c3)