Skip to content
Snippets Groups Projects
Commit aebfcb07 authored by Yingjian Wang's avatar Yingjian Wang
Browse files

Add new file

parent 6a94cfb2
No related branches found
No related tags found
No related merge requests found
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;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment