Open
Description
I have written a test case for the double tennis problem. However, I am proposing a few changes in the double tennis problem implementation. The changes are:
- Action
Hit(actor, Ball)
can be defined asHit(actor, Ball, loc)
; loc is the location the ball is approaching. - Action
Go(actor, to)
can be defined asGo(actor, to, loc)
; loc is the location the actor is currently at; to is the location the actor wants to go to. - The goal of the problem can be defined as
required = [expr('Returned(Ball)'), expr('At(a, LeftNet)'), expr('At(a, RightNet)')]
instead ofrequired= [expr('Goal(Returned(Ball))'), expr('At(a, LeftNet)'), expr('At(a, RightNet)')]
.
Below is the code for double_tennis problem and the test case for the same:
def double_tennis_problem():
init = [expr('At(A, LeftBaseLine)'),
expr('At(B, RightNet)'),
expr('Approaching(Ball, RightBaseLine)'),
expr('Partner(A, B)'),
expr('Partner(B, A)')]
def goal_test(kb):
required = [expr('Returned(Ball)'), expr('At(a, LeftNet)'), expr('At(a, RightNet)')]
return all(kb.ask(q) is not False for q in required)
# Actions
# Hit
precond_pos = [expr("Approaching(Ball,loc)"), expr("At(actor,loc)")]
precond_neg = []
effect_add = [expr("Returned(Ball)")]
effect_rem = []
hit = Action(expr("Hit(actor, Ball, loc)"), [precond_pos, precond_neg], [effect_add, effect_rem])
# Go
precond_pos = [expr("At(actor, loc)")]
precond_neg = []
effect_add = [expr("At(actor, to)")]
effect_rem = [expr("At(actor, loc)")]
go = Action(expr("Go(actor, to, loc)"), [precond_pos, precond_neg], [effect_add, effect_rem])
return PDDL(init, [hit, go], goal_test)
def test_double_tennis():
p = double_tennis_problem()
assert p.goal_test() is False
solution = [expr("Go(A, RightBaseLine, LeftBaseLine)"),
expr("Hit(A, Ball, RightBaseLine)"),
expr("Go(A, LeftNet, RightBaseLine)")]
for action in solution:
p.act(action)
assert p.goal_test()
Metadata
Metadata
Assignees
Labels
No labels