Example #1
0
    def test_find_zero_count():
        """Test setting grass in columns and rows with zero count"""
        game = solver.Board("test/inputs/single_tree")
        game.find_zero_count()

        np.testing.assert_array_equal(
            np.array(
                [[3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 1, 0, 3, 3], [3, 3, 3, 3, 3]]
            ),
            game.board,
        )

        game = solver.Board("test/inputs/easy")

        game.find_zero_count()
        np.testing.assert_array_equal(
            np.array(
                [
                    [0, 3, 0, 0, 0],
                    [0, 1, 0, 1, 0],
                    [3, 3, 3, 3, 3],
                    [1, 1, 0, 0, 0],
                    [0, 3, 0, 0, 1],
                ]
            ),
            game.board,
        )
Example #2
0
    def test_max_tents():
        """Test counting max tents"""
        game = solver.Board("test/inputs/single_tree")
        game.get_max_tents()
        np.testing.assert_array_equal(np.array([2, 2, 2, 2, 2]), game.max_tents_in_col)
        np.testing.assert_array_equal(np.array([3, 3, 3, 3]), game.max_tents_in_row)

        game = solver.Board("test/inputs/easy")
        game.get_max_tents()
        np.testing.assert_array_equal(np.array([3, 3, 3, 3, 2]), game.max_tents_in_col)
        np.testing.assert_array_equal(np.array([3, 3, 3, 2, 2]), game.max_tents_in_row)
Example #3
0
    def test_empty_cells():
        """Test counting empty cells"""
        game = solver.Board("test/inputs/single_tree")
        game.get_empty_cells()
        np.testing.assert_array_equal(np.array([4, 3, 4, 4, 4]), game.empty_cell_in_col)
        np.testing.assert_array_equal(np.array([5, 5, 4, 5]), game.empty_cell_in_row)

        game = solver.Board("test/inputs/easy")
        game.get_empty_cells()
        np.testing.assert_array_equal(np.array([4, 3, 5, 4, 4]), game.empty_cell_in_col)
        np.testing.assert_array_equal(np.array([5, 3, 5, 3, 4]), game.empty_cell_in_row)
Example #4
0
    def test_find_blanks_without_neighboring_tree():
        """Test finding cells without neighboring tree"""
        game = solver.Board("test/inputs/single_tree")
        game.find_blanks_without_neighboring_tree()

        np.testing.assert_array_equal(
            np.array(
                [[3, 3, 3, 3, 3], [3, 0, 3, 3, 3], [0, 1, 0, 3, 3], [3, 0, 3, 3, 3]]
            ),
            game.board,
        )
Example #5
0
    def test_board_loading(self):
        """Load sample board and verify fields"""
        game = solver.Board("test/inputs/single_tree")
        self.assertEqual(4, game.n_rows)
        self.assertEqual(5, game.n_cols)
        np.testing.assert_array_equal(np.array([0, 0, 1, 0, 0]), game.tents_in_col)
        np.testing.assert_array_equal(np.array([0, 0, 1, 0]), game.tents_in_row)

        np.testing.assert_array_equal(
            np.array(
                [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]
            ),
            game.board,
        )
Example #6
0
    def test_equal_empty_and_tents():
        """Test placing tents in columns/rows, where empty cells equal number of tents"""
        game = solver.Board("test/inputs/equal_tents_empty")

        game.get_empty_cells()
        game.check_equal_empty_and_tents()

        np.testing.assert_array_equal(
            np.array(
                [
                    [3, 1, 3, 3, 3],
                    [2, 1, 2, 1, 2],
                    [3, 1, 3, 3, 3],
                    [1, 1, 1, 2, 1],
                    [3, 2, 3, 3, 1],
                ]
            ),
            game.board,
        )
Example #7
0
    def test_set_tile(self):
        """Test setting grass and tents on the board"""
        game = solver.Board("test/inputs/single_tree")
        self.assertEqual(solver.TileType.BLANK, game.board[2, 0])
        self.assertEqual(solver.TileType.TREE, game.board[2, 1])

        game.set_tile(2, 0, solver.TileType.GRASS)
        self.assertEqual(solver.TileType.GRASS, game.board[2, 0])

        game.set_tile(2, 2, solver.TileType.TENT)
        self.assertEqual(0, game.tents_in_col[2])
        self.assertEqual(0, game.tents_in_row[2])

        np.testing.assert_array_equal(
            np.array(
                [[0, 0, 0, 0, 0], [0, 3, 3, 3, 0], [3, 1, 2, 3, 0], [0, 3, 3, 3, 0]]
            ),
            game.board,
        )

        with self.assertRaises(ValueError):
            game.set_tile(2, 1, solver.TileType.TENT)
        self.assertEqual(solver.TileType.TREE, game.board[2, 1])
        self.assertEqual(solver.TileType.BLANK, game.board[1, 0])
"""This module creates a web gui for presenting Tents-and-Trees game board"""

import os

import numpy as np
from flask import Flask, render_template, request
from tents_and_trees import solver as Solver

app = Flask(__name__)
solver = Solver.Board(None)

PORT = int(os.environ.get("PORT", 5000))

try:
    os.makedirs(app.instance_path)
except OSError:
    pass


@app.route("/")
def home():
    """Render home page"""
    return render_template("template.html")


@app.route("/input")
@app.route("/input/<int:size>")
def input_board(size=4):
    """Render input page"""
    return render_template("input.html", size=size)