Comments/Ratings for a Single Item
I'm confused about what you want to say. Isn't it that : and cond empty #0 capture isupper space #1; does exactly that, capture for actual moves, and isupper space #1 checks for a potential victim in potential moves? Where am I wrong?
That's not the issue. The issue is that and has only one value. With only one value, it is a breaking and, which means that it will immediately exit the function and return false if the value it receives is false. See the "Breaking Logic" section in the tutorial on the fairychess include file for details.
I'm confused about what you want to say. Isn't it that : and cond empty #0 capture isupper space #1; does exactly that, capture for actual moves, and isupper space #1 checks for a potential victim in potential moves? Where am I wrong?
The first thing it does is require that the move is a capture. If it is not a capture, it will not proceed any further.
I have corrected the post move code to:
if != const alias $moved White_Joker:
if != const alias $moved White_Pawn:
set last_type_moved const alias $moved;
else:
set last_type_moved Black_Barren_Pawn;
endif;
endif;
and similar for black. This code works.
But the Barren_Pawn worked fine when I had done only the move part of the pawn's powers but now I have added the capture part and nothing is legal anymore. Please help if you may! The code in question is:
def Black_Barren_Pawn
checkaleap #0 #1 0 -1 and cond empty #0 not capture empty #1
or checkleap #0 #1 -1 -1 or checkleap #0 #1 1 -1
and cond empty #0 capture isupper space #1;
It doesn't work, because you are testing the codename of the piece, but Pawn is not the codename for any piece. It is the display name for the pieces with the codenames of Black_Pawn and White_Pawn.
Is that minus sign in Pawn-Range intended, or is it a typo for an underscore?
It's a hyphen, not a minus sign, and it is not a typo.
Is that minus sign in Pawn-Range intended, or is it a typo for an underscore?
@Fergus
A few weeks ago I have figured out that the joker imitates the pawn in all things which causes the joker moves to not be allowed.
To tackle this issue I have decided to write a Barren_Pawn function that the joker will use when imitating a pawn instead of imitating the regular pawn function. Otherwise things are unchanged. The Barren_Pawn functions are:
def White_Barren_Pawn checkaleap #0 #1 1 0 and empty #1 islower space #1 and or checkaleap #0 #1 1 -1 checkaleap #0 #1 1 1;
def White_Barren_Pawn-Range merge leaps #0 1 0 leaps #0 1 1;
def Black_Barren_Pawn checkaleap #0 #1 -1 0 and empty #1 isupper space #1 and or checkaleap #0 #1 -1 -1 checkaleap #0 #1 -1 1;
def Black_Barren_Pawn-Range merge leaps #0 1 0 leaps #0 1 1;
The piece of code involving the joker imitation is:
if != const alias $moved White_Joker:
if != const alias $moved Pawn:
set last_type_moved const alias $moved;
else:
set last_type_moved White_Barren_Pawn;
endif;
endif;
and for black:
if != const alias $moved Black_Joker:
if != const alias $moved Pawn:
set last_type_moved const alias $moved;
else:
set last_type_moved Black_Barren_Pawn;
endif;
endif;
I thought it should easily work. Unfortunately it does not. Any idea why that is?
Ok, thanks for the heads up. I'll try to think at something else.
I wouldn't recommend that. That doesn't sound like the correct solution to your problem.
@Fergus
The way I had thought the game, the joker should, when imitating a pawn, get only the regular power and not promotion rights or double move privileges. And that works best with moving some of the lines in the pawn function to the pawn subroutine. It should be rather easy.
Since it works for displaying legal moves, it's probably because the Pawn functions are only for potential moves, and the Joker is trying to use one of the Pawn functions when making an actual move. Specifically, I think it fails on the line "and empty #1" in the Pawn function, because that space is occupied for an actual move. Some options include changing your rules, rewriting the Pawn functions to handle both potential and actual moves, or using a Joker subroutine for actual moves, which would let you undo the Joker's move before testing it with a function, then redoing it if it is legal.
@Fergus,
I have unfortunately uncovered another bug on the preset for this game.
The joker can't move when imitating a pawn, although the moves are properly displayed. Any idea why?
@ Fergus,
I have found the mistake.
This piece of code was missing and adding it has solved the problem.
if == moved K:
unsetflag f2;
set Kpos $dest;
endif;
It still gives the error: "you may not move into check".
I didn't say to get rid of the else clause. I said to get rid of the else. Just the else. A single line of code.
The new sub looks like this:
sub Apothecary_King from to:
if checkleap #from #to 1 1 or checkleap #from #to 1 0:
return true;
endif;
move #to #from;
if checkleap #from #to 1 3
or checkleap #from #to 1 2
and match rankname #to 1 10
and flag #from :
if not sub checked #from:
move #from #to;
return true;
else die You may not perform the special moves out of check.;
endif;
endif;
return false;
endsub;
When trying to use regular moves out of check, I get the error "you cannot move into check.". This happens with or without the else part.
Also, add "return false;" to the very end of the subroutine.
The function looks fine. In the subroutine, you should remove the else.
I have made the distinction between the function and the subroutine. But I still could not make work as expected.
def Apothecary_King
checkleap #0 #1 1 3
or checkleap #0 #1 1 2
and not sub checked #0
and match rankname #1 1 10
and flag #0
or checkleap #0 #1 1 0
or checkleap #0 #1 1 1;
sub Apothecary_King from to:
if checkleap #from #to 1 1 or checkleap #from #to 1 0:
return true;
endif;
move #to #from;
if checkleap #from #to 1 3
or checkleap #from #to 1 2
and match rankname #to 1 10
and flag #from :
if sub checked #from:
die You may not perform the special moves out of check.;
endif;
else:
move #from #to;
return true;
endif;
endsub;
$origin should not be included in the function definition. It may be used as an argument when calling a function or subroutine, but it should not be included in the definition of one. You should check the flag before calling the checked subroutine, because that will minimize the use of the subroutine. The same goes for checking the rank of the destination. Always do less expensive operations before more expensive operations, because that will minimize the need to do the most expensive operations.
You are saying the the checked subroutine must be used inside the function?
Like that:
def Apothecary_King
checkleap #0 #1 1 3
or checkleap #0 #1 1 2
and match rankname #1 1 10
and flag #0
and not sub checked $origin
or checkleap #0 #1 1 0
or checkleap #0 #1 1 1;
because this does not work.
The subroutine should undo the King's move before checking whether it is in check. If the move is legal, then it should redo it. The function does not need to undo and redo the King's move, but it should make sure the King is not in check before allowing the special moves. Also, each should handle the regular moves before checking whether the King is in check. Your current subroutine is very wasteful, because it will check whether the King is in check every single time.
I have separated the 2 codes but never are the special moves availeble. I'm not sure about what to do!
25 comments displayed
Permalink to the exact comments currently displayed.
I have corrected the mistake and now it goes like this:
def White_Barren_Pawn
checkaleap #0 #1 0 1 and cond empty #0 not capture empty #1
or and checkaleap #0 #1 -1 1 or checkaleap #0 #1 1 1
cond empty #0 capture islower space #1;
def White_Barren_Pawn-Range merge leaps #0 1 0 leaps #0 1 1;
def Black_Barren_Pawn
checkaleap #0 #1 0 -1 and cond empty #0 not capture empty #1
or and checkaleap #0 #1 -1 -1 or checkaleap #0 #1 1 -1
cond empty #0 capture isupper space #1;
But during my tests I came across the fact that a joker imitating a barren_pawn does not have the ability to capture another joker (although it is fine when capturing a knight).