Implement a sample program in that language. The program should allow the user to observe a virtual environment and perform actions in it. First, the user will read a description of a place where he is and what actions he can do. He will then type one of several simple commands. Then, the program will simulate what happens next and then give the user an updated description of where he is and what actions can be done next. This way it proceeds in a loop until the user exits the program by issuing a special command.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is a sample program implemented in SimpleScript, based on the language specification I provided earlier. This program simulates a simple text-based adventure game in a virtual environment (a small house with three connected rooms: Living Room, Kitchen, and Garden). The user starts in the Living Room.
Assumptions and Additions for Completeness
I've added a built-in command input prompt to read user input (e.g., set cmd [input "What do you do? "]). This fits the language's philosophy (command-based, string-returning) and is necessary for interactivity. It displays the prompt and returns the user's input as a string.
The program uses variables to track state (e.g., current room).
Available actions are listed in each room's description. Supported commands: "north", "south", "east", "west", "look" (redescribe), "quit".
The program loops until "quit" is entered.
Invalid commands give feedback and continue.
SimpleScript Program: House Adventure
code
# Simple text adventure in a house
# Define room descriptions as procedures
proc describe_living {} {
print "You are in the cozy Living Room. There's a TV and a comfy chair."
print "Possible actions: north (to Kitchen), east (to Garden), look, quit"
}
proc describe_kitchen {} {
print "You are in the Kitchen. It smells like fresh bread. There's a fridge."
print "Possible actions: south (to Living Room), look, quit"
}
proc describe_garden {} {
print "You are in the sunny Garden. Flowers bloom everywhere."
print "Possible actions: west (to Living Room), look, quit"
}
# Main game state
set current_room "living"
# Procedure to describe current room
proc describe {} {
if {$current_room == "living"} {
describe_living
} {
if {$current_room == "kitchen"} {
describe_kitchen
} {
if {$current_room == "garden"} {
describe_garden
} {
print "Error: Unknown room!"
}
}
}
}
# Procedure to handle user command
proc handle_command {cmd} {
set cmd [lower $cmd] # Assume a built-in 'lower' for case-insensitivity
if {$cmd == "quit"} {
print "Goodbye!"
return "quit"
} {
if {$cmd == "look"} {
describe
return ""
} {
# Movement based on current room
if {$current_room == "living"} {
if {$cmd == "north"} {
set current_room "kitchen"
describe
return ""
} {
if {$cmd == "east"} {
set current_room "garden"
describe
return ""
}
}
} {
if {$current_room == "kitchen"} {
if {$cmd == "south"} {
set current_room "living"
describe
return ""
}
} {
if {$current_room == "garden"} {
if {$cmd == "west"} {
set current_room "living"
describe
return ""
}
}
}
}
}
}
print "Invalid command: $cmd. Try again."
return ""
}
# Main game loop
describe # Initial description
while {1} {
set cmd [input "What do you do? "]
set result [handle_command $cmd]
if {$result == "quit"} {
break
}
}
Explanation
Structure: The program defines procedures for room descriptions and command handling. It uses a while loop for the main game loop, which repeatedly describes the environment, prompts for input, processes the command, and updates the state.
State Management: The current_room variable tracks location. Descriptions include available actions to guide the user.
Command Processing: The handle_command proc checks the input and either moves the player, redescribes, quits, or handles invalid input.
Loop and Exit: The loop runs indefinitely until "quit" is entered, at which point it breaks.
Simplicity: This leverages SimpleScript's features (procs, if, while, set, print, input) without complex data structures, making it easy to implement and run in a resource-constrained environment.
Sample Run (Simulated Output)
code
You are in the cozy Living Room. There's a TV and a comfy chair.
Possible actions: north (to Kitchen), east (to Garden), look, quit
What do you do? north
You are in the Kitchen. It smells like fresh bread. There's a fridge.
Possible actions: south (to Living Room), look, quit
What do you do? look
You are in the Kitchen. It smells like fresh bread. There's a fridge.
Possible actions: south (to Living Room), look, quit
What do you do? south
You are in the cozy Living Room. There's a TV and a comfy chair.
Possible actions: north (to Kitchen), east (to Garden), look, quit
What do you do? quit
Goodbye!
This program could be extended with more rooms, items, or actions while keeping the implementation simple.