Code Examples
A repository of 155 code examples for BeepBeep
TurnAround.java
1 /*
2  BeepBeep processor chains for the CRV 2016
3  Copyright (C) 2016 Sylvain Hallé
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package pingus;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.Connector.ConnectorException;
22 import ca.uqac.lif.cep.GroupProcessor;
23 import ca.uqac.lif.cep.tmf.Fork;
24 import ca.uqac.lif.cep.tmf.Trim;
25 import ca.uqac.lif.cep.util.Numbers;
26 import ca.uqac.lif.cep.functions.ApplyFunction;
27 import ca.uqac.lif.cep.ltl.Always;
28 import ca.uqac.lif.cep.ltl.NewTrooleanForAll;
29 import ca.uqac.lif.cep.ltl.Troolean;
30 import ca.uqac.lif.cep.ltl.TrooleanCast;
31 import ca.uqac.lif.cep.xml.XPathFunction;
32 
33 public class TurnAround extends GroupProcessor
34 {
35  ///
36  public TurnAround() throws ConnectorException
37  {
38  super(1, 1);
39  GroupProcessor next_g = new GroupProcessor(1, 1);
40  {
41  Fork fork = new Fork(2);
42  next_g.addProcessor(fork);
43  next_g.associateInput(0, fork, 0);
44  ApplyFunction distance_x_now = new ApplyFunction(new DistanceX());
45  next_g.addProcessor(distance_x_now);
46  Connector.connect(fork, 0, distance_x_now, 0);
47  Trim next = new Trim(3);
48  next_g.addProcessor(next);
49  Connector.connect(fork, 1, next, 0);
50  ApplyFunction distance_x_later = new ApplyFunction(new DistanceX());
51  next_g.addProcessor(distance_x_later);
52  Connector.connect(next, distance_x_later);
53  ApplyFunction gt = new ApplyFunction(Numbers.isLessThan);
54  next_g.addProcessor(gt);
55  Connector.connect(distance_x_now, 0, gt, 0);
56  Connector.connect(distance_x_later, 0, gt, 1);
57  ApplyFunction cast = new ApplyFunction(TrooleanCast.instance);
58  next_g.addProcessor(cast);
59  Connector.connect(gt, cast);
60  next_g.associateOutput(0, cast, 0);
61  }
62  GroupProcessor imp_g = new GroupProcessor(1, 1);
63  Fork fork = new Fork(2);
64  imp_g.addProcessor(fork);
65  ApplyFunction collides = new ApplyFunction(new Collides());
66  imp_g.addProcessor(collides);
67  Connector.connect(fork, 0, collides, 0);
68  //imp_g.addProcessor(fa3);
69  imp_g.addProcessor(next_g);
70  Connector.connect(fork, 1, next_g, 0);
71  ApplyFunction implies = new ApplyFunction(Troolean.IMPLIES_FUNCTION);
72  imp_g.addProcessor(implies);
73  Connector.connect(collides, 0, implies, 0);
74  Connector.connect(next_g, 0, implies, 1);
75  imp_g.associateInput(0, fork, 0);
76  imp_g.associateOutput(0, implies, 0);
77  NewTrooleanForAll fa2 = new NewTrooleanForAll("p2", new XPathFunction("message/characters/character[status=BLOCKER]/id/text()"), imp_g);
78  NewTrooleanForAll fa1 = new NewTrooleanForAll("p1", new XPathFunction("message/characters/character[status=WALKER]/id/text()"), fa2);
79  Always a = new Always(fa1);
80  //Connector.connect(fa1, a);
81  associateInput(0, a, 0);
82  associateOutput(0, a, 0);
83  }
84  ///
85 }
Function |x1-x2|.
Definition: DistanceX.java:11
Predicate |x1-x2| < 6 ∧ |y1-y2| < 10.
Definition: Collides.java:13