Study Notes for Assignment: Text Adventure Game in Prolog

Assignment Overview

  • Instructor: Dr. Robert Collier

  • Final Assignment: Text Adventure Game in Prolog

    • Different from previous assignments.

    • Combines programming with a guided tutorial.

    • Specified PDF available on Brightspace.

Text Adventure Game Definition

  • Text Adventure Game: A game allowing players to navigate a virtual environment using a text-only terminal interface.

    • Players issue commands based on the environment description provided by the game.

    • The game reacts according to the player's commands.

Purpose and Importance of Text Adventure Games

  • Analogy to Graph Representation and Search Problems.

  • Graphs are vital abstractions in computer science, relevant in many academic contexts.

  • Utilized for representing Finite State Machines (FSMs).

Finite State Machines (FSMs)

  • Definition: Graphical abstractions represented by vertices (states) and edges (transitions).

    • Vertices represent system states.

    • Edges depict conditions leading to state transitions.

  • Example: A lamp with four states (off, dim, medium, bright).

    • Transition occurs via user input (controller knob).

    • Sequence: off → bright → dim → brightest → off.

  • Alternative Example: Game character states, such as walking or attacking, and transitions based on conditions (e.g., health status).

Game Development Using FSMs

  • Game will consist of state representing player location and possession of items (e.g., flashlight).

  • Graph conditions must be adhered to; using incorrect predicates (like assert) will result in an automatic zero for the assignment.

Virtual Environment Setup

  • Initial Setup: A flight of stairs with two states (top and bottom) for player location.

  • Commands: Transitions based on player input, such as "down" or "up".

    • State changes depend on possession of items (e.g., flashlight needed to go down).

Complexity Addition
  • Introduction of variables beyond location: player location (top/bottom) and flashlight possession (Boolean).

    • Configuring states leads to a total of four possible game states:

    1. Top of stairs without flashlight

    2. Top of stairs with flashlight

    3. Bottom of stairs without flashlight

    4. Bottom of stairs with flashlight

Transition Description
  • Commands prompt responses, and illegal transitions must be defined (e.g., going down without a flashlight).

State Representation in Prolog

  • Assign predicates correctly to represent game state transitions which are governed by user commands.

Creation of Basic Predicates

  • Game Loop Predicates: start and game predicates initialize the game, utilizing state representation.

    • start predicate imports modules, triggering game predicate, with steps indicated in backwards implication.

    • Within game, print current state, prompt user input, and invoke an update command.

Example Code Structure
  • update predicate manages user commands (e.g., quit game, handle unrecognized input).

More Complex States and Commands

  • Building upon the initial commands by implementing responses to additional conditions.

    • Commands can be player commands (moving up/down or picking up items).

  • Implementation of conditional transitions based on state combinations.

Enhanced Game Mechanics

  • Adding Inventory: Managing items (like flashlight) in the player’s state.

  • Support additional commands like help, drop, and take.

    • Example implementation of inventory management, handling possession of items, and updating game state after each action.

Development Checklist

  1. Set up basic predicates: start and game.

  2. Ensure correct state representation: Dynamics must adhere to FSM principles.

  3. Implement movement commands: Ensure transitions reflect the right player states and validate conditions (e.g., not moving into dark areas).

  4. Develop inventory and items management: Include commands for taking and dropping items in the game.

  5. Establish scoring metrics: Increment the score based on player achievements like collecting items.

  6. Create a help command: Guidance for the players including an overview of accepted commands.

  7. Test for obstacles: Implement barriers based on items (e.g., needing a rubber boot to cross electrified floor).

  8. Implement descriptive feedback: Print informative messages based on player actions and current state.

  9. Comments and Author Name: Comment all code and provide a summary of the approach and potential for implementing an auto-solver for the text adventure game.

Conclusion

  • Emphasizes creativity and functionality beyond basic requirements, ensuring that students are encouraged to expand upon their projects with inventive features.

  • Engage with project specifications to implement a complex yet interactive Prolog environment, laying the foundation for future explorations in computer programming and game design.