Three in a row project

For this lab, you will be using backtracking to solve a common puzzle problem. For a more complete description of these puzzles, please visit This site

Simple introduction

Your code will take a file specifying an n-by-n grid which represents an initial state for a three-in-a-row game. The format of the file will have the first line contain the value for n followed by n lines of n colors each, such as

6
B---B-
W--B-W
------
WW--B-
------
--W---
Which has a graphical representation of:

The basic rules to solve these are:

  1. All squares must be filled in either white or blue.
  2. All rows and columns must have an equal number of whites and blues.
  3. There may be not be an serires of three consecutive blue or whites.

A solution to this problem would be

  
BWBWBW
WBWBBW
BWBWWB
WWBWBB
BBWBWW
WBWBWB
Which has a graphical representation of:

What you will be given

There are three python files for this lab:
  • threeInARowBoard.py, the python file which specifies a board class to hold the board.
  • threeInARowBoard.html, HTML file documenting the board class.
  • threeInARowMain.py, which start the game.
  • threeInARowSolver.py, which you will complete to make it work. And additional support files:
  • 03-26-easy-6x6.in, an easy 6x6 board.
  • 2018-03-30-medium-6x6.in, a medium 6x6 board.
  • 2018-03-30-medium-14x14.in, a medium 6x6 board.
  • allBlankSix.in, a blank 6x6 board.
  • allBlank14.in, a blank 14x14 board.

    The algorithm to complete the game

    Your code will use the following algorithm to complete the game.
  • Find the next '-' or undefined location Following this algorithm, you will have one of two outcomes. Hopefully, you will have have found a valid solution, stopping as soon as you do. If not, you will have exhausted all possibilities and shown that a solution does not exist, ultimately returning False.

    What you need to do

    Ultimately, you need to complete the function findSolution(board) in the file threeInARowSolver.py This quite likely will be best done writing additional helper functions as well. Think about some of the additional things that will need to be done, such as the following: You will need to download the files listed again here:
  • threeInARowBoard.py, the python file which specifies a board class to hold the board.
  • threeInARowMain.py, which start the game.
  • threeInARowSolver.py, which you will complete to make it work.
  • 03-26-easy-6x6.in, an easy 6x6 board.
  • 2018-03-30-medium-6x6.in, a medium 6x6 board.

    When you run the file, it will ask you to choose a file. The file you choose should be one of the initial boards listed above, such as 03-26-easy-6x6.in.

    I have created short video going over a solution of this in action. This is a backtracking specific video going over the backtracking method for solving the 3-in-row problem. This is longer and may be a little too pedantic. And now one video going over how we would solving the 3-in-row problem when not using a computer.