use of com.google.cloud.dialogflow.cx.v3.Agent in project study-prj by SaminZou.
the class Client method main.
public static void main(String[] args) {
// style1
// 代理者和被代理者必须实现同一个接口 代理者的目的是隐藏被代理者的行为
Subject star = new Star();
Subject proxy = new Agent(star);
proxy.movie();
System.out.println("-------------------------------------------------------");
// style2
// 这种方式是客户端直接访问被代理角色,代理由被代理角色指定。
// 前面的一种方式则是客户端不能访问直接访问被代理角色,只能访问代理。
Subject2 star2 = new Star2();
Subject2 proxy2 = star2.getAgent();
proxy2.movie();
}
use of com.google.cloud.dialogflow.cx.v3.Agent in project cg by nmahoude.
the class MoveAI method think.
public void think(State currentState) {
state.copyFrom(currentState);
Agent agent = state.agents[0];
BFS bfs = new BFS();
bfs.process(state, agent.pos, MAX_MOVE);
Route emptyRoute = new Route();
emptyRoute.state.copyFrom(currentState);
List<Route> allRoutes = new ArrayList<>();
allRoutes.add(emptyRoute);
boolean foundNewRoutes = true;
while (foundNewRoutes) {
List<Route> newRoutesToCheck = new ArrayList<>();
foundNewRoutes = false;
System.err.println("Total routes : " + allRoutes.size());
for (Route route : allRoutes) {
if (route.explored)
continue;
route.explored = true;
List<Route> newRoutes = route.findRouteToAnyQuestItem();
System.err.println("Checking route : " + route.debug());
System.err.println(" => found " + newRoutes.size() + " new routes to questItems");
if (!newRoutes.isEmpty()) {
foundNewRoutes = true;
newRoutesToCheck.addAll(newRoutes);
}
}
allRoutes.addAll(newRoutesToCheck);
}
// now find the best route ...
double bestScore = Double.NEGATIVE_INFINITY;
Route best = null;
for (Route route : allRoutes) {
double score = route.questItemsFound * 100;
if (score > bestScore) {
bestScore = score;
best = route;
}
}
if (best != null && !best.route.isEmpty()) {
// remove objects
best.state.applyMoves(best.route);
best = best.goToBestSpotForNextPush();
List<Pos> route = best.route;
actions = rebuildFromRoute(route);
return;
} else {
best = emptyRoute.goToBestSpotForNextPush();
List<Pos> route = best.route;
if (route.size() > 1) {
actions = rebuildFromRoute(route);
} else {
actions = PASS;
}
return;
}
}
use of com.google.cloud.dialogflow.cx.v3.Agent in project cg by nmahoude.
the class Simulation method computePush.
private void computePush() {
Dir[] validDirs = move.dir1.pushDirections();
boolean validPushDirection = (move.dir2 == validDirs[0]) || (move.dir2 == validDirs[1]) || (move.dir2 == validDirs[2]);
if (!validPushDirection) {
// dir2 is invalid
move.dir2Invalid();
return;
}
int targetX = agent.x + move.dir1.dx;
int targetY = agent.y + move.dir1.dy;
Agent pushed = state.agents[state.occupiedBy(targetX, targetY)];
int pushToX = targetX + move.dir2.dx;
int pushToY = targetY + move.dir2.dy;
if ((!state.isValid(pushToX, pushToY)) || (state.isOccupied(move.id, pushToX, pushToY))) {
move.dir2Invalid();
return;
}
int pushToHeight = state.getHeight(pushToX, pushToY);
int pushFromHeight = state.getHeight(targetX, targetY);
if (pushToHeight >= FINAL_HEIGHT || pushToHeight > pushFromHeight + 1) {
move.dir2Invalid();
return;
}
// TODO check if we know a agent is at pushTo and would block the action ?
// move ok, update agent position & grid
agent.x = agent.x;
agent.y = agent.y;
state.setHeight(targetX, targetY, pushFromHeight + 1);
pushed.x = pushToX;
pushed.y = pushToY;
move.dir1X = targetX;
move.dir1Y = targetY;
move.dir1Height = pushFromHeight;
move.dir2X = pushToX;
move.dir2Y = pushToY;
move.dir2Height = pushToHeight;
move.allValid();
return;
}
use of com.google.cloud.dialogflow.cx.v3.Agent in project cg by nmahoude.
the class MC2 method minimizeOpp.
private double minimizeOpp(Agent originalMe, Agent originalOpp) {
Agent me = new Agent(0);
Agent opp = new Agent(1);
// inverse both players
me.copyFrom(originalOpp);
opp.copyFrom(originalMe);
double minScore = scorer.score(originalMe, originalOpp);
for (int i = 0; i < 200; i++) {
oppCurrentActionsFE = 0;
boolean stop = false;
while (!stop) {
if (Player.random.nextInt(100) > 98) {
stop = true;
} else {
possibleActionsFE = 0;
computeAttacks(me, opp);
if (possibleActionsFE == 0) {
stop = true;
} else {
int rand = Player.random.nextInt(possibleActionsFE);
Action chosen = possibleActions[rand];
oppCurrentActions[oppCurrentActionsFE++] = chosen;
sim.run(me, opp, chosen);
}
}
}
minScore = Math.min(scorer.score(opp, me), minScore);
}
return minScore;
}
use of com.google.cloud.dialogflow.cx.v3.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");
}
}
Aggregations