-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCubeSide.py
79 lines (65 loc) · 2.2 KB
/
CubeSide.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
from unified_planning.shortcuts import Not, And
from AIROB.domain import PDDLObject
from AIROB.domain.decorators import PDDLEffect, PDDLPrecondition, PDDLPredicate, PDDLType, PDDLAction
@PDDLType
class CubeSide(PDDLObject):
def __init__(self, up: bool, idx: int, cube_ref: int):
super().__init__()
self.painted = False
self.up = up
self.dry = True
self.idx = idx
self.cube = cube_ref
def get_id(self) -> str:
return f"Cube_{self.cube}_side_{self.idx}"
def isPainted(self: 'CubeSide'):
return self.painted
def isUp(self: 'CubeSide'):
return self.up
def setUp(self, up):
self.up = up
@PDDLPredicate()
def dry(self: 'CubeSide'):
return self.isDry()
def isDry(self):
return self.dry
def setDry(self, d: bool):
self.dry = d
@PDDLPredicate()
def painted(self: 'CubeSide'):
return self.isPainted()
@PDDLPredicate()
def up(self: 'CubeSide'):
return self.isUp()
@PDDLPrecondition(lambda cube, side, brush: And(
Not(side.painted()),
side.up(),
cube.cube_has_side(side),
cube.loaded(),
brush.picked(),
brush.hasColor()
))
@PDDLEffect(lambda cube, side: side.painted(), True)
@PDDLEffect(lambda cube, side: side.dry(), False)
@PDDLEffect(lambda brush: brush.hasColor(), False)
@PDDLAction()
def paint(side: 'CubeSide', cube: 'Cube', brush: 'Brush'):
print(
f"Painting side {side.idx} of cube {side.cube} with brush {brush.idx}") # (Side was {'up' if side.isUp() else 'down'})
side.painted = True
side.dry = False
@PDDLPrecondition(lambda cube, dryer, side: And(
side.painted(),
side.up(),
dryer.picked(),
dryer.turnedOn(),
Not(side.dry()),
cube.cube_has_side(side),
cube.loaded()))
@PDDLEffect(lambda cube, side: side.dry(), True)
@PDDLAction()
def drySide(side: 'CubeSide', cube: 'Cube', dryer: 'Dryer'):
print(f"Drying side {side.idx} of cube {side.cube} using dryer {dryer.idx}")
side.dry = True
def __str__(self):
return f"CubeSide:{self.painted, self.up}"