Comments/Ratings for a Single Item
For potential moves, you need to check whether the space is empty, and for actual moves you need to check whether a capture has been made. See my code for the Cannon for an example of how to do this.
Does this work?
def White_Elephant checkleap #0 #1 2 2 or and checkaleap #0 #1 0 -1 empty where #0 0 -1;
def White_Elephant-Range mergeall leaps #0 2 2 where #0 0 -1;
def Black_Elephant checkleap #0 #1 2 2 or and checkaleap #0 #1 0 1 empty where #0 0 1;
def Black_Elephant-Range mergeall leaps #0 2 2 where #0 0 1;
No, this may work for potential moves, but it will not work for actual moves. I believe you should replace "empty where #0 0 -1" with "cond empty #0 capture empty #1". Also, the function would be better optimized for most legal moves, as well as for testing for check on the King, if you reversed its two parts. This will also allow you to use breaking logic all the way through.
def White_Elephant checkaleap #0 #1 0 -1 and cond empty #0 capture empty #1 or checkleap #0 #1 2 2;
def Black_Elephant checkaleap #0 #1 0 1 and cond empty #0 capture empty #1 or checkleap #0 #1 2 2;
@arx, I think I tried that, and it did not work. I'm putting the code down for a while, so I don't get frustrated.
The elephant to me is a diagonal mover. It may leap 1 or two squares. I want to make a variant of the elephant that has the ability to change its diagonal color (checkered board). The changing of color is a special move.
I think the original suggestions I gave were mistaken.
def White_Elephant checkaleap #0 #1 0 -1 and cond empty #0 capture empty #1 or checkleap #0 #1 2 2;
def White_Elephant checkaleap #0 #1 0 -1 and cond empty #0 not capture empty #1 or checkleap #0 #1 2 2 or checkleap #0 #1 1 1;
def Black_Elephant checkaleap #0 #1 0 1 and cond empty #0 capture empty #1 or checkleap #0 #1 2 2;
def Black_Elephant checkaleap #0 #1 0 1 and cond empty #0 not capture empty #1 or checkleap #0 #1 2 2 or checkleap #0 #1 1 1;
So each one first checks whether the move is a diagonal leap of one or two spaces. If it is not, it checks the condition "cond empty #0 not capture empty #1". If the origin space is empty, it is checking an actual move. So it checks whether a capture has already been made. If the origin space is not empty, it is checking a potential move. So it checks whether the destination space is still empty. If it turns out to be a capturing move, the function immediately returns false. Otherwise, it evaluates whether it is a one-space move vertically backwards.
6 comments displayed
Permalink to the exact comments currently displayed.
def White_Elephant checkleap #0 #1 2 2 or checkleap #0 #1 1 1 ; def White_Elephant-Range mergeall leaps #0 2 2 leaps #0 1 1 leap #0 0 1;
set White_Elephant-Desc "The %s may leap two spaces in any diagonal direction, or go backwards 1 space if the space is empty.";
def Black_Elephant checkleap #0 #1 2 2 or checkleap #0 #1 1 1; def Black_Elephant-Range merge leaps #0 2 2 leaps #0 1 1; set Black_Elephant-Desc "The Elephant may leap two spaces in any diagonal direction, and may move one space backward if the square is empty.";
*** What do I need to do to make a non-capture move that is 1 square south?