Today we’ll be constructing chess boards like it’s 1980.
No prebuilt images, just the power of arrays and pixel art.
Your job is to render out chess boards with red and blue queens on them.
We’re keeping it really basic here so the only pieces are queens and each queen is represented by a blue or red square.
Chess board is an 8 by 8 grid of alternating black and white squares. The queens are red and blue squares.
Each board will have one red and one blue queen at different coordinates. In addition to displaying the board you’ll need to identify if the queens are “under attack” based on their coordinates.
Define a ChessBoard class
Should contain an 8x8 grid.
add_red method that accepts a row and column as input which colors the corresponding cell.add_blue method that accepts a row and column as input which colors the corresponding cell.render method that displays the chess board on the screen with red and blue shown in correct locations.is_under_attack method that returns a boolean if red is under attack by a blue piece horizontally, vertically, or diagonally.Diagonal attacks can come from four directions. Make sure to handle all of them.
Render your board for each is_under_attack scenario:
There are no acceptance tests required. The notebook should clearly show that the various is_under_attack scenarios have been handled.
Implement a Queue using two Stacks.
enqueue
dequeue
NOTE: The Stack instances have only push, pop, and peek methods. You should use your own Stack implementation. Instantiate these Stack objects in your PseudoQueue constructor.
# Example
queue = PseudoQueue()
queue.enqueue(5)
queue.enqueue(10)
queue.enqueue(15)
value = queue.dequeue() # Output: 5
| Input | Args | Internal State |
|---|---|---|
| [10]->[15]->[20] | 5 | [5]->[10]->[15]->[20] |
| 5 | [5] |
| Input | Output | Internal State |
|---|---|---|
| [5]->[10]->[15]->[20] | 20 | [5]->[10]->[15] |
| [5]->[10]->[15] | 15 | [5]->[10] |
Bookmark and Review
Statement on why this topic matter as it relates to what I’m studying in this module:
What are the key features and benefits of Jupyter Lab, and how does it differ from Jupyter Notebook?
Key Features and Benefits of Jupyter Lab
Unified Interface: provides a unified and flexible interface that integrates various components, including notebooks, text editors, terminals, and custom components, in a single environment.
Extensibility: highly extensible, allowing users to customize and enhance their environment through extensions.
Rich Text Support: includes a text editor with features like syntax highlighting, configurable indentation, and support for markdown, making it suitable for both code and narrative text.
File Browser and Console: The interface incorporates a file browser for easy navigation and management of files. It also supports consoles and terminals, providing full support for system shells.
Differences from Jupyter Notebook
Interface Structure: provides a more structured interface with a sidebar that can contain multiple panels, making it more versatile for various tasks. In contrast, Jupyter Notebook has a simpler structure with tabs for open notebooks.
Document Handling: extends beyond notebooks and allows the handling of various document types, including notebooks, scripts, and markdown files, within the same environment. Jupyter Notebook primarily focuses on notebook documents.
Cell Drag-and-Drop: supports cell drag-and-drop capabilities, enabling users to rearrange cells easily. This feature enhances the organization and structure of notebooks, which is not as seamless in Jupyter Notebook.
Advanced Text Editor: features a more advanced text editor with enhanced capabilities, including syntax highlighting and configurable indentation. Jupyter Notebook has a simpler text editor.
Extension Management: improved extension management, making it easier for users to discover, install, and manage extensions directly from the interface. Jupyter Notebook extensions often require additional command-line steps for installation.
What are the main functionalities provided by the NumPy library, and how can it be useful in Python programming, particularly for scientific computing and data manipulation tasks?
ndarray object for representing N-dimensional arrays.Explain the basic structure and properties of NumPy arrays, and provide examples of how to create, manipulate, and perform operations on them.
Basic Structure and Properties of NumPy Arrays:
numpy.array(), numpy.zeros(), numpy.ones(), numpy.arange(), etc.shape, dtype, and size.Operations: Support for element-wise and mathematical operations between arrays.
Examples:
import numpy as np
# Creating arrays
arr1 = np.array([1, 2, 3])
arr2 = np.zeros((3, 3))
arr3 = np.arange(0, 10, 2)
# Basic properties
print(arr1.shape) # (3,)
print(arr2.dtype) # float64
# Indexing and slicing
print(arr1[0]) # 1
print(arr2[:, 1]) # Second column of arr2
# Mathematical operations
result = arr1 + arr3
print(result) # [1 5 9 13 17]
Write a brief reflection on your learning today, or use the prompt below to get started.
Read this short article on Imposter Syndrome. On a scale from 1 (least) to 10 (most), to what extent do you experience these feelings? Have you always felt the way you do now? If you have successfully lowered the number you’d use to rate your Imposter Syndrome, how have you done so?