SoccerFun 0.4.4 → 0.5
raw patch · 7 files changed
+114/−87 lines, 7 filesdep −plugins
Dependencies removed: plugins
Files
- SoccerFun.cabal +3/−3
- SoccerFun/MatchGame.hs +33/−33
- SoccerFun/Tape/Record.hs +8/−7
- SoccerFun/Tape/Record/Template.hs +27/−0
- tournament/Makefile +13/−6
- tournament/makeAll.sh +0/−38
- tournament/mkIndex.sh +30/−0
SoccerFun.cabal view
@@ -1,5 +1,5 @@ Name: SoccerFun-Version: 0.4.4+Version: 0.5 Copyright: (c) 2010, Jan Rochel License: BSD3 License-File: LICENSE@@ -15,7 +15,7 @@ Cabal-Version: >= 1.6 Data-Files: template/Main.hs template/Makefile template/Children/Child.hs template/Children/Team.hs- tournament/makeAll.sh tournament/makeLoop.sh tournament/Makefile+ tournament/mkIndex.sh tournament/makeLoop.sh tournament/Makefile SoccerFun/Tape/Record/Template.hs Library Extensions:@@ -32,7 +32,6 @@ mtl >= 1.1 && < 2.1, derive >= 2.4 && < 2.5, binary >= 0.5 && < 0.6,- plugins >= 1.5 && < 1.6, process >= 1.0 && < 1.1, directory >= 1.0 && < 1.1, zlib >= 0.5 && < 0.6@@ -52,6 +51,7 @@ SoccerFun.Referee SoccerFun.Random SoccerFun.Prelude+ Paths_SoccerFun Executable sfRecord Main-Is: SoccerFun/Tape/Record.hs
SoccerFun/MatchGame.hs view
@@ -13,10 +13,10 @@ import Control.Monad import System.Random import System.Exit-import System.Directory-import System.Eval.Haskell import System.Process+import System.Cmd import Data.List (findIndices)+import Paths_SoccerFun (getDataFileName) showTime ∷ Minutes → String -- ^ display time in (mm:ss min) format@@ -57,42 +57,42 @@ team2 = t2 East field in liftM (setMatchStart team1 team2 field (ivanovReferee field team1 team2) 1) newStdGen --- also returns the team names-dynSetupMatch ∷ String → String → IO (String, String, Match)-dynSetupMatch t1 t2 = do- (t1name, team1) ← loadTeam t1- (t2name, team2) ← loadTeam t2- match ← setupMatch team1 team2- return (t1name, t2name, match)+dynRecord ∷ FilePath → FilePath → IO ()+dynRecord p1 p2 = do+ (loc1,name1) ← compileTeam p1+ (loc2,name2) ← compileTeam p2+ record ← getDataFileName "SoccerFun/Tape/Record/Template.hs"+ exitCode ← system $ "runhaskell -i" ⧺ loc1 ⧺ " -i" ⧺ loc2 ⧺ " -DTEAM1=" ⧺ name1 ⧺ " -DTEAM2=" ⧺ name2 ⧺ " " ⧺ record+ when (exitCode ≢ ExitSuccess) (fail "Could merge teams, probably due to a type error.") -loadTeam ∷ String → IO (String, Home → Field → Team)-loadTeam t = do- t ← return $ removeTrailingSlashes t- let (loc,name) = case findIndices isSlash t of+compileTeam ∷ FilePath → IO (FilePath,String)+compileTeam p = do+ let (loc,teamName) = dissectPath p+ let teamMod = teamName ⧺ ".Team"+ exitCode ← compile (Just loc) teamMod+ if exitCode ≡ ExitSuccess+ then return (loc,teamName)+ else fail ("Failed compiling " ⧺ teamMod ⧺ " in " ⧺ loc ⧺ ".")+ where + dissectPath ∷ FilePath → (FilePath, String)+ dissectPath p = case findIndices isSlash t of [ ] → (".", t) ixs → let (loc,slash:name) = splitAt (last ixs) t in (loc, name)- team ← inDir loc $ do- exitCode ← waitForProcess =<< runProcess "ghc" ["--make", "-v0", name ⧺ ".Team"] (Just ".") Nothing Nothing Nothing Nothing- if exitCode ≢ ExitSuccess- then return $ Left ["Teams could not be compiled"]- else eval_ (name ⧺ ".Team.team") [name ⧺ ".Team"] [] [] [loc] -- the [loc] doesn't seem to have any effect- case team of- Left errors → mapM_ putStrLn ("Failed to load team. Errors:" : errors) >> exitFailure- Right Nothing → do- putStrLn "Failed to load team due to type error."- putStrLn "Remember that <TeamName>.Team has to export a function with signature"- putStrLn "team :: Home -> Field -> Team"- exitFailure- Right (Just t) → return (name, t)- where+ t = removeTrailingSlashes p removeTrailingSlashes str = if isSlash (last str) then removeTrailingSlashes (init str) else str isSlash = flip elem ['/','\\']- inDir dir ioAction = do- oldDir ← getCurrentDirectory- setCurrentDirectory dir- res ← ioAction- setCurrentDirectory oldDir- return res++ compile ∷ (Maybe FilePath) → String → IO ExitCode+ compile workingDir modName = waitForProcess =<< runProcess+ "ghc" ["--make", "-v0", modName] workingDir Nothing Nothing Nothing Nothing+++-- inDir dir ioAction = do+-- oldDir ← getCurrentDirectory+-- setCurrentDirectory dir+-- res ← ioAction+-- setCurrentDirectory oldDir+-- return res {- This module defines the match and tournament data structures. -}
SoccerFun/Tape/Record.hs view
@@ -21,11 +21,12 @@ ["Record a match between two teams <Team1> and <Team2>", "Usage: " ⧺ prog ⧺ " <dir1> <dir2>", " where both arguments are paths to directories containing a team module."]+ dynRecord t1 t2 - (t1name,t2name,match) ← dynSetupMatch t1 t2- let tape = recordMatch match- encodeFile (t1name ⧺ "-" ⧺ t2name ⧺ ".sft") tape- let Tape steps = tape- endOfMatch = snd (last steps)- finalScore = score endOfMatch- putStrLn $ show (fst finalScore) ⧺ " / " ⧺ show (snd finalScore)+-- (t1name,t2name,match) ← dynSetupMatch t1 t2+-- let tape = recordMatch match+-- encodeFile (t1name ⧺ "-" ⧺ t2name ⧺ ".sft") tape+-- let Tape steps = tape+-- endOfMatch = snd (last steps)+-- finalScore = score endOfMatch+-- putStrLn $ show (fst finalScore) ⧺ " / " ⧺ show (snd finalScore)
+ SoccerFun/Tape/Record/Template.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE UnicodeSyntax, CPP #-}+{-# OPTIONS_GHC -pgmP cpp #-}+-- | Usage: Hit /q/ to abort the match+module Main where++import Control.Monad+import System.Exit+import Prelude.Unicode+import Data.Binary+import SoccerFun.Tape+import SoccerFun.MatchControl+import SoccerFun.MatchGame+import System.Environment+import qualified TEAM1.Team as Team1+import qualified TEAM2.Team as Team2++#define MKSTRING(x) #x+#define TOSTRING(x) MKSTRING(x)++main ∷ IO ()+main = do+ tape ← liftM recordMatch $ setupMatch Team1.team Team2.team+ encodeFile (TOSTRING(TEAM1) ⧺ "-" ⧺ TOSTRING(TEAM2) ⧺ ".sft") tape+ let Tape steps = tape+ endOfMatch = snd (last steps)+ finalScore = score endOfMatch+ putStrLn $ show (fst finalScore) ⧺ " / " ⧺ show (snd finalScore)
tournament/Makefile view
@@ -1,11 +1,22 @@ .SUFFIXES: .log .sft .hs-.PHONY: recordAll record clean+.PHONY: default recordAll record index clean TEAMS=$(notdir $(wildcard teams/*)) +default: recordAll index+ recordAll:- for t1 in $(TEAMS); do for t2 in $(TEAMS); do make TEAM1=$$t1 TEAM2=$$t2 record; done; done+ for t1 in $(TEAMS); do for t2 in $(TEAMS); do make -s TEAM1=$$t1 TEAM2=$$t2 record; done; done +index: tapes/index.html++tapes/index.html: tapes/*.log+ ./mkIndex.sh > $@++clean:+ rm -f tapes/*+ rm -f teams/*/*.o teams/*/*.hi+ # the rest of the file requires TEAM1 and TEAM2 to be defined record: teams/$(TEAM1) teams/$(TEAM2) tapes/$(TEAM1)-$(TEAM2).log@@ -13,7 +24,3 @@ tapes/$(TEAM1)-$(TEAM2).log: teams/$(TEAM1)/* teams/$(TEAM2)/* ulimit -t 15; sfRecord teams/$(TEAM1) teams/$(TEAM2) > $@ 2>&1 [ -f $(TEAM1)-$(TEAM2).sft ] && mv $(TEAM1)-$(TEAM2).sft tapes--clean:- rm -f tapes/*- rm -f teams/*/*.o teams/*/*.hi
− tournament/makeAll.sh
@@ -1,38 +0,0 @@-#!/bin/sh--echo '<html><head><title>SoccerFun Tournament</title></head><body><table>' > out--echo "<tr>" >> out-for i in teams/*; do- echo "<td>`basename $i`</td>" >> out-done-echo "<td></td>" >> out-echo "</tr>" >> out--for i in teams/*; do- for j in teams/*; do- make TEAM1=`basename $i` TEAM2=`basename $j` record- done;-done--for i in teams/*; do- echo "<tr>" >> out- for j in teams/*; do- game=`basename $i`-`basename $j`- echo "<td>" >> out- if [ `stat -c%s "tapes/$game.log"` -lt 10 ]; then- [ -s tapes/$game.sft ] && echo "<a href=\"$game.sft\">" >> out- cat "tapes/$game.log" >> out- [ -s tapes/$game.sft ] && echo "</a>" >> out- else- echo "<a href=\"$game.log\">error</a>" >> out- fi- echo "</td>" >> out- done;- echo "<td>`basename $j`</td>" >> out- echo "</tr>" >> out-done--echo '</table></title></head><body><table>' >> out--mv out tapes/index.html
+ tournament/mkIndex.sh view
@@ -0,0 +1,30 @@+#!/bin/sh++echo '<html><head><title>SoccerFun Tournament</title></head><body><table>'++echo "<tr>"+for i in teams/*; do+ echo "<td>`basename $i`</td>"+done+echo "<td></td>"+echo "</tr>"++for i in teams/*; do+ echo "<tr>"+ for j in teams/*; do+ game=`basename $i`-`basename $j`+ echo "<td>"+ if [ `stat -c%s "tapes/$game.log"` -lt 10 ]; then+ [ -s tapes/$game.sft ] && echo "<a href=\"$game.sft\">"+ cat "tapes/$game.log"+ [ -s tapes/$game.sft ] && echo "</a>"+ else+ echo "<a href=\"$game.log\">error</a>"+ fi+ echo "</td>"+ done;+ echo "<td>`basename $i`</td>"+ echo "</tr>"+done++echo '</table></title></head><body><table>'