Giter VIP home page Giter VIP logo

thewitnesssolver's Introduction

The Witness Puzzle Solver (SPOILERS!)

This is a tool for solving all of the non-environment puzzles in the video game The Witness. It provides an interface for inputting puzzles similar to the panels in the game. It finds the simplest solution and displays it in the grid. You can also configure the solver to only show part of the solution if you just need a hint.

You can try out the solver here:

https://overv.github.io/TheWitnessSolver/

Algorithm

Currently a very simple branch-and-bound algorithm is used that walks through all possible paths from each starting node and evaluates if the current path forms a correct solution when it hits an exit node.

Even just verifying a solution for the puzzles with tetris blocks appears to be an NP-complete problem so the algorithm is unlikely to become more efficient. Most of the effort should probably be dedicated to finding heuristics for the bound conditions to reduce the depth of the search tree.

This solver does not attempt to find the "simplest" solution, because that would require an exhaustive search that eliminates many optimisation opportunities to keep the performance reasonable.

The areas split up by the solution path are found incrementally, which means that for every step in the path only the last area has to be reexamined. This is much faster than running flood fill from scratch for every proposed solution and allows for early termination decisions, because other areas are known to longer change with future steps.

Similar to the first-fit decreasing bin packing algorithm, tetris puzzle solutions are verified by trying to fit the largest tetris blocks within an area first, which allows for detecting nonsensical solutions earlier. Note that unlike the bin packing algorithm, all possible combinations will be attempted if necessary.

Prefer required neighbour nodes

If multiple unvisited neighbour nodes are available, try visiting the required nodes first. This can avoid a lot of dead end solutions early on.

Segregation optimization through auxilary required nodes

If differently colored squares are direct neighbours, then the edge between them must be part of the correct solution path. That means that the endpoints of that edge are required nodes in the path. By checking for these (extra) required nodes in the solution check, the full segregation check doesn't need to run most of the time, which saves a lot of time.

Terminate a path if finished areas are already wrong

If an area that cannot be revisited already fails the segregation or tetris checks then there is no point going on.

Rules

This is a list of the mechanics as implemented by this solver:

Path

The path must be a self-avoiding walk starting at a start node and ending at an end node

Hexagons

Nodes or edges with a hexagon must be included in the path

Squares

For every region R, all squares in R must share the same color.

Suns / Stars

For every region R, if a sun of color X in in R, then there must be exactly two elements of color X in R.

Tetris Pieces

For every region R, R must exactly accommodate all the tetris pieces represented in R.

Hollow Squares

For every region R, let H be the total number of hollow squares represented in the region (that is, groups just contribute their size, and the shape is ignored). For some choice of H individual tetris blocks, R must pass tetris validation (the step described above) when these pieces are removed, but not if fewer than H blocks are removed.

Cancellation symbols

For every region R, let K denote the number of cancellation symbols in R. For some choice of K (non-cancellation) elements from the region, validation must pass (that is, all the rules described above must pass) when these elements are removed, but not if fewer than K elements are removed.

Notable implementation discrepancies

Here are some things that are different from the game:

  • Perhaps most importantly, Cancellation symbols will not respect hexagons -- they only consider entities in the interiors of cells.
  • Hollow tetris cubes are implemented only depending on the total amount of hollow blocks in a region, disregarding shape. For the vast majority of puzzles in the game, this is acceptable. It's not completely clear how respecting the shape of hollow squares would work, as there were very few puzzles in the game using this mechanic.

thewitnesssolver's People

Contributors

blumia avatar cemulate avatar overv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thewitnesssolver's Issues

Add Support for Triangle Puzzles

It would be really great if there was support for puzzles with triangles in the boxes that correspond to how man sides of the box that the line can touch.

No solution found for solvable in-game puzzle

I was able to solve this puzzle in-game (upper loft section of the quarry, near the ramp/platform controls) but not in the puzzle solver.
screesnhot
I tried changing the color of the Y symbol in the lower left, but color doesn't seem to make a difference, there was still no solution found.

Let me know if there's a trick I'm missing as far as setting up this puzzle in the solver. Otherwise I'm not sure which mechanic/component is causing it to not find a solution, but my guess would be the Y symbol. It's supposed to negate one of the black dots. Here's my in-game solution. screenshot-solved

Edges can also be exits

At the moment the code assumes an edge is either present or missing. Outer edges however can also be an exit!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.