package greycat.samples.Battleground;




import greycat.*;
import static greycat.Tasks.*;
import static greycat.internal.task.CoreActions.*;


public class BattlegroundOntology {

    public static void main(String[] args) {

        //Create a minimal graph with the default configuration
        Graph g = new GraphBuilder().build();

        //Connect the graph
        g.connect((Boolean isConnected) -> {
            //Display that the graph database is connected!
            System.out.println("Connected : " + isConnected);

            //TRYING HERE !!!
            newTask()
                    .loop("1","10",
                            newTask()
                                .then(createNode())
                                .then(setAttribute("name",Type.STRING,"node_{{i}}"))
                                .then(setAttribute("type",Type.STRING,"Tank"))
                                    ///Trying to math i
                                .then(setAttribute("power",Type.DOUBLE,"{{i}}"))
                                .then(travelInTime("0"))
                                .then(println("{{result}}")))

                    .execute(g,null);

            newTask()
                    .loop("1","14",
                            newTask()
                                    .then(createNode())
                                    .then(setAttribute("name",Type.STRING,"node_{{i}}"))
                                    .then(setAttribute("type",Type.STRING,"Target"))
                                    .then(setAttribute("resilience",Type.DOUBLE,"{{i}}"))
                                    .then(travelInTime("0"))
                                    .then(println("{{result}}")))

                    .execute(g,null);

            /*
            loop("0", "3",
                    .newNode()
                            .setProperty("name", Type.STRING, "node_{{i}}")
                            .print("{{result}}")
            ).execute(g,null);
            /////


            Node sensor0 = g.newNode(0, 0); //create a new node for world 0 and time 0
            sensor0.set("sensorId", Type.INT, 12); //set the id attribute as an integer
            sensor0.set("name",Type.STRING, "sensor0"); //set the name attribute as a string

            //Display the first node we created
            System.out.println(sensor0); //print {"world":0,"time":0,"id":1,"sensorId":12,"name":"sensor0"}

            Node room0 = g.newNode(0, 0); //create new node for world 0 and time 0
            room0.set("name",Type.STRING, "room0"); //set the name attribute
            room0.addToRelation("sensors", sensor0); //add the sensor0 to the relation sensors of room0

            //Let's display the room0 node to see what's inside
            System.out.println(room0); //print {"world":0,"time":0,"id":2,"name":"room0","sensors":[1]}

            //iterate over the saved sensors relation from room0
            room0.relation("sensors", (Node[] sensors) -> {
                System.out.println("Relationship Sensors:");
                for (Node sensor : sensors) {
                    System.out.println("\t" + sensor.toString());
                }

                //Disconnect the database
                g.disconnect(result -> {
                    System.out.println("GoodBye!");
                });

            }); */


            g.disconnect(result -> {
                System.out.println("GoodBye!");
            });
        });
    }

}

@@ -49,24 +49,140 @@
  greycat.*;%0A
+import greycat.internal.task.math.MathExpressionEngine;%0Aimport greycat.internal.task.math.CoreMathExpressionEngine;%0A
 import stati
@@ -805,113 +805,1562 @@
     
-.then(createNode())%0A                                .then(setAttribute(%22name%22,Type.STRING,%22node_%7B%7Bi%7D%7D%22))%0A
+    ///Trying to math i%0A                                   /*.thenDo(new ActionFunction() %7B%0A                                        @Override%0A                                        public void eval(TaskContext taskContext) %7B%0A                                            MathExpressionEngine engine = CoreMathExpressionEngine.parse(%225*4%22);%0A                                            double res = engine.eval(null,null,null);%0A                                            taskContext.continueTask();%0A                                        %7D%0A                                    %7D)*/%0A                                    //.then(inject(10))%0A                                    //.then(defineAsVar(%22it%22))%0A                                    //.then(print(%22%7B%7Bit%7D%7D%22))%0A                                    //.inject(%22%7B%7B=4*i%7D%7D%22)%0A                                    .thenDo(new ActionFunction() %7B%0A                                        @Override%0A                                        public void eval(TaskContext ctx) %7B%0A                                            ctx.continueWith(ctx.wrap(ctx.template(%22%7B%7B=4*i%7D%7D%22)).clone());%0A                                        %7D%0A                                    %7D)%0A                                   //.log(%22%7B%7Bresult%7D%7D%22)%0A                                   // .then(inject(CoreMathExpressionEngine.parse(%224*%7B%7Bi%7D%7D%22).eval(null,null,null)))%0A                                    .then(defineAsVar(%22res%22))%0A                                    .then(println(%22%7B%7Bres%7D%7D%22))%0A                                    .then(createNode())%0A    
     
@@ -2399,35 +2399,35 @@
 n(setAttribute(%22
-typ
+nam
 e%22,Type.STRING,%22
@@ -2430,12 +2430,18 @@
 NG,%22
-Tank
+node_%7B%7Bi%7D%7D
 %22))%0A
@@ -2476,36 +2476,67 @@
         
-///Trying to math i%0A
+.then(setAttribute(%22type%22,Type.STRING,%22Tank%22))%0A    
         
@@ -2593,39 +2593,45 @@
 ,Type.DOUBLE,%22%7B%7B
-i
+res
 %7D%7D%22))%0A
+    
                 
@@ -2663,32 +2663,36 @@
 velInTime(%220%22))%0A
+    
                 

Test commit