# Board Class

A flexible, grid-based 2D rectangular board implementation using two-layered lists, perfect for board game creation and grid manipulations.

## Installation

```bash
pip install boards.py
```

```python
from boards import Board
```

## Board creation:

```python

# Board(width, height, item=None, background=None, joint="")

# Create a 3x3 board with default value 0, joint=" " (space between items)

board = Board(3, 3, item=0, background=0, joint=" ")
board[1, 1] = 'X'
board[0, 0] = 'O'
print(board)
# Output:
# O 0 0
# 0 X 0
# 0 0 0

# Same board but with joint="" (no space between items)
board.joint = ""
print(board)
# Output:
# O00
# 0X0
# 000

# Iterating over cells

board = Board(2, 2, item='.', joint=" ")
board[0,0] = 'A'
board[1,1] = 'B'
for row, col, value in board:
    print(f"({row},{col}): {value}")
# Output:
# (0,0): A
# (0,1): .
# (1,0): .
# (1,1): B

# Board transformations

board = Board(3, 3, item=0, joint=" ")
board[0,0] = 1
board[1,1] = 2
board[2,2] = 3
print("Original:")
print(board)
# Output:
# 1 0 0
# 0 2 0
# 0 0 3

board.rotate()
print("Rotated 90°:")
print(board)
# Output:
# 0 0 1
# 0 2 0
# 3 0 0

board.hflip()
print("Horizontally flipped:")
print(board)
# Output:
# 1 0 0
# 0 2 0
# 0 0 3

# Finding connecting regions

board = Board(5, 5, item='.', background='.', joint=" ")
board[1,1] = board[1,2] = board[2,1] = board[2,2] = 'X'
board[3,3] = board[3,4] = board[4,3] = 'O'
print("Board:")
print(board)
# Output:
# . . . . .
# . X X . .
# . X X . .
# . . . O O
# . . . O .

connected_region = board.connected(1, 1)
print(f"Connected cells to (1,1): {connected_region}")
# Output: Connected cells to (1,1): [(1, 1), (1, 2), (2, 1), (2, 2)]

# Scrolling effects

board = Board(3, 3, item=0, joint=" ")
board.checkerboard(1, 2)
print("Original:")
print(board)
# Output:
# 1 2 1
# 2 1 2
# 1 2 1

print("Scrolled right by 1:")
print(board.rscrolled(1))
# Output:
# 1 1 2
# 2 2 1
# 1 1 2

print("Scrolled down by 1:")
print(board.dscrolled(1))
# Output:
# 2 1 2
# 1 2 1
# 1 2 1

# Board comparison

board1 = Board(3, 3, item='A', joint=" ")
board2 = board1.copy()
board2[1,1] = 'B'
print("Board 1:")
print(board1)
# Output:
# A A A
# A A A
# A A A
print("Board 2:")
print(board2)
# Output:
# A A A
# A B A
# A A A

similarity = board1.similarity(board2)
print(f"Similarity: {similarity:.1f}%")
# Output: Similarity: 88.9%
print(f"Difference: {board1.difference(board2):.1f}%")
# Output: Difference: 11.1%

# Flood fill

board = Board(5, 5, item='.', background='.', joint=" ")
board[1,1] = board[1,2] = board[2,1] = board[2,2] = 'X'
print("Before flood fill:")
print(board)
# Output:
# . . . . .
# . X X . .
# . X X . .
# . . . . .
# . . . . .

board.floodfill(1, 1, 'O')
print("After flood fill at (1,1):")
print(board)
# Output:
# . . . . .
# . O O . .
# . O O . .
# . . . . .
# . . . . .

# Working with different joint strings

# With space separator
board1 = Board(3, 3, item='#', joint=" ")
print(board1)
# Output:
# # # #
# # # #
# # # #

# With no separator
board2 = Board(3, 3, item='#', joint="")
print(board2)
# Output:
# ###
# ###
# ###

# With custom separator
board3 = Board(3, 3, item='#', joint="|")
print(board3)
# Output:
# #|#|#
# #|#|#
# #|#|#

# Board extension

board1 = Board(2, 2, item=1, joint=" ")
board2 = Board(2, 2, item=2, joint=" ")
print("Board 1:")
print(board1)
# Output:
# 1 1
# 1 1
print("Board 2:")
print(board2)
# Output:
# 2 2
# 2 2

board1.extend_to_right(board2)
print("Board 1 extended to the right:")
print(board1)
# Output:
# 1 1 2 2
# 1 1 2 2

# Compression

board = Board(5, 5, item='.', background='.', joint=" ")
board[2,2] = 'X'
print("Original:")
print(board)
# Output:
# . . . . .
# . . . . .
# . . X . .
# . . . . .
# . . . . .

board.compress()
print("Compressed:")
print(board)
# Output:
# . . X . .
# . . . . .
# . . . . .

# Binary marking

board = Board(2, 3, item=0, joint=" ")
print("Empty board:")
print(board)
# Output:
# 0 0 0
# 0 0 0

board.binary_mark(13)  # 13 in binary is 1101, padded to 6 digits: 001101
print("Board filled with binary of 13:")
print(board)
# Output:
# 0 0 1
# 1 0 1

# Checkerboard pattern

board = Board(4, 4, item='', joint=" ")
board.checkerboard('X', 'O')
print(board)
# Output:
# X O X O
# O X O X
# X O X O
# O X O X

# Moving items

board = Board(3, 3, item='.', background='.', joint=" ")
board[0,0] = 'X'
print("Before move:")
print(board)
# Output:
# X . .
# . . .
# . . .

board.move(0, 0, 2, 2)
print("After moving from (0,0) to (2,2):")
print(board)
# Output:
# . . .
# . . .
# . . X

# Checking symmetry

board = Board(3, 3, item=0, joint=" ")
board.checkerboard(1, 2)
print("Board:")
print(board)
# Output:
# 1 2 1
# 2 1 2
# 1 2 1

print(f"Horizontally symmetric? {board.is_symmetric('horizontal')}")
# Output: Horizontally symmetric? True
print(f"Vertically symmetric? {board.is_symmetric('vertical')}")
# Output: Vertically symmetric? True
print(f"Both? {board.is_symmetric('both')}")
# Output: Both? True
```

