-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_generators.py
87 lines (74 loc) · 3.11 KB
/
tile_generators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Tile generator classes for Lolo puzzle game."""
"""
/-------------\
/ \
/ \
/ \
| XXXX XXXX |
| XXXX XXXX |
| XXX XXX |
\ X /
--\ XXX /--
| | XXX | |
| | | |
| I I I I I I I |
| I I I I I I |
\ /
-- --
\-------/
XXX XXX
XXXXX XXXXX
XXXXXXXXX XXXXXXXXXX
XXXXX XXXXX
XXXXXXX
XXXXX XXXXX
XXXXXXXXX XXXXXXXXXX
XXXXX XXXXX
XXX XXX
**************
* BEWARE!! *
**************
All ye who enter here:
Most of the code in this module
is twisted beyond belief!
Tread carefully.
If you think you understand it,
You Don't,
So Look Again.
"""
import game_regular
from model import AbstractTileGenerator
__author__ = "Benjamin Martin and Brae Webb"
__copyright__ = "Copyright 2017, The University of Queensland"
__license__ = "MIT"
__version__ = "1.1.2"
class LoadedGenerator(AbstractTileGenerator):
"""Tile generator based upon the values of a serialized grid."""
def __init__(self, grid):
"""Constructor
Parameters:
grid (list<list<tuple<int, int>>>): The serialized grid.
"""
print("WARNING: LoadedGenerator is deprecated and should no longer be used.")
self._grid = grid
def generate(self, position):
"""(AbstractTile) Generates a new tile."""
data = self._grid[position[0]][position[1]]
return game_regular.RegularTile(*data)
class WeightedGenerator(AbstractTileGenerator):
"""Tile generator based upon WeightedSelector value."""
def __init__(self, selector, constructor):
"""Constructor
Parameters:
selector (WeightedSelector): The weighted selector to choose from.
constructor (function):
Callable which returns the tile. Accepts two arguments:
constructor(selection, position)
- selection: The value returned from selector.choose()
- position: The position passed to the generate method.
"""
self._selector = selector
self._constructor = constructor
def generate(self, position):
"""(AbstractTile) Generates a new tile."""
return self._constructor(self._selector.choose(), position)