Skip to content

Commit

Permalink
Fixes, optimizations, and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
NateKomodo committed Aug 20, 2019
1 parent 069041c commit a3590a1
Show file tree
Hide file tree
Showing 19 changed files with 507 additions and 56 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.jvmargs=-Xmx3G
mod_version=0.0.4
mod_version=0.0.6
mc_version=1.12.2
forge_version=14.23.5.2768
mappings_version=snapshot_20171003
30 changes: 30 additions & 0 deletions src/main/java/me/ktechnet/openmineai/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import me.ktechnet.openmineai.Helpers.PlayerMovement;
import me.ktechnet.openmineai.Models.Classes.PopulousAStarSearch;
import me.ktechnet.openmineai.Models.Classes.Pos;
import me.ktechnet.openmineai.Models.Enums.NodeType;
import me.ktechnet.openmineai.Models.Interfaces.INode;
import me.ktechnet.openmineai.Models.Interfaces.IPathingCallback;
import me.ktechnet.openmineai.Models.Interfaces.IPathingProvider;
import me.ktechnet.openmineai.Models.Interfaces.IRoute;
Expand All @@ -14,6 +16,7 @@
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.client.IClientCommand;

Expand Down Expand Up @@ -90,6 +93,33 @@ public void completeRouteFound(IRoute route) {
LocalDateTime now = LocalDateTime.now();
long diff = ChronoUnit.MILLIS.between(pre, now);
ChatMessageHandler.SendMessage("Found complete route, took " + diff + "ms");
for (INode node : route.path()) {
if (node.pos().IsEqual(node.master().destination())) {
Minecraft.getMinecraft().world.setBlockState(node.pos().ConvertToBlockPos(), Blocks.EMERALD_BLOCK.getDefaultState());
continue;
}
switch (node.myType()) {
case PLAYER:
Minecraft.getMinecraft().world.setBlockState(node.pos().ConvertToBlockPos(), Blocks.REDSTONE_BLOCK.getDefaultState());
break;
case MOVE:
case ASCEND_TOWER:
Minecraft.getMinecraft().world.setBlockState(node.pos().ConvertToBlockPos(), Blocks.COBBLESTONE.getDefaultState());
break;
case STEP_UP:
Minecraft.getMinecraft().world.setBlockState(node.pos().ConvertToBlockPos(), Blocks.LAPIS_BLOCK.getDefaultState());
break;
case STEP_UP_AND_BREAK:
case DESCEND_MINE:
case ASCEND_BREAK_AND_TOWER:
case BREAK_AND_MOVE:
Minecraft.getMinecraft().world.setBlockState(node.pos().ConvertToBlockPos(), Blocks.BRICK_BLOCK.getDefaultState());
break;
case STEP_DOWN:
Minecraft.getMinecraft().world.setBlockState(node.pos().ConvertToBlockPos(), Blocks.YELLOW_GLAZED_TERRACOTTA.getDefaultState());
break;
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.ktechnet.openmineai.Helpers;

import me.ktechnet.openmineai.Models.Classes.Pos;
import me.ktechnet.openmineai.Models.Enums.NodeType;

import java.util.ArrayList;

public class BrokenBlocksHelper {
public ArrayList<Pos> Broken(NodeType type, Pos pos) {
ArrayList<Pos> list = new ArrayList<>();
switch (type) {
case BREAK_AND_MOVE:
list.add(pos);
list.add(new Pos(pos.x, pos.y + 1, pos.z));
break;
case ASCEND_BREAK_AND_TOWER:
list.add(new Pos(pos.x, pos.y + 1, pos.z));
break;
case STEP_UP_AND_BREAK:
list.add(new Pos(pos.x, pos.y + 1, pos.z));
list.add(new Pos(pos.x, pos.y + 2, pos.z));
break;
case STEP_DOWN_AND_BREAK:
list.add(new Pos(pos.x, pos.y + 1, pos.z));
list.add(new Pos(pos.x, pos.y + 0, pos.z));
list.add(new Pos(pos.x, pos.y - 1, pos.z));
break;
case DESCEND_MINE:
list.add(pos);
break;
}
return list;
}
}
93 changes: 93 additions & 0 deletions src/main/java/me/ktechnet/openmineai/Helpers/NodeTypeRules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package me.ktechnet.openmineai.Helpers;

import me.ktechnet.openmineai.Models.Classes.Rule;
import me.ktechnet.openmineai.Models.Enums.Rules;
import me.ktechnet.openmineai.Models.Interfaces.IRule;

public class NodeTypeRules {
public IRule GetMove() {
IRule rule = new Rule();
rule.PushToStack(1, Rules.PASSABLE);
rule.PushToStack(0, Rules.PASSABLE);
rule.PushToStack(-1, Rules.IMPASSABLE_NOT_LAVA);
return rule;
}
public IRule GetStepUp() {
IRule rule = new Rule();
rule.PushToStack(2, Rules.PASSABLE);
rule.PushToStack(1, Rules.PASSABLE);
rule.PushToStack(0, Rules.IMPASSABLE_NOT_LAVA);
return rule;
}
public IRule GetStepUpAndBreak() { //TODO this may cause diagonal tunneling, testing needed
IRule rule = new Rule();
rule.ruleMeta().CheckBreakableLavaAdj = true;
rule.PushToStack(2, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(1, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(0, Rules.IMPASSABLE_NOT_LAVA);
return rule;
}
public IRule GetStepDown() {
IRule rule = new Rule();
rule.PushToStack(1, Rules.PASSABLE);
rule.PushToStack(0, Rules.PASSABLE);
rule.PushToStack(-1, Rules.PASSABLE);
rule.PushToStack(-2, Rules.IMPASSABLE_NOT_LAVA);
return rule;
}
public IRule GetStepDownAndBreak() { //TODO this may cause diagonal tunneling, testing needed
IRule rule = new Rule();
rule.ruleMeta().CheckBreakableLavaAdj = true;
rule.PushToStack(1, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(0, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(-1, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(-2, Rules.IMPASSABLE_NOT_LAVA);
return rule;
}
public IRule GetBreakAndMove() {
IRule rule = new Rule();
rule.ruleMeta().CheckBreakableLavaAdj = true;
rule.PushToStack(1, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(0, Rules.BREAKABLE_OR_PASSABLE);
rule.PushToStack(-1, Rules.IMPASSABLE_NOT_LAVA);
return rule;
}
public IRule GetDecentOrParkourOrBridge() {
IRule rule = new Rule();
rule.ruleMeta().CheckBreakableLavaAdj = true;
rule.PushToStack(0, Rules.PASSABLE);
rule.PushToStack(-1, Rules.PASSABLE);
rule.PushToStack(-2, Rules.PASSABLE);
return rule;
}
public IRule GetTower() {
IRule rule = new Rule();
rule.PushToStack(1, Rules.PASSABLE);
rule.PushToStack(0, Rules.PASSABLE);
return rule;
}
public IRule GetBreakAndTower() {
IRule rule = new Rule();
rule.ruleMeta().CheckBreakableLavaAdj = true;
rule.PushToStack(1, Rules.BREAKABLE);
rule.PushToStack(0, Rules.PASSABLE);
return rule;
}
public IRule GetLadder() {
IRule rule = new Rule();
rule.PushToStack(0, Rules.CLIMBABLE);
return rule;
}
public IRule GetRareDrop() {
IRule rule = new Rule();
rule.PushToStack(0, Rules.PASSABLE);
return rule;
}
public IRule GetDescentMine() {
IRule rule = new Rule();
rule.ruleMeta().CheckBreakableLavaAdj = true;
rule.PushToStack(1, Rules.PASSABLE);
rule.PushToStack(0, Rules.BREAKABLE);
return rule;
}
}
32 changes: 11 additions & 21 deletions src/main/java/me/ktechnet/openmineai/Models/Classes/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Node implements INode {
private Node me = this;


Node(NodeType type, IPathingProvider master, INode parent, int currentCost, int myCost, Pos myPos, Pos destination, int TTL) { //TODO am i a replicant or not
Node(NodeType type, IPathingProvider master, INode parent, int currentCost, int myCost, Pos myPos, Pos destination, int TTL) { //TODO am i a replicant or not, fix adj to destination but solid block issue
this.myType = type;
this.master = master;
this.parent = parent;
Expand All @@ -53,24 +53,7 @@ public class Node implements INode {
master.nodeManifest().put(myPos, this);
//TODO check for collisions, and partial backprop
optionProvider = new OptionProvider(this);
if (type == NodeType.PLAYER) {
//ChatMessageHandler.SendMessage("PlayerNode");
Minecraft.getMinecraft().world.setBlockState(myPos.ConvertToBlockPos(), Blocks.REDSTONE_BLOCK.getDefaultState());
} else if (myPos.IsEqual(destination)) {
//ChatMessageHandler.SendMessage("Dest");
Minecraft.getMinecraft().world.setBlockState(myPos.ConvertToBlockPos(), Blocks.EMERALD_BLOCK.getDefaultState());
} else {
//ChatMessageHandler.SendMessage("Node, proxim to dest: " + DistanceHelper.CalcDistance(myPos, master.destination()) + " TTL: " + TTL + " myPos: " + myPos.x + "," + myPos.y + "," + myPos.z+ " dest: " + destination.x + "," + destination.y + "," + destination.z + " Type: " + myType);
switch (myType)
{
case STEP_DOWN:
Minecraft.getMinecraft().world.setBlockState(myPos.ConvertToBlockPos(), Blocks.LAPIS_BLOCK.getDefaultState());
case STEP_UP:
Minecraft.getMinecraft().world.setBlockState(myPos.ConvertToBlockPos(), Blocks.YELLOW_GLAZED_TERRACOTTA.getDefaultState());
case MOVE:
Minecraft.getMinecraft().world.setBlockState(myPos.ConvertToBlockPos(), Blocks.COBBLESTONE.getDefaultState());
}
}
Main.logger.info("Node, proxim to dest: " + DistanceHelper.CalcDistance(myPos, master.destination()) + " TTL: " + TTL + " myPos: " + myPos.x + "," + myPos.y + "," + myPos.z+ " dest: " + destination.x + "," + destination.y + "," + destination.z + " Type: " + myType);
}


Expand Down Expand Up @@ -131,6 +114,7 @@ public void Backpropagate(BackpropagateCondition condition, ArrayList<INode> pat
path.add(this);
parent.Backpropagate(condition, path);
} else {
path.add(this);
master.RouteFound(condition, path);
}
}
Expand All @@ -152,8 +136,14 @@ public int compare(IOption o1, IOption o2) {
return Integer.compare(o1.cost(), o2.cost());
}
});
if (!(options.size() > 0)) return;
if (!(options.size() > 0)) {
ChatMessageHandler.SendMessage("No options found.");
return;
}
if (options.get(0).cost() > options.get(options.size() - 1).cost()) Collections.reverse(options);
for (IOption opt : options) {
Main.logger.info("Candidate: " + opt.typeCandidate() + " Cost: " + opt.cost());
}
IOption option1 = options.get(0);
//IOption option2 = options.get(1); Note: make sure there are sufficient choices
//IOption option3 = options.get(2);
Expand All @@ -175,7 +165,7 @@ public int compare(IOption o1, IOption o2) {
// }
//};
//new Thread(runnable2).start();
Node node = new Node(option1.typeCandidate(), master, me, costToMe, option1.cost(), option1.position(), destination, TTL - 1);
Node node = new Node(option1.typeCandidate(), master, me, costToMe + option1.cost(), option1.cost(), option1.position(), destination, TTL - 1);
children.add(node);
node.SpawnChildren();
}
Expand Down
Loading

0 comments on commit a3590a1

Please sign in to comment.