Skip to content

Commit

Permalink
Holy mother of conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Meshulam Silk committed Feb 6, 2014
2 parents 453ec39 + a072e38 commit 3a9a939
Show file tree
Hide file tree
Showing 77 changed files with 1,906 additions and 1,100 deletions.
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="/Users/MeshulamSilk/Documents/workspace/Grame/res/Libraries/mail.jar"/>
<classpathentry kind="lib" path="res"/>
<classpathentry kind="lib" path="/MooConsole/Build/MooConsole.jar"/>
<classpathentry kind="lib" path="/MooCommands/Build/MooCommands.jar"/>
<classpathentry kind="lib" path="/Mootilities/Build/Mootilities.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
bin/*
bin/
*.class
JavaDoc/*
*.class
.classpath
.DS_Store
.settings/
.settings/

*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# TeXlipse plugin
.texlipse

.DS_STORE
73 changes: 73 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#Sun Nov 24 07:00:48 IST 2013
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6
Binary file modified Build/Grame.jar
Binary file not shown.
Binary file added src/com/moomoohk/Grame/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.moomoohk.Grame.AI;
package com.moomoohk.Grame.Basics.AI;

import java.awt.Color;
import java.io.Serializable;
import java.util.ArrayList;

import com.moomoohk.Grame.Basics.Dir;
import com.moomoohk.Grame.Basics.Entity;
import com.moomoohk.Grame.Basics.MovementAI;
import com.moomoohk.Grame.Basics.Schematic;
import com.moomoohk.Grame.Essentials.Base;
import com.moomoohk.Grame.Essentials.Coordinates;
import com.moomoohk.Grame.Essentials.GrameManager;
import com.moomoohk.Grame.Essentials.GrameObjectLayer;
import com.moomoohk.Grame.Essentials.GrameUtils;
import com.moomoohk.Grame.Graphics.PlainGridRender;
import com.moomoohk.Grame.Graphics.RenderManager;
import com.moomoohk.Grame.Interfaces.MainGrameClass;
import com.moomoohk.Grame.Interfaces.MovementAI;
import com.moomoohk.Grame.Core.Coordinates;
import com.moomoohk.Grame.Core.GrameManager;
import com.moomoohk.Grame.Core.GrameObjectLayer;
import com.moomoohk.Grame.Core.GrameUtils;
import com.moomoohk.Grame.Core.Grid;
import com.moomoohk.Grame.Core.MainGrameClass;
import com.moomoohk.Grame.Core.Graphics.CleanGridRender;
import com.moomoohk.Grame.Core.Graphics.RenderManager;

public class AStarPathfindingMovementAI extends MovementAI implements MainGrameClass
{
Expand All @@ -37,23 +37,23 @@ public String author()
}

@Override
public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2)
public Coordinates getNext(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2)
{
if (ent1.getPos(b.ID).distance(ent2.getPos(b.ID)) == 1)
if (ent1.getPos(g.ID).distance(ent2.getPos(g.ID)) == 1)
return pos;
if (cachedTargetPos != null)
if (cachedTargetPos.equals(targetPos))
{
Node last = getLast(cachedNodePath.get(cachedNodePath.size() - 1));
if (cachedNodePath.remove(last)) //TODO: Fix this list
if (cachedNodePath.remove(last))
return last.getPos();
}
else
{
if (showVisualization)
b.setFloorColor(Color.white);
g.setFloorColor(Color.white);
if (showCosts)
RenderManager.clearText(b.ID);
RenderManager.clearText(g.ID);
cachedTargetPos = targetPos;
}
else
Expand All @@ -70,11 +70,11 @@ public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entit
if (!current.getPos().equals(pos))
closed.add(current);
open.remove(current);
if (current.getPos().distance(ent2.getPos(b.ID)) == 1)
if (current.getPos().distance(ent2.getPos(g.ID)) == 1)
break;
for (Coordinates sur : current.getPos().getAllSurrounding(b))
for (Coordinates sur : current.getPos().getAllSurrounding(g))
{
if (!b.isInBase(sur) || b.isOccupied(sur) || contains(closed, sur))
if (!g.isInGrid(sur) || g.isOccupied(sur) || contains(closed, sur))
{
open.remove(getNodeFromList(open, sur));
continue;
Expand All @@ -93,15 +93,14 @@ public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entit
while (current.getPos() != targetPos); //FIXME: NullPointerException when can't reach target

Node node = getLast(closed.get(closed.size() - 1));
// visualizationColor = new Color(new Random().nextFloat(), new Random().nextFloat(), new Random().nextFloat());
if (showCosts || showVisualization)
for (int i = 0; i < closed.size(); i++)
{
if (showVisualization)
b.setFloorColor(closed.get(i).getPos(), new Color((255 - ((255 - visualizationColor.getRed()) / closed.size() * i)), (255 - ((255 - visualizationColor.getGreen()) / closed.size() * i)), (255 - ((255 - visualizationColor.getBlue()) / closed.size() * i))));
g.setFloorColor(closed.get(i).getPos(), new Color((255 - ((255 - visualizationColor.getRed()) / closed.size() * i)), (255 - ((255 - visualizationColor.getGreen()) / closed.size() * i)), (255 - ((255 - visualizationColor.getBlue()) / closed.size() * i))));
if (showCosts)
RenderManager.setText(b.ID, new Coordinates(closed.get(i).getPos().getY(), closed.get(i).getPos().getX()), /*"F" + (int)(calcG(current, closed.get(i).getPos()) + calcH(closed.get(i).getPos(), targetPos))*/
"G" + (int) calcG(current, closed.get(i).getPos()) + "H" + (int) calcH(closed.get(i).getPos(), targetPos), costColor);
RenderManager.setText(g.ID, new Coordinates(closed.get(i).getPos().getY(), closed.get(i).getPos().getX()), /*"F" + (int)(calcG(current, closed.get(i).getPos()) + calcH(closed.get(i).getPos(), targetPos))*/
"G" + (int) calcG(current, closed.get(i).getPos()) + "H" + (int) calcH(closed.get(i).getPos(), targetPos), costColor);
}

cachedNodePath = closed;
Expand Down Expand Up @@ -166,9 +165,26 @@ private Node findLowestFCost(ArrayList<Node> open)
}

@Override
public boolean isValid(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2)
public boolean isValid(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2)
{
return !pos.isSurrounded(b);
// boolean[][] checked = new boolean[b.getRows()][b.getColumns()];
// for (int i = 0; i < checked.length; i++)
// for (int j = 0; j < checked[0].length; j++)
// checked[i][j] = false;
// return floodCheck(checked, pos, targetPos, b);
return true;
}

public boolean floodCheck(boolean[][] checked, Coordinates pos, Coordinates targetPos, Grid g)
{
g.setFloorColor(pos, GrameUtils.randomColor());
if (pos.equals(targetPos))
return true;
checked[pos.getY()][pos.getX()] = true;
for (Coordinates sur : pos.getSurrounding(g))
if (!checked[sur.getY()][sur.getX()])
return floodCheck(checked, sur, targetPos, g);
return true;
}

@Override
Expand Down Expand Up @@ -247,25 +263,25 @@ public static void main(String[] args)
@Override
public void newGame()
{
Base b = new Base(20, 20);
b.setWraparound(true);
Grid g = new Grid(20, 20);
g.setWraparound(true);
Entity player = new Entity("Player", Color.gray);
Entity monster = new Entity("Monster", Color.red);
b.addGrameObjectLayer(new GrameObjectLayer(b.getColumns(), b.getRows()), 1);
player.makePlayer(1, true, b.ID);
g.addGrameObjectLayer(new GrameObjectLayer(g.getColumns(), g.getRows()), 1);
player.makePlayer(1, true, g.ID);
player.setSpeed(1);
monster.setTarget(player.ID);
AStarPathfindingMovementAI aStar = new AStarPathfindingMovementAI();
monster.addAI(aStar, b.ID);
monster.addAI(aStar, g.ID);
monster.setSpeed(5);
b.addGrameObject(player, new Coordinates(0, 0));
b.addGrameObject(monster, new Coordinates(18, 10), 1);
g.addGrameObject(player, new Coordinates(10, 10));
g.addGrameObject(monster, new Coordinates(18, 10), 1);
for (int i = 1; i <= 10; i++)
new Schematic().load(b, GrameUtils.randomCoordinates(b));
new Schematic().load(g, GrameUtils.randomCoordinates(g));
// Schematic s = new Schematic(1);
// System.out.println(s.toString());
// s.load(b, new Coordinates(10, 10));
RenderManager.render(b.ID, new PlainGridRender());
RenderManager.render(g.ID, new CleanGridRender());
RenderManager.setVisible(true);
aStar.showVisualization = true;
// for (int i = 0; i < b.getColumns(); i++)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.moomoohk.Grame.AI;
package com.moomoohk.Grame.Basics.AI;

import com.moomoohk.Grame.Basics.Dir;
import com.moomoohk.Grame.Basics.Entity;
import com.moomoohk.Grame.Essentials.Base;
import com.moomoohk.Grame.Essentials.Coordinates;
import com.moomoohk.Grame.Essentials.GrameManager;
import com.moomoohk.Grame.Interfaces.GrameObject;
import com.moomoohk.Grame.Interfaces.MovementAI;
import com.moomoohk.Grame.Basics.MovementAI;
import com.moomoohk.Grame.Core.Coordinates;
import com.moomoohk.Grame.Core.GrameManager;
import com.moomoohk.Grame.Core.GrameObject;
import com.moomoohk.Grame.Core.Grid;

/**
* AI that lets the user control {@link GrameObject}s using the keyboard.
Expand All @@ -32,27 +32,27 @@ public PlayerMovementAI(int player)
this.player = player;
}

public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2)
public Coordinates getNext(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2)
{
Dir d = player == 1 ? GrameManager.dir1 : player == 2 ? GrameManager.dir2 : null;
if (d == null)
return pos;
int layer = -1;
for (int i = 0; i < b.getGrameObjectLayers().size(); i++)
if (b.getGrameObjectLayers().get(i).contains(ent1.ID))
for (int i = 0; i < g.getGrameObjectLayers().size(); i++)
if (g.getGrameObjectLayers().get(i).contains(ent1.ID))
layer = i;
if (!b.isInBase(MovementAI.slide(b, pos, d, layer)))
if (b.getWraparound())
return MovementAI.wraparound(b, MovementAI.slide(b, pos, d, layer), d);
if (!g.isInGrid(MovementAI.slide(g, pos, d, layer)))
if (g.getWraparound())
return MovementAI.wraparound(g, MovementAI.slide(g, pos, d, layer), d);
else
return pos;
else
return MovementAI.slide(b, pos, d, layer);
return MovementAI.slide(g, pos, d, layer);
}

public boolean isValid(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2)
public boolean isValid(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2)
{
return ent1.isPlayer(b.ID);
return ent1.isPlayer(g.ID);
}

public boolean isOverride()
Expand Down
Loading

0 comments on commit 3a9a939

Please sign in to comment.