Rods¶
Rods is a collection of Rod‘s, one representing the start, end and intermediary rods for the tower.
-
class
towers.core.rods.
Rods
[source]¶ A collection of 3 Rod’s that form the Tower.
Parameters: Raises: - InvalidTowerHeight – The height of the tower is invalid.
- InvalidRod – A rod is not of expected type Rod.
- InvalidRodHeight – A rod height is inconsistent with the specified height.
- DuplicateDisk – A rod contains a duplicate disk
- CorruptRod – A disk is on top of a disk of smaller size on a Rod.
-
__bool__
()[source]¶ A Rods is considered True if it contains any disks on any rods.
Return type: bool
-
__nonzero__
()[source]¶ A Rods is considered non-zero if it contains any disks on any rods.
Return type: bool
-
classmethod
from_json
(d)[source]¶ Return a class instance from a json serializable representation.
Parameters: d (str|dict) – The json or decoded-json from which to create a new instance. Return type: Rods
Raises: See Rods
.__new__.
-
height
¶ Retrieve the height of the rods (ie: max number of disks each one can hold).
Return type: int
-
validate
()[source]¶ Perform self validation.
Raises: - DuplicateDisk – This rod already contains this disk
- CorruptRod – A disk is on top of a disk of smaller size.