2048-ml

git clone git://git.codymlewis.com/2048-ml.git
Log | Files | Refs | README | LICENSE

Tile.py (527B)


      1 '''
      2 Object for the 2048 tile
      3 '''
      4 
      5 
      6 class Tile:
      7     '''
      8     2048 Tile class
      9     '''
     10 
     11     def __init__(self, value, max_num_len=1):
     12         self.__value = value
     13         self.max_num_len = max(max_num_len, len(str(value)))
     14 
     15     def __add__(self, other):
     16         return Tile(self.__value + int(other))
     17 
     18     def __eq__(self, other):
     19         return isinstance(other, Tile) and self.__value == int(other)
     20 
     21     def __str__(self):
     22         return f"{self.__value:{self.max_num_len}d}"
     23 
     24     def __int__(self):
     25         return self.__value