Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
UpdatedHanoi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yingjian Wang
UpdatedHanoi
Commits
d3d9a1aa
Commit
d3d9a1aa
authored
3 years ago
by
Yingjian Wang
Browse files
Options
Downloads
Patches
Plain Diff
Update Move.jadd
parent
2c771235
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/jastadd/hanoi/Move.jadd
+152
-137
152 additions, 137 deletions
src/main/jastadd/hanoi/Move.jadd
with
152 additions
and
137 deletions
src/main/jastadd/hanoi/Move.jadd
+
152
−
137
View file @
d3d9a1aa
import java.util.*;
aspect Move{
aspect Connectives{
public boolean Constraint.oddTurnMove(Pillar P0, Pillar P1){
uncache Connective.eval();
/*for every odd turn(turn==true), move the smallest disk D0 in sequence. |-----------Right:DisksOnPillar(P0)
syn boolean Connective.eval();
Therefore, ValidTarget checks for a move from P0 to P1, when D0 is on the top of P0. |------If():ComparFunction()------Left:ConstantNumM0(0)
eq Conjunction.eval(){
Conjunction()-------------hasSmallestDisk()---------R0()-----------------F0()----------------|------Then():P0TopDiskSize()
return this.getLeft().eval() && this.getRight().eval();
| TopDiskSizeEq1 IfThenElse |------Else():ConstantNumM1(-1)
}
| |
eq Disjunction.eval(){
| |----------ConstantNum1(1)
return this.getLeft().eval() || this.getRight().eval();
|---ValidTarget()---------R1()---------P1.ID()
}
P1EqTarget
eq Implication.eval(){
|
return (!this.getLeft().eval()) || this.getRight().eval();
|-----Mod0()------Left:Plus0()------Left:Plus1()------Left:Mod1()------TotalDiskAmount();
}
| | | |------------ConstantNum2(2)
eq Negation.eval()= !getConnective().eval();
| | |--------ConstantNum1(1)
eq Atom.eval(){
| |------P0.ID
return this.getRelation().eval();
|------ConstantNum3(3)*/
}
Conjunction ValidMove=new Conjunction();
uncache Relation.eval();
syn boolean Relation.eval();
Atom hasSmallestDisk=new Atom();//if the smallest disk is on this pillar
eq Subsetof.eval(){
Equal TopDiskSizeEq1= new Equal();
Set left=new HashSet<>();
IfThenElse TopDiskChecher=new IfThenElse();
for(String element : this.getLeft().Set()){
CompareFunction PillarHasDisk=new CompareFunction();
left.add(element);
TopDiskSize P0TopDiskSize=new TopDiskSize();
}
ConstantNum NumM1=new ConstantNum();
Set right=new HashSet<>();
ConstantNum Num1=new ConstantNum();
for(String element : this.getRight().Set()){
ConstantNum Num0=new ConstantNum();
right.add(element);
DisksOnPillar DisksOnP0=new DisksOnPillar();
}
return right.containsAll(left);
Atom ValidTarget=new Atom();//check if the move sequence from P0 to P1 is valid
}
Equal P1EqTarget= new Equal();
eq Compare.eval(){
PillarID P1ID=new PillarID();
return (this.getLeft().eval() - this.getRight().eval())<0;
Mod Mod0=new Mod();
}
Mod Mod1=new Mod();
eq Equal.eval(){
Plus Plus0=new Plus();
return this.getLeft().eval() - this.getRight().eval()==0;
Plus Plus1=new Plus();
}
TotalDiskAmount DisksOverall=new TotalDiskAmount();
uncache Term.eval();
PillarID P0ID=new PillarID();
syn int Term.eval();
ConstantNum Num2=new ConstantNum();
eq Plus.eval(){
ConstantNum Num3=new ConstantNum();
return this.getLeft().eval() + this.getRight().eval();
}
ValidMove.setLeft(hasSmallestDisk);
eq Minus.eval(){
ValidMove.setRight(ValidTarget);
return this.getLeft().eval() - this.getRight().eval();
}
NumM1.setNum(-1);
eq Multi.eval(){
Num0.setNum(0);
return this.getLeft().eval() * this.getRight().eval();
Num1.setNum(1);
}
Num2.setNum(2);
eq Divide.eval(){
Num3.setNum(3);
return this.getLeft().eval() / this.getRight().eval();
}
TopDiskSizeEq1.setLeft(TopDiskChecher);
eq Mod.eval(){
TopDiskChecher.setIf(PillarHasDisk);
return this.getLeft().eval() % this.getRight().eval();
PillarHasDisk.setLeft(Num0);
}
PillarHasDisk.setRight(DisksOnP0);
eq IfThenElse.eval(){
DisksOnP0.setRel(P0);
if(this.getIf().Satisfied()){
TopDiskChecher.setThen(P0TopDiskSize);
return this.getThen().eval();
P0TopDiskSize.setRel(P0);
}
TopDiskChecher.setElse(NumM1);
return this.getElse().eval();
TopDiskSizeEq1.setRight(Num1);
}
hasSmallestDisk.setRelation(TopDiskSizeEq1);
eq CompareFunction.eval(){
if(this.getLeft().eval() < this.getRight().eval()){
ValidTarget.setRelation(P1EqTarget);
return 1;
P1EqTarget.setLeft(P1ID);
}
P1ID.setRel(P1);
return 0;
P1EqTarget.setRight(Mod0);
}
Mod0.setLeft(Plus0);
eq EqualFunction.eval(){
Mod0.setRight(Num3);
if(this.getLeft().eval() == this.getRight().eval()){
Plus0.setLeft(Plus1);
return 1;
Plus0.setRight(P0ID);
}
P0ID.setRel(P0);
return 0;
Plus1.setLeft(Mod1);
}
Plus1.setRight(Num1);
eq SubsetofFunction.eval(){
Mod1.setLeft(DisksOverall);
Set left=new HashSet<>();
DisksOverall.setRel(P0);
for(String element : this.getLeft().Set()){
Mod1.setRight(Num2);
left.add(element);
}
this.addConnective(ValidMove);
Set right=new HashSet<>();
if(this.getConnective(0).eval()){
for(String element : this.getRight().Set()){
System.out.println("Odd turn: P" + P0.ID() +".hahasSmallestDisk0 && (P" + P0.ID() +".target == P" + P1.ID()+")");
right.add(element);
return true;//odd turn and valid move
}
if(right.containsAll(left)){
return 1;
}
return 0;
}
eq ConstantNum.eval(){
return this.getNum();
}
eq PillarID.eval(){
return this.getRel().ID();
}
eq TotalDiskAmount.eval(){
return this.getRel().AmountD();
}
eq DisksOnPillar.eval(){
return this.getRel().getNumDisk();
}
eq TopDiskSize.eval(){
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
}
//customerized terms
eq Term1.eval(){//return the size of top disk
if(this.getRel().getNumDisk()>0){
//if the pillar is not empty, check if the top disk has size 1
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
}else{
}else{
return -1;//no disk, the number is invalid, return -1
return false;
}
}
}
}
eq Term2.eval(){
public boolean Constraint.evenTurnMove(Pillar P0, Pillar P1){
return this.getRel().moveSeq();
/*for every even turn(turn==false), move the disk D on top of P0 to P1:
}
D is not D0(the smallest disk).
eq Term3.eval(){
There is always one D can be moved in the even turn according to the game rules.
return this.getRel().ID();
Statements:
}
1.P0 is not empty: not OND().
uncache Condition.Satisfied();
2.When condition 1 holds, P1 can be empty: TND().
syn boolean Condition.Satisfied();
3.When 1 holds and 2 doesn’t hold, D0 < D1(for the disks on the top of P0 and P1 respectively).
eq CompareFunction.Satisfied(){
Therefore, we want not OND() and (TND() or ValidTarget()) to be true.
return this.getLeft().eval() < this.getRight().eval();
|-----------hasSmallestDisk()-----------------R0---------------T0()
}
C1 |C3 |----------------T3()
eq EqualFunction.Satisfied(){
Conjunction()-------------Negation()------Disjunction()----OND()----------------R1()----------------T0()
return this.getLeft().eval() == this.getRight().eval();
C0 | |----------------T2()
}
|---Disjunction()-----------TND()--------------R2()---------T1()
eq SubsetofFunction.Satisfied(){
|C2 |-----------T2()
Set left=new HashSet<>();
|------------------ValidTarget()-----------------R3()---------T0()
for(String element : this.getLeft().Set()){
|---------T1*/
left.add(element);
Conjunction C0=new Conjunction();
}
Negation C1=new Negation();
Set right=new HashSet<>();
Disjunction C2=new Disjunction();
for(String element : this.getRight().Set()){
Disjunction C3=new Disjunction();
right.add(element);
Atom hasSmallestDisk=new Atom();//if the smallest disk is on this pillar
}
Atom OND=new Atom();//origin has no disk
return right.containsAll(left);
Atom TND=new Atom();//target has no disk
}
Atom ValidTarget=new Atom();//check the size, if the disk on the top of origin has smaller size than the one on target
public String[] Term.Set(){
String[] str=new String[]{};
C0.setLeft(C1);
return str;
C0.setRight(C2);
}
C1.setConnective(C3);
}
C2.setLeft(TND);
C2.setRight(ValidTarget);
C3.setLeft(hasSmallestDisk);
C3.setRight(OND);
Term1 T0=new Term1();//return size of top disk, return -1 when no disk.
Term1 T1=new Term1();
ConstantNum T2=new ConstantNum();
ConstantNum T3=new ConstantNum();
T0.setRel(P0);
T1.setRel(P1);
T2.setNum(0);
T3.setNum(1);
Equal R0=new Equal();
Compare R1=new Compare();
Compare R2=new Compare();
Compare R3=new Compare();
R0.setLeft(T0);
R0.setRight(T3);
R1.setLeft(T0);
R1.setRight(T2);
R2.setLeft(T1);
R2.setRight(T2);
R3.setLeft(T0);
R3.setRight(T1);
hasSmallestDisk.setRelation(R0);
OND.setRelation(R1);
TND.setRelation(R2);
ValidTarget.setRelation(R3);
this.addConnective(C0);
if(this.getConnective(0).eval()){
System.out.println("Even turn: !(P" + P0.ID() +".#disk == 0 || P" + P0.ID() +".hahasSmallestDisk0) && (P" + P1.ID() +".#disk == 0 || P" + P0.ID() +".topDisk < P" + P1.ID() +".topDisk)");
return true;//even turn and valid move
}
return false;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment