Skip to content

Latest commit

 

History

History

blunder1

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Blunder - Episode 1

Overview

In this puzzle, you will learn about parsing, storing, and manipulating two-dimensional arrays. These arrays serve as the basis for solving 2D problems. Additionally, you will implement a simple but complete Finite State Machine and gain an understanding of this concept.

To solve the puzzle, you will assist Blunder, a robot, in navigating through a city. Your task is to determine the robot's next movement based on its previous moves and the environment, including obstacles. It is essential to carefully read and understand the rules for the robot's displacement and how to represent the city's map.

This puzzle presents learning opportunities in the following concepts:

  1. State machine: You will implement a Finite State Machine, a computational model that consists of a set of states and transitions between them. It allows you to represent and control the behavior of the robot based on its current state and inputs.

  2. Simulation: You will simulate the movement of the robot through the city by manipulating the two-dimensional arrays. This involves updating the robot's position and checking for obstacles or other conditions that affect its movement.

By solving this puzzle, you will enhance your skills in state machine design and simulation techniques using two-dimensional arrays.

We have to print Blunder's path in the maze and also be able to detect infinite loops. We can detect loops by checking if Blunder passed a cell twice in the same state and with no modifications to the map in between.

Code Explanation

The Python code defines a program that simulates a game where a character named "Blunder" moves on a grid-based environment, interacting with different symbols and obstacles. Let's break down the structure of the code:

  1. Imports and Type Annotations:

    • The typing module is imported to support type hints.
    • List, Optional, and Tuple are imported from typing for specifying types.
    • Position is defined as a tuple of two integers representing coordinates on the grid.
  2. Constants:

    • Various symbols are defined as constants, such as strong and weak wall symbols, start and finish symbols, symbols for directions, items, and empty space.
  3. Class Definitions:

    • Cell class represents a cell on the grid with its symbol and some additional states related to Blunder's movements.
    • Blunder class represents the character in the game. It keeps track of Blunder's position, direction, movement history, and other states.
    • Game class manages the game state, including the grid, Blunder's actions, and game logic.
  4. Methods:

    • Methods in the Blunder class handle movements and updates Blunder's state based on the game rules.
    • Methods in the Game class manage the game state, including initializing the grid, checking validity of moves, updating Bender's state, moving Bender, and checking for game-ending conditions.
  5. Input Reading:

    • read_input_data() function reads input data from the standard input and initializes the game state accordingly.
  6. Main Function:

    • The main function initializes the game, reads input data, and runs the game loop until Blunder reaches the finish symbol or an infinite loop is detected. It then prints the moves made by Blunder or a message indicating a loop.

Overall, this code implements a simple game simulation with a character navigating through a grid while interacting with various symbols and obstacles.