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
aebfcb07
Commit
aebfcb07
authored
3 years ago
by
Yingjian Wang
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
6a94cfb2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/jastadd/hanoi/MoveAlter.jadd
+64
-0
64 additions, 0 deletions
src/main/jastadd/hanoi/MoveAlter.jadd
with
64 additions
and
0 deletions
src/main/jastadd/hanoi/MoveAlter.jadd
0 → 100644
+
64
−
0
View file @
aebfcb07
aspect MoveAlter{
public boolean Constraint.oddTurnMoveAlter(Pillar P0, Pillar P1){
/*for every odd turn(turn==true), move the smallest disk D0 in sequence. |-----------Right:DisksOnPillar(P0)
Therefore, ValidTarget checks for a move from P0 to P1, when D0 is on the top of P0. |------If():ComparFunction()------Left:ConstantNumM0(0)
Conjunction()-------------hasSmallestDisk()---------R0()-----------------F0()----------------|------Then():P0TopDiskSize()
| TopDiskSizeEq1 IfThenElse |------Else():ConstantNumM1(-1)
| |
| |----------ConstantNum1(1)
|---ValidTarget()---------R1()---------P1.ID()
P1EqTarget
|
|-----Mod0()------Left:Plus0()------Left:Plus1()------Left:Mod1()------TotalDiskAmount();
| | | |------------ConstantNum2(2)
| | |--------ConstantNum1(1)
| |------P0.ID
|------ConstantNum3(3)*/
TopDiskSize P0TopDiskSize=new TopDiskSize(P0);
ConstantNum NumM1=new ConstantNum(-1);
ConstantNum Num1=new ConstantNum(1);
ConstantNum Num0=new ConstantNum(0);
ConstantNum Num2=new ConstantNum(2);
ConstantNum Num3=new ConstantNum(3);
DisksOnPillar DisksOnP0=new DisksOnPillar(P0);
PillarID P0ID=new PillarID(P0);
PillarID P1ID=new PillarID(P1);
TotalDiskAmount DisksOverall=new TotalDiskAmount(P0);//return the number of disks set at the beginning
CompareFunction PillarHasDisk=new CompareFunction(Num0, DisksOnP0);
IfThenElse TopDiskChecher=new IfThenElse(PillarHasDisk, P0TopDiskSize, NumM1);//if the origin pillar
// is not emapty
//return the size of its top disk
//else return -1 means no such disk
Equal TopDiskSizeEq1= new Equal(TopDiskChecher, Num1);//the size of the disk on the top equals 1,
//indicates this is the smallest disk
Atom hasSmallestDisk=new Atom(TopDiskSizeEq1);//if the smallest disk is on this pillar
Mod Mod1=new Mod(DisksOverall, Num2);//check if we have odd or even disks in the game
Plus Plus1=new Plus(Mod1, Num1);//a intermediat parameter for calculating the target pillar in an odd turn
Plus Plus0=new Plus(Plus1, P0ID);//a parameter for calculating the target pillar in an odd turn
Mod Mod0=new Mod(Plus0, Num3);//calculating the target pillar in an odd turn
Equal P1EqTarget= new Equal(P1ID, Mod0);
Atom ValidTarget=new Atom(P1EqTarget);//check if the move sequence from P0 to P1 is valid
Conjunction ValidMove=new Conjunction(hasSmallestDisk, ValidTarget);
this.addConnective(ValidMove);
if(this.getConnective(0).eval()){
System.out.println("Odd turn: P" + P0.ID() +".hahasSmallestDisk0 && (P" + P0.ID() +".target == P" + P1.ID()+")");
return true;//odd turn and valid move
}else{
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