Class Game

java.lang.Object
topics.branchandbound.utils.Node
topics.branchandbound.rectangles.Game
All Implemented Interfaces:
Comparable<Node>

class Game extends Node

Board State for Rectangle Placement

Represents a distinct physical configuration of the board within the execution tree of the Branch and Bound algorithm. It manages the insertion of rectangular pieces, enforces geometric constraints (boundaries, overlaps, adjacency), and calculates the heuristic bounding box area.

Author:
vicegd
  • Constructor Details

    • Game

      public Game(int boardSize, List<Piece> pieces)
      Constructs the root node representing an empty board.
      Parameters:
      boardSize - The dimension of the square board (N × N).
      pieces - The sequence of pieces to be placed on the board.
    • Game

      public Game(int[][] board, List<Piece> pieces, int depth, UUID parentId)
      Constructs a child node representing a subsequent placement state.
      Parameters:
      board - The new board configuration matrix.
      pieces - The sequence of pieces pending placement.
      depth - The current depth in the state space tree.
      parentId - The unique identifier of the parent node.
  • Method Details

    • expand

      public List<Node> expand()
      Generates all mathematically valid configurations extending from the current state by placing the next available piece.
      Specified by:
      expand in class Node
      Returns:
      A list containing the resulting child nodes.
    • calculateHeuristicValue

      public void calculateHeuristicValue()
      Computes the bounding box area of all placed pieces. This serves as the lower-bound heuristic estimate to prune sub-optimal configurations.
      Specified by:
      calculateHeuristicValue in class Node
    • isSolution

      public boolean isSolution()
      Determines whether the current node represents a fully resolved configuration.
      Specified by:
      isSolution in class Node
      Returns:
      true if all pieces have been successfully placed.
    • toString

      public String toString()
      Overrides:
      toString in class Object