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

Update CanMove.jrag

parent 615b1403
No related branches found
No related tags found
No related merge requests found
aspect CanMove {
uncache Disk.smallerThan(Disk D);
syn boolean Disk.smallerThan(Disk D) {
if(this.getSize() < D.getSize()){
return true;
}
return false;
}
/*for odd turns, the smallest disk D0 is supposed to move in a certain sequence
to eventually move all the disks from P0 to P2.
Pillar.moveseq() return the integer who demonstrates the target pillar according to the sequence.
the sequence is 0 2 1... when the amount of disks is odd and 0 1 2... when even.*/
uncache Pillar.moveSeq();
inh int Pillar.moveSeq();
eq Hanoi.getPillar(int i).moveSeq(){
if(this.getAmountD()%2 == 1){
return (i+2)%3;
}else{
return (i+1)%3;
}
}
uncache Pillar.ID();
inh int Pillar.ID();
eq Hanoi.getPillar(int i).ID(){
return i;
}
}
\ No newline at end of file
aspect Info {
uncache Disk.smallerThan(Disk D);
syn boolean Disk.smallerThan(Disk D) {
if(this.getSize() < D.getSize()){
return true;
}
return false;
}
/*for odd turns, the smallest disk D0 is supposed to move in a certain sequence
to eventually move all the disks from P0 to P2.
Pillar.moveseq() return the integer who demonstrates the target pillar according to the sequence.
the sequence is 0 2 1... when the amount of disks is odd and 0 1 2... when even.*/
uncache Pillar.moveSeq();
inh int Pillar.moveSeq();
eq Hanoi.getPillar(int i).moveSeq(){
if(this.getAmountD()%2 == 1){
return (i+2)%3;
}else{
return (i+1)%3;
}
}
uncache Pillar.AmountD();
inh int Pillar.AmountD();
eq Hanoi.getPillar(int i).AmountD(){
return this.getAmountD();
}
uncache Pillar.ID();
inh int Pillar.ID();
eq Hanoi.getPillar(int i).ID(){
return i;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment