Skip to content

Commit

Permalink
Example 12 passes
Browse files Browse the repository at this point in the history
  • Loading branch information
PPKFS committed Dec 22, 2024
1 parent 01cd0b9 commit e6631c1
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source-repository-package
type: git
location: https://github.com/haskell-effectful/effectful.git
tag: a235b074cd68d770cbe732dc2a65067ff0c754f5
tag: 54236f4e7b975d46bcc8108285c0c09483f8dd93
subdir: effectful-core
subdir: effectful-plugin
subdir: effectful-th
Expand Down
2 changes: 1 addition & 1 deletion yaifl/run_no
Original file line number Diff line number Diff line change
@@ -1 +1 @@
673
686
11 changes: 8 additions & 3 deletions yaifl/src/Yaifl/Game/ActionProcessing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Yaifl.Model.Rules.Rulebook
import Yaifl.Model.Rules.Run
import Effectful.Reader.Static
import Breadcrumbs
import Yaifl.Model.Actions.Args


actionProcessingRules :: forall wm. ActionProcessing wm
Expand Down Expand Up @@ -64,9 +65,13 @@ actionProcessingRules = ActionProcessing $ \aSpan a@((Action{..}) :: Action wm r
, Rule "report stage rule"
[]
( \v -> do
ignoreSpanIfEmptyRulebook reportRules
r <- runRulebookAndReturnVariables (Just aSpan) False reportRules v
return (first Just $ fromMaybe (v, Nothing) r))
addAnnotation $ show (silently (actionOptions v))
if silently (actionOptions v)
then return (Just v, Nothing)
else do
ignoreSpanIfEmptyRulebook reportRules
r <- runRulebookAndReturnVariables (Just aSpan) False reportRules v
return (first Just $ fromMaybe (v, Nothing) r))
, notImplementedRule "clean actions rule"
]) u)
where
Expand Down
8 changes: 6 additions & 2 deletions yaifl/src/Yaifl/Game/Actions/Exiting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Yaifl.Model.Kinds.AnyObject
import Yaifl.Model.Metadata
import Yaifl.Model.Kinds.Supporter
import Breadcrumbs
import Yaifl.Game.Move
import Yaifl.Model.Entity

data ExitingResponses wm

Expand Down Expand Up @@ -49,7 +51,7 @@ exitingAction = (makeAction "exiting")
, carryOutRules = makeActionRulebook "carry out exiting rulebook" [ standardExiting ]
, reportRules = makeActionRulebook "report exiting rulebook"
[ notImplementedRule "standard report exiting"
, notImplementedRule "describe room emerged into"
, describeExited
]
}

Expand Down Expand Up @@ -81,7 +83,9 @@ cantExceedCapacity :: ExitingRule wm
cantExceedCapacity = notImplementedRule "can't exit if this exceeds carrying capacity"

standardExiting :: WMWithProperty wm Enclosing => ExitingRule wm
standardExiting = makeRule "standard exiting" [] $ \a@Args{variables=v} -> rulePass
standardExiting = makeRule "standard exiting" [] $ \a@Args{variables=v} -> do
o <- getObject (thingContainedBy $ getTaggedObject v)
bool (Just True) Nothing <$> move (source a) (tagObject @_ @EnclosingTag (thingContainedBy $ getTaggedObject v) o)

describeExited ::
ExitingRule wm
Expand Down
38 changes: 30 additions & 8 deletions yaifl/src/Yaifl/Game/Actions/GettingOff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ import Yaifl.Model.Kinds.Supporter
import Yaifl.Game.Move (move)
import Yaifl.Model.Query
import Yaifl.Model.Entity
import Yaifl.Model.Kinds.AnyObject
import Breadcrumbs

data GettingOffResponses wm

type GettingOffAction wm = Action wm () 'TakesThingParameter (SupporterThing wm)
type GettingOffAction wm = Action wm () ('TakesOneOf 'TakesThingParameter 'TakesNoParameter) (SupporterThing wm)

gettingOffAction :: (WithPrintingNameOfSomething wm, WMWithProperty wm Enclosing, WMWithProperty wm Container, WMWithProperty wm Supporter) => GettingOffAction wm
gettingOffAction = (makeAction "getting off")
{ name = "getting off"
, understandAs = ["get off"]
, matches = [("from", TakesThingParameter)]
, parseArguments = ParseArguments $ \(UnverifiedArgs Args{..}) -> do
let mbS = getSupporterMaybe (fst variables)
case mbS of
Nothing -> return $ FailedParse "can't get off a not-supporter"
Just s -> return $ SuccessfulParse (tagObject s (fst variables))
offFrom <- case fst variables of
Left thingToExit -> return (Just thingToExit)
Right _ -> getThingMaybe $ thingContainedBy source
let mbS = getSupporterMaybe =<< offFrom
case (offFrom, mbS) of
(Just t, Just s) -> return $ SuccessfulParse (tagObject s t)
{-
if the actor is on the noun, continue the action;
if the actor is carried by the noun, continue the action;
Expand All @@ -38,10 +42,11 @@ gettingOffAction = (makeAction "getting off")
tense]moment[otherwise]time[end if]." (A);
stop the action.
-}
, carryOutRules = makeActionRulebook "carry out gettingOff rulebook" [ standardGettingOff ]
_ -> return $ FailedParse "can't get off a not-supporter"
, carryOutRules = makeActionRulebook "carry out getting off rulebook" [ standardGettingOff ]
, reportRules = makeActionRulebook "report getting off rulebook"
[ notImplementedRule "standard report getting off"
, notImplementedRule "describe room stood up into"
[ reportGettingOff
, describeExited
]
}

Expand All @@ -54,4 +59,21 @@ standardGettingOff = makeRule "standard getting off rule" [] $ \Args{source=s, v
let supporterHolder = thingContainedBy (getTaggedObject v)
e' <- getEnclosingObject supporterHolder
move s (tagObject @_ @EnclosingTag (snd e') (fst e'))
rulePass

reportGettingOff ::
WithPrintingNameOfSomething wm
=> GettingOffRule wm
reportGettingOff = makeRule "standard report getting off rule" [] $ \a@Args{source=s, variables=v} -> do
-- if the action is not silent:
unlessSilent a
-- say "[The actor] [get] off [the noun]." (A);
[saying|{The s} #{get} off {the v}.|]
rulePass

describeExited ::
GettingOffRule wm
describeExited = makeRule "describe room stood up into rule" forPlayer' $ \a@Args{variables=v} -> do
-- TODO: reckon darkness
parseAction ((actionOptions a) { silently = True }) [ConstantParameter "going"] "look"
rulePass
2 changes: 1 addition & 1 deletion yaifl/src/Yaifl/Game/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ runActionHandlerAsWorldActions = interpret $ \_ -> \case
Nothing -> do
addAnnotation $ (("Argument mismatch because we got " <> show (S.fromList $ match:additionalArgs) <> " and we expected " <> show (goesWithA @goesWith Proxy)) :: Text)
return $ Left (("Argument mismatch because we got " <> show (S.fromList $ match:additionalArgs) <> " and we expected " <> show (goesWithA @goesWith Proxy)) :: Text)
Just v' -> Right <$> tryAction actionOpts a (UnverifiedArgs $ Args { actionOptions = ActionOptions False False, timestamp = ts, source = actor, variables = (v', parsedArgs) })
Just v' -> Right <$> tryAction actionOpts a (UnverifiedArgs $ Args { actionOptions = actionOpts, timestamp = ts, source = actor, variables = (v', parsedArgs) })
case nouns of
Left ex -> do
addAnnotation ex
Expand Down
1 change: 1 addition & 0 deletions yaifl/src/Yaifl/Model/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type ActionRulebook wm ac v = Rulebook wm ((:>) (Reader ac)) (Args wm v) Bool
type ActionRule wm ac v = Rule wm ((:>) (Reader ac)) (Args wm v) Bool

data ActionInterrupt = ContinueAction | StopAction
deriving stock (Eq, Ord, Enum, Bounded, Generic, Read, Show)

makeFieldLabelsNoPrefix ''Action

Expand Down
4 changes: 2 additions & 2 deletions yaifl/test/testcases/Chapter3/Starry Void
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ You close the magician's booth.
>look

The Starry Void
The door stands open to the outside.
A crack of light indicates the way back out to the center ring.

>examine crack of light

The booth door is wide open.
The booth door is shut, admitting only a thin crack of light.
83 changes: 83 additions & 0 deletions yaifl/test/testcases/Chapter3/Tamed
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
-----------------
----- Tamed -----
-----------------

Center Ring (on the pedestal)
Off to one side is a magician's booth, used in disappearing acts. The exterior is covered with painted gilt stars.

You can also see a cage (closed) (in which is a lion) here.

>get in cage

You can't get into the closed cage.

>open cage

You open the cage.

>get in cage

(getting off the pedestal)

You get into the cage.

In the cage you can see a lion.

The lion eyes you with obvious discontent.

>z

Time passes.

The lion eyes you with obvious discontent.

>close cage

You close the cage.

Though the lion does not move, you are aware that it is watching you closely.

>out

You can't get out of the closed cage.

Though the lion does not move, you are aware that it is watching you closely.

>open cage

You open the cage.

The lion eyes you with obvious discontent.

>get on pedestal

(getting out of the cage)

You get onto the pedestal.

>get off

You get off the pedestal.

Center Ring
Off to one side is a magician's booth, used in disappearing acts. The exterior is covered with painted gilt stars.

You can also see a cage (in which is a lion) and a pedestal here.

>look

Center Ring
Off to one side is a magician's booth, used in disappearing acts. The exterior is covered with painted gilt stars.

You can also see a cage (in which is a lion) and a pedestal here.

>enter booth

You get into the magician's booth.

>out

Center Ring
Off to one side is a magician's booth, used in disappearing acts. The exterior is covered with painted gilt stars.

You can also see a cage (in which is a lion) and a pedestal here.
4 changes: 2 additions & 2 deletions yaifl/yaifl.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.6
name: yaifl
version: 0.0.11.584
version: 0.0.12.686
synopsis: Yet another interactive fiction library.
description: Yet another interactive fiction library.
homepage: https://github.com/PPKFS/yaifl
Expand Down Expand Up @@ -47,7 +47,7 @@ common common-options
-fprint-potential-instances -fno-warn-unused-do-bind -haddock
-fwrite-ide-info -fplugin=Effectful.Plugin -Wunused-packages

default-language: GHC2021
default-language: GHC2024
default-extensions:
DataKinds
DefaultSignatures
Expand Down

0 comments on commit e6631c1

Please sign in to comment.