packages feed

htzaar (empty) → 0.0.0

raw patch · 5 files changed

+146/−0 lines, 5 filesdep +OpenGLdep +SDLdep +basesetup-changed

Dependencies added: OpenGL, SDL, base, random

Files

+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) Tom Hawkins 2009++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the distribution.+3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+SUCH DAMAGE.
+ RELEASE-NOTES view
@@ -0,0 +1,4 @@+htzaar 0.0.0    ???++-+
+ Setup.lhs view
@@ -0,0 +1,8 @@+#! /usr/bin/env runhaskell++> module Main (main) where+>+> import Distribution.Simple (defaultMain)+>+> main :: IO ()+> main = defaultMain
+ htzaar.cabal view
@@ -0,0 +1,40 @@+name:    htzaar+version: 0.0.0++category: Game++synopsis: A two player abstract strategy game.++description:+  Htzaar, an implementation of Tzaar ((c) 2007 Kris Brum), is a two player abstract+  strategy game played on a hexagonal board.  Tzaar is the latest from+  the GIPF game series.++author:     Tom Hawkins <tomahawkins@gmail.com>+maintainer: Tom Hawkins <tomahawkins@gmail.com>++license:      BSD3+license-file: LICENSE++homepage: http://tomahawkins.org++build-type:    Simple+cabal-version: >= 1.6++extra-source-files:+  RELEASE-NOTES++executable htzaar+  hs-source-dirs:   src+  main-is:          Main.hs+  other-modules:+  build-depends:+    base       >= 4       && < 5,+    OpenGL     >= 2.4     && < 2.5,+    SDL        >= 0.5.5   && < 0.6,+    random     >= 1.0.0   && < 1.1+  ghc-options:     -W++source-repository head+    type:     darcs+    location: http://patch-tag.com/r/tomahawkins/htzaar/pullrepo
+ src/Main.hs view
@@ -0,0 +1,67 @@+module Main (main) where++import Data.List+import Data.Maybe+import System.Environment+import System.Random+import Text.Printf++import AI+import Board+import Play++main :: IO ()+main = do+  args <- getArgs+  case args of+    [a, b]             | elem a aiNames && elem b aiNames -> aiVsAI 0 a b+    ["-s", seed, a, b] | elem a aiNames && elem b aiNames -> aiVsAI (read seed) a b+    [a]                | elem a aiNames -> play (mkStdGen 0)           $ fromJust $ lookup a ais+    ["-s", seed, a]    | elem a aiNames -> play (mkStdGen $ read seed) $ fromJust $ lookup a ais+    _ -> help++aiVsAI :: Int -> String -> String -> IO ()+aiVsAI seed a b = go 1 ("white", fromJust $ lookup a ais) ("black", fromJust $ lookup b ais) (boardTree startingBoard) (mkStdGen seed)++go :: Int -> (String, AI) -> (String, AI) -> BoardTree -> StdGen -> IO ()+go n a@(aColor, aAI) b@(bColor, bAI) bt@(BoardTree _ _ branches) g+  | null branches = putStrLn $ bName ++ " Wins!"+  | otherwise     = case lookup t branches of+    Nothing -> putStrLn ("Invalid Turn: " ++ aName ++ ": " ++ show t)+    Just bt -> printf "%2i. %s %s : %-20s        (%i)\n" n aColor ("(" ++ name aAI ++ ")") (showTurn t) (length branches) >> go (n + 1) b a (swapBoardTree bt) g'+  where+  (t, g') = strategy aAI bt g+  aName  = aColor ++ " (" ++ name aAI ++ ")"+  bName  = bColor ++ " (" ++ name bAI ++ ")"+  ++help :: IO ()+help = putStrLn $ unlines+  [ ""+  , "NAME"+  , "  htzaar - Haskell Tzaar, a two-player abstract strategy game."+  , ""+  , "SYNOPSIS"+  , "  htzaar [-s SEED] AI [AI]"+  , ""+  , "EXAMPLES"+  , "  htzaar lame"+  , "    Play a game against the lame AI."+  , ""+  , "  htzaar -s 1234 lame"+  , "    Play a game against the lame AI with an initial seed."+  , ""+  , "  htzaar -s 1234 lame lame"+  , "    Simulate a game with an initial seed between two instances of the lame AI."+  , ""+  , "UI CONTROLS"+  , "  left  mouse button : Select piece to move or location to move too.  Also starts a new game."+  , "  right mouse button : Undo last action."+  , "  space bar          : Pass on the second optional move."+  , ""+  , "AI LIBRARY"+  ] ++ unlines [ "  " ++ name a ++ " : " ++ description a | a <- ai ] ++ "\n"++aiNames = map name ai+ais = zip aiNames ai+