Search in sources :

Example 21 with Agent

use of com.google.cloud.dialogflow.cx.v3beta1.Agent in project cg by nmahoude.

the class MC2 method think.

public void think(Agent originalMe, Agent originalOpp) {
    Agent me = new Agent(0);
    Agent opp = new Agent(1);
    double bestScore = Double.NEGATIVE_INFINITY;
    bestActions[0] = Action.pass();
    bestActionsFE = 1;
    int iter = 0;
    while (true) {
        iter++;
        me.copyFrom(originalMe);
        opp.copyFrom(originalOpp);
        currentActionsFE = 0;
        boolean stop = false;
        while (!stop) {
            if (Player.random.nextInt(100) > 98) {
                stop = true;
            } else {
                possibleActionsFE = 0;
                // TODO possible de precompute tous les summon possible pour pick dedans sur le 1er tour
                computeSummons(me);
                computeAttacks(me, opp);
                computeUse(me, opp);
                if (possibleActionsFE == 0) {
                    stop = true;
                } else {
                    int rand = Player.random.nextInt(possibleActionsFE);
                    Action chosen = possibleActions[rand];
                    currentActions[currentActionsFE++] = chosen;
                    sim.run(me, opp, chosen);
                }
            }
        }
        double minScoreOpp;
        if (opp.face.defense <= 0 || me.face.defense <= 0) {
            minScoreOpp = scorer.score(me, opp);
        } else {
            minScoreOpp = minimizeOpp(me, opp);
        }
        // scorer.score(me, opp);
        double score = minScoreOpp;
        if (score > bestScore) {
            bestScore = score;
            bestActionsFE = currentActionsFE;
            Action[] tmp = currentActions;
            currentActions = bestActions;
            bestActions = tmp;
        // if (Player.turn == 37) {
        // if (bestScore == Double.POSITIVE_INFINITY) {
        // System.err.println("Current best score is "+bestScore);
        // System.err.println("Current actions ");
        // for (int i=0;i<bestActionsFE;i++) {
        // System.err.print(bestActions[i]);
        // }
        // System.err.println();
        // System.err.println("opp board");
        // opp.debugBoardCards();
        // 
        // System.err.println("-------------------- RETRO --------------------------");
        // me.copyFrom(originalMe);
        // opp.copyFrom(originalOpp);
        // System.err.println("Original opp board  ");
        // originalOpp.debugBoardCards();
        // System.err.println("Current opp board  ");
        // opp.debugBoardCards();
        // for (int i=0;i<bestActionsFE;i++) {
        // System.err.println("Apply action "+bestActions[i]);
        // sim.run(me, opp, bestActions[i]);
        // System.err.println("Result = ");
        // opp.debugBoardCards();
        // }
        // 
        // 
        // System.err.println("-------------------- RETRO --------------------------");
        // }
        // }
        }
        if (iter % 255 == 0) {
            if (System.currentTimeMillis() - Player.start > 90) {
                break;
            }
        }
    }
    System.err.println("Iterations = " + iter);
    if (bestActionsFE != 0) {
        me.copyFrom(originalMe);
        opp.copyFrom(originalOpp);
        for (int i = 0; i < bestActionsFE; i++) {
            System.err.println("Action = " + bestActions[i]);
            bestActions[i].print(me, opp, System.out);
            System.out.print(";");
            sim.run(me, opp, bestActions[i]);
        }
        // policy: attack with all remaining cards
        if (opp.guardsCount == 0) {
            for (int i = 1; i < me.boardCardsFE; i++) {
                Card myCard = me.boardCards[i];
                if (myCard.isDead())
                    continue;
                if (!myCard.canAttack)
                    continue;
                Action.attack(i, -1).print(me, opp, System.out);
            }
        }
        System.out.println();
    } else {
        System.err.println("No best node");
        System.out.println("PASS");
    }
}
Also used : Agent(lcm2.Agent) Action(lcm2.simulation.Action) Card(lcm2.cards.Card)

Example 22 with Agent

use of com.google.cloud.dialogflow.cx.v3beta1.Agent in project java-dialogflow by googleapis.

the class SetAgent method setAgent.

public static Agent setAgent(String parent, String displayName) throws IOException {
    AgentsSettings agentsSettings = AgentsSettings.newBuilder().build();
    try (AgentsClient client = AgentsClient.create(agentsSettings)) {
        // Set the details of the Agent to create
        Builder build = Agent.newBuilder();
        build.setDefaultLanguageCode("en");
        build.setDisplayName(displayName);
        Agent agent = build.build();
        // Make API request to create agent
        Agent response = client.setAgent(agent);
        System.out.println(response);
        return response;
    }
}
Also used : Agent(com.google.cloud.dialogflow.v2.Agent) AgentsSettings(com.google.cloud.dialogflow.v2.AgentsSettings) AgentsClient(com.google.cloud.dialogflow.v2.AgentsClient) Builder(com.google.cloud.dialogflow.v2.Agent.Builder)

Example 23 with Agent

use of com.google.cloud.dialogflow.cx.v3beta1.Agent in project java-dialogflow by googleapis.

the class ITSystemTest method getAgentTest.

@Test
public void getAgentTest() {
    GetAgentRequest request = GetAgentRequest.newBuilder().setParent(PROJECT_NAME.toString()).build();
    Agent actualAgent = agentsClient.getAgent(request);
    assertEquals(PROJECT_NAME.toString(), actualAgent.getParent());
    assertEquals(DISPLAY_NAME, actualAgent.getDisplayName());
    assertEquals(DEFAULT_LANGUAGE_CODE, actualAgent.getDefaultLanguageCode());
    assertEquals(TIME_ZONE, actualAgent.getTimeZone());
    assertEquals(Agent.MatchMode.MATCH_MODE_HYBRID, actualAgent.getMatchMode());
    assertEquals(Agent.ApiVersion.API_VERSION_V2, actualAgent.getApiVersion());
    assertEquals(Agent.Tier.TIER_STANDARD, actualAgent.getTier());
}
Also used : Agent(com.google.cloud.dialogflow.v2.Agent) GetAgentRequest(com.google.cloud.dialogflow.v2.GetAgentRequest) Test(org.junit.Test)

Example 24 with Agent

use of com.google.cloud.dialogflow.cx.v3beta1.Agent in project java-dialogflow-cx by googleapis.

the class FlowsClientTest method listFlowsTest.

@Test
public void listFlowsTest() throws Exception {
    Flow responsesElement = Flow.newBuilder().build();
    ListFlowsResponse expectedResponse = ListFlowsResponse.newBuilder().setNextPageToken("").addAllFlows(Arrays.asList(responsesElement)).build();
    mockFlows.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListFlowsPagedResponse pagedListResponse = client.listFlows(parent);
    List<Flow> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getFlowsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFlows.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListFlowsRequest actualRequest = ((ListFlowsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListFlowsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.FlowsClient.ListFlowsPagedResponse) Test(org.junit.Test)

Example 25 with Agent

use of com.google.cloud.dialogflow.cx.v3beta1.Agent in project java-dialogflow-cx by googleapis.

the class IntentsClientTest method listIntentsTest.

@Test
public void listIntentsTest() throws Exception {
    Intent responsesElement = Intent.newBuilder().build();
    ListIntentsResponse expectedResponse = ListIntentsResponse.newBuilder().setNextPageToken("").addAllIntents(Arrays.asList(responsesElement)).build();
    mockIntents.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
    List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockIntents.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListIntentsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.IntentsClient.ListIntentsPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 AbstractMessage (com.google.protobuf.AbstractMessage)18 Agent (com.google.cloud.dialogflow.cx.v3.Agent)4 Builder (com.google.cloud.dialogflow.cx.v3.Agent.Builder)4 AgentsClient (com.google.cloud.dialogflow.cx.v3.AgentsClient)4 AgentsSettings (com.google.cloud.dialogflow.cx.v3.AgentsSettings)4 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)4 Agent (com.google.cloud.dialogflow.v2.Agent)3 ArrayList (java.util.ArrayList)3 AgentName (com.google.cloud.dialogflow.cx.v3beta1.AgentName)2 ListAgentsPagedResponse (com.google.cloud.dialogflow.cx.v3beta1.AgentsClient.ListAgentsPagedResponse)2 Flow (com.google.cloud.dialogflow.cx.v3beta1.Flow)2 Intent (com.google.cloud.dialogflow.cx.v3beta1.Intent)2 Page (com.google.cloud.dialogflow.cx.v3beta1.Page)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Agent (lcm2.Agent)2 Action (lcm2.simulation.Action)2 NamespaceBinding (org.sbolstandard.core.datatree.Datatree.NamespaceBinding)2 NamespaceBinding (org.sbolstandard.core.datatree.NamespaceBinding)2