-- DumpGameAnalysis.hs -- Tom Moertel -- CVS $Id: DumpGameAnalysis.hs,v 1.4 2002/09/12 03:14:19 thor Exp $ -- | The DumpGameAnalysis filter converts a Game into an easy-to-parse -- stream of status lines. It is intended to allow easy integration -- between RAVT and visualization tools written in other languages. module Main (main) where import Data.FiniteMap import BasicTypes import Board import Eval import Game import GameState import GetInput -- | Main entry point. Reads the game, analyses it via 'evalGame' -- and them dumps the results along with information about the game -- board and configuration. main :: IO () main = interactDefault $ dumpGameStream . read -- | Dump the game and stream of GameStates in an easy-to-read format dumpGameStream :: Game -> String dumpGameStream g = unlines (setupDump ++ stateDump) where setupDump = head sbrd : reverse (tail sbrd) ++ botConfigs sbrd = lines . showBoard $ gameBoard g botConfigs = show (length botNames) : map dumpBotName botNames botNames = gameRobotNames g dumpBotName (r,nm) = unwords [ "I", show r, if null nm then show r else nm ] stateDump = concatMap dumpTurn (evalGame g) dumpTurn :: GameState -> [String] dumpTurn (GS rbtK _ _ turn) = map dumpRobot (filter rbtAliveStart (eltsFM rbtK)) where dumpRobot rbt = unwords [ "R", show turn , show rid, xy, score, money, pkgs, cmd] where rid = rbtID rbt xy = showPt (rbtLocation rbt) score = case rbtScore rbt of Just s -> show s; _ -> "?" money = case rbtMoney rbt of Just m -> show m; _ -> "?" pkgs = show . length . rbtPackages $ rbt cmd = if rbtAliveEnd rbt then rbtBidAndCommand rbt else unwords ["0", deathMsg] deathMsg = case rbtFinish rid of reasons@(_:_) -> unwords (take 2 reasons) _ -> "(Finished.)" rbtFinish rid = head [mgs | (r,_,mgs) <- gameEpilogues g, r == rid] -- | Shows a point (x,y) as "x y" showPt :: Point -> String showPt (x,y) = unwords [show x, show y] -- ================================================================= -- -- Copyright (C) 2002 Thomas Moertel. -- -- This program 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 2 -- of the License, or (at your option) any later version. -- -- The text of the GNU GPL may be found in the LICENSE file, -- included with this software, or online at the following URL: -- -- http://www.gnu.org/copyleft/gpl.html -- -- This program 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. -- -- Except as provided for under the terms of the GNU GPL, all rights -- are reserved worldwide. -- -- =================================================================