-- DumpGameAnalysis.hs -- Tom Moertel -- CVS $Id$ -- | 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.Array import Data.Char import Data.List (intersperse) import Data.FiniteMap import System.Environment 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 = do interactDefault $ dumpGameStream . read where opt = "--colorize" -- | Dump the game and stream of GameStates in an easy to read format dumpGameStream :: Game -> String dumpGameStream g = joinWith "\n" [ setupDump, stateDump ] where setupDump = showPt (boardSize brd) : drawBoard brd : botConfigs botConfigs = show (length botNames) : map dumpBotName botNames botNames = gameRobotNames g dumpBotName (r,nm) = unwords [show r, if nm == "" then show r else nm] brd = gameBoard g stateDump = concatMap dumpTurn (zip [0..] (evalGame g)) dumpTurn (turn, gs@(GS rbtK _)) = map dumpRobot (eltsFM rbtK) where dumpRobot rbt = unwords [ "R", show turn , show rid, xy, score, money, pkgs, cmd] where rid = rbtID rbt xy = showPt (if alive then rbtLocation rbt else (0,0)) 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 alive then rbtBidAndCommand rbt else unwords ["0", rbtEpilogue] alive = rbtAlive rbt rbtEpilogue = case [msgs | (r,_,msgs)<-gameEpilogues g, r==rid] of [reason:_] -> reason _ -> "(Finished)" -- | Joins lists (typically Strings) with a given separator list. joinWith :: [a] -> [[a]] -> [a] joinWith sep = concat . intersperse sep -- | Shows a point (x,y) as "x y" showPt :: Point -> String showPt (x,y) = unwords [show x, show y] -- | Show an integral number using n digits digN :: (Integral a) => a -> a -> String digN n num = tail (show $ 10^n + num) -- ================================================================= -- -- 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. -- -- =================================================================