-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute.py
More file actions
39 lines (29 loc) · 1.3 KB
/
Copy pathattribute.py
File metadata and controls
39 lines (29 loc) · 1.3 KB
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
from collections import OrderedDict
import numpy as np
class Attribute:
''' Attribute class for card attributes. '''
def __init__(self, name, options):
''' Set name (e.g. 'color') and options (e.g. ['red', 'blue', 'green']). '''
# set initial values
self.name = name
self.options = sorted(options)
# set number of options for this attribute
self.num_options = len(self.options)
def value2index(self, value):
''' Convert value to index, e.g. 'blue' to 1. '''
return self.options.index(value)
def index2value(self, index):
''' Convert index to value, e.g. 2 to 'green'. '''
return self.options[index]
colors = Attribute('color', ['red', 'blue', 'green'])
fills = Attribute('fill', ['empty', 'dots', 'filled'])
shapes = Attribute('shape', ['square', 'triangle', 'circle'])
counts = Attribute('count', ['1', '2', '3'])
attributes_listed = [colors, fills, shapes, counts]
attributes_dict = dict(
zip([attr.name for attr in attributes_listed], attributes_listed))
# Set importable constants
CARD_ATTRIBUTES = OrderedDict(sorted(attributes_dict.items()))
NUMBER_OF_OPTIONS_PER_PROPERTY = [
attribute.num_options for attribute in CARD_ATTRIBUTES.values()]
NUMBER_OF_PLAYABLE_CARDS = np.prod(NUMBER_OF_OPTIONS_PER_PROPERTY)