Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jdsl-2.1.1/lib/jdsl.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="/CardGameMaker/lib/commons-lang3-3.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jdsl-2.1.1/lib/jdsl.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
27 changes: 27 additions & 0 deletions Grammars/mariolevel.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#A# S
#N# LEVEL CHUNKS CHUNK GAP X Y WG WBEFORE WAFTER WG PLATFORM W TUBE BOXES BOXTYPE ENEMIES ENEMY ENEMYTYPE H WC DIGIT DOSCINCO NUMBER TRESNUEVE ZEROCINCO UNOOCHO CINCONUEVE
#T# gap platform tube hill cannon_hill tube_hill coin cannon block_coin block_powerup rock_coin rock_empty koopa goompa ( ) , 0 1 2 3 4 5 6 7 8 9 ;
S ::= LEVEL
LEVEL ::= CHUNKS ; ENEMIES
CHUNKS ::= CHUNK ; CHUNK ; CHUNK ; CHUNK ; CHUNK | CHUNK ; CHUNKS
CHUNK ::= gap ( X , Y , WG , WBEFORE , WAFTER ) | platform ( X , Y , W ) | tube ( X , Y , H , WBEFORE , WAFTER ) | hill ( X , Y , W ) | cannon_hill ( X , Y , H , WBEFORE , WAFTER ) | tube_hill ( X , Y , H , WBEFORE , WAFTER ) | coin ( X , Y , WC ) | cannon ( X , Y , H , WBEFORE , WAFTER ) | BOXES
X ::= 1 CINCONUEVE | UNOOCHO DIGIT | 9 ZEROCINCO
Y ::= 1 | 2 | 3
WG ::= 2 | 3 | 4 | 5
W ::= 0 TRESNUEVE | 1 ZEROCINCO
WAFTER ::= DOSCINCO
WBEFORE ::= DOSCINCO
WC ::= DIGIT
H ::= 2 | 3
BOXES ::= BOXTYPE ( X , Y )
BOXTYPE ::= block_coin | block_powerup | rock_coin | rock_empty
ENEMIES ::= ENEMY ; ENEMY ; ENEMY ; ENEMY ; ENEMY | ENEMY ; ENEMIES
ENEMY ::= ENEMYTYPE ( X )
ENEMYTYPE ::= koopa | goompa
NUMBER ::= DIGIT DIGIT
TRESNUEVE ::= 3 | 4 | 5 | 6 | 7 | 8 | 9
ZEROCINCO ::= 0 | 1 | 2 | 3 | 4 | 5
UNOOCHO ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
CINCONUEVE ::= 5 | 6 | 7 | 8 | 9
DOSCINCO ::= 2 | 3 | 4 | 5
DIGIT ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013 aturing

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file removed bin/grammar/Derivation.class
Binary file not shown.
Binary file removed bin/grammar/Element.class
Binary file not shown.
Binary file removed bin/grammar/Elements.class
Binary file not shown.
Binary file removed bin/grammar/Grammar.class
Binary file not shown.
Binary file removed bin/grammar/GrammarException.class
Binary file not shown.
Binary file removed bin/grammar/NonTerminal.class
Binary file not shown.
Binary file removed bin/grammar/Production.class
Binary file not shown.
Binary file removed bin/grammar/Productions.class
Binary file not shown.
Binary file removed bin/grammar/Terminal.class
Binary file not shown.
Binary file removed bin/grammar/util/Trees.class
Binary file not shown.
Binary file removed bin/tests/MutationTest.class
Binary file not shown.
44 changes: 31 additions & 13 deletions src/grammar/Derivation.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ private Tree getMaxRandomDerivation(Tree t, int currentDepth, Element knot, Posi
* root node. */
pos.set("Production", null);
/* e is the Element associated to the node (Position=node). */
pos.set("Element", knot);
/* a copy of the terminal is introduced to let diferent internal values for each instance */
pos.set("Element", new Terminal((Terminal) knot));
}
/* Recursive step */
else{
Expand All @@ -200,7 +201,7 @@ private Tree getMaxRandomDerivation(Tree t, int currentDepth, Element knot, Posi
}

if(cP_aux.isEmpty()){
throw new GrammarException("The NonTerminal " + knot.getSymbol() + " doesnt " + "has a Production associated so that " + "1 + Length(Production)<= " + this.grammar.getAxiom().getDepth());
throw new GrammarException("The NonTerminal " + knot.getSymbol() + " doesnt has a Production associated so that 1 + Length(Production)<= " + this.grammar.getAxiom().getDepth());
}

Random rand = new Random();
Expand Down Expand Up @@ -240,18 +241,9 @@ public Derivation mutate() throws GrammarException {
int pos = rand.nextInt(NT.size());
Position mPoint = NT.get(pos);
Element symbol = ((Element) mPoint.get("Element"));
// System.out.print("Mutation node: "+symbol.getSymbol()+" -> ");
Production prod = (Production) mPoint.get( "Production" );
ArrayList<Element> E = prod.getRight();
// for (Element e:E){
// System.out.print(" "+e.getSymbol());
// }
// System.out.println();

Tree subtree = new NodeTree();
subtree = this.getMaxRandomDerivation( subtree, dCopy.depthBackwards(mPoint)+1, symbol, null );

// System.out.println("New branch: "+new Derivation(grammar, maxDepth, subtree).getWord());
subtree = this.getMaxRandomDerivation( subtree, dCopy.depthBackwards(mPoint), symbol, null );

copy.replaceSubtree(mPoint, subtree);
dCopy.setTree(copy);
Expand Down Expand Up @@ -279,7 +271,7 @@ public String getWord(){
n = (Position) poi.nextObject();
e = (Element)n.get("Element");
if (e instanceof Terminal){
res = res.concat(((Element)n.get("Element")).getSymbol());
res = res.concat(((Element)n.get("Element")).getSymbol() + "");
}
}
}
Expand Down Expand Up @@ -748,6 +740,32 @@ public ArrayList<Position> getNonTerminalNodes() throws GrammarException {
return nodes;
}

/**
*
* As a Derivation is a m-Tree (a Tree where each node has several nodes), the function returns the
* Derivation's terminal nodes from left to right.
*
* @return
* A Collection with the Derivation's nodes.
*
*/
public ArrayList<Terminal> getTerminalNodes() {
ArrayList <Terminal> nodes = new ArrayList<Terminal>();

if(this.derivation != null){
PreOrderIterator poi = new PreOrderIterator(this.derivation);
while(poi.hasNext()){
Position p = (Position) poi.nextObject();
Element e = (Element) p.get("Element");
if (e instanceof Terminal){
nodes.add((Terminal) e);
}
}
}
return nodes;

}


/**
*
Expand Down
38 changes: 37 additions & 1 deletion src/grammar/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class Terminal extends Element {

private Object value;

/**
*
Expand All @@ -23,5 +24,40 @@ public class Terminal extends Element {
public Terminal(int id, String symbol) throws GrammarException{
super(id, symbol);
this.setDepth(0);
this.value = null;
}
}


/**
*
* Constructor that receives a terminal to get copied.
*
* @param terminal
* An instance of terminal.
*
**/
public Terminal(Terminal terminal) throws GrammarException{
super(terminal.getId(), terminal.getSymbol());
this.setDepth(0);
this.value = null;
}

/**
* Set value object
*
* @param object
* value of the termninal
*
*/
public void value(Object value) { this.value = value; }


/**
* get value object
*
* @return object
* value of the terminal
*
*/
public Object value() { return this.value; }
}
56 changes: 0 additions & 56 deletions src/tests/MutationTest.java

This file was deleted.