Rod¶
Note
A tower that contains Disks.
-
class
towers.core.rod.
Rod
[source]¶ A single tower containing disks.
-
__deepcopy__
(*d)[source]¶ Return a deep copy of this instance.
Parameters: d (dict) – Memoisation dict. Return type: Rod
-
__eq__
(other)[source]¶ Compare Rod instances for equivalence.
Parameters: other (Rod) – Return type: bool
-
static
__new__
(name, disks=None, height=0)[source]¶ Parameters: - name (str) – The name of the rod.
- disks (List[Disk]) – (optional) mutatable list of Disks.
- height (int) – The height of the rod.
Return type: Raises: See Rod.validate.
-
append
(disk, validate=True)[source]¶ Append the disk to this rod and optionally validate.
Parameters: - disk (Disk) – The disk to add to the top of our rod.
- validate (bool) – True=perform self validation.
-
classmethod
from_json
(d)[source]¶ Return a class instance from a json serializable representation.
Parameters: d (Union[str,dict]) – The json or decoded-json from which to create a new instance. Return type: Rod Raises: See Rod.__new__.
-
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.
- InvalidTowerHeight – The height of the tower is invalid.
- InvalidDiskPosition – The position of the disk is invalid.
-