Skip to content

Sontran0118/Advanced-C-Skyscrapers-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced "Skyscrapers" Puzzle Game and Solver in C

This project is a comprehensive C-based implementation of the "Skyscrapers" logic puzzle. It features a fully interactive command-line game and an advanced, heuristic-based automated solver. The implementation is designed to handle variable grid sizes, from 4x4 up to 8x8.

About the Game

Skyscrapers is a logic puzzle where the objective is to place "skyscrapers" of varying heights (e.g., 1 to N in an N_N grid) onto a board. The rules are similar to Sudoku: each height can only appear once in each row and column. The puzzle's unique challenge comes from the numerical "clues" placed at the edges of the grid. These clues indicate how many skyscrapers are visible from that specific vantage point, with taller buildings obscuring the view of shorter ones behind them.

Key Features

1. Interactive Game Module

  • Dynamic Board Initialization: The game starts by parsing command-line arguments to set up the board size, initial piece placements, and edge clues.
  • Robust User Input: Handles player moves via standard input, with comprehensive validation to prevent invalid piece placement (e.g., out of bounds, on an occupied cell, or violating the one-per-row/column rule).
  • Real-time Constraint Checking: After a row or column is filled, the program validates the move against the edge clues, preventing placements that would make the puzzle unsolvable.
  • Formatted CLI Display: Renders a clean, readable display of the game board and all clues after each move.

2. Heuristic-Based Automated Solver

The core of this project is the automated solver, which implements a series of sophisticated heuristics to solve Skyscrapers puzzles without resorting to brute-force backtracking. This approach mimics advanced human logic and includes:

  • Heuristic #1: Edge Clue Initialization & Constraint Rule: Automatically places skyscrapers of maximum height (N) when a clue is 1, and fills in full sequences (e.g., 1, 2, ..., N) when a clue is N. It also uses an "Edge Constraint Rule" to proactively eliminate impossible placements for other values near the edges.

  • Heuristic #2: Constraint Propagation: After a piece is placed, the solver propagates this new information across the corresponding row and column, removing that piece as a possibility from all other cells in those lines.

  • Heuristic #3: Process of Elimination (Single Possibility): The solver scans each row and column to find if a specific number can only be placed in one remaining empty cell, and if so, places it there.

  • Heuristic #4: Clue Elimination (Sequence Filtration): For partially filled rows or columns, this is the most advanced heuristic. It generates all possible permutations of the remaining numbers and filters this list down to only those sequences that would satisfy the edge clues. From this filtered list, it can either identify a definitively placed number or further eliminate possibilities from individual cells.

This project demonstrates a robust application of C programming to game development and algorithmic problem-solving, with a particular focus on constraint satisfaction and heuristic-based logic.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Generated from BatDan24/cse220_hw1