Check out Balbo's Chess, our featured variant for October, 2024.


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Comments/Ratings for a Single Item

Earlier Reverse Order Later
how do you program a non-capture move[Subject Thread] [Add Response]
wdtr2 wrote on Sat, Jul 20 09:48 AM UTC:
This message is mostly for @fergus 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. This special move is 1 leap backward in the South direction only and it can only be done as a non-capture move. I attempted to program this move, but I can't figure out how to do it. I am hoping someone can help me out. This is my elephant move right now:

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?


🕸Fergus Duniho wrote on Sat, Jul 20 01:35 PM UTC in reply to wdtr2 from 09:48 AM:

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.


Daniel Zacharias wrote on Sat, Jul 20 02:55 PM UTC in reply to wdtr2 from 09:48 AM:

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;

🕸Fergus Duniho wrote on Sat, Jul 20 05:14 PM UTC in reply to Daniel Zacharias from 02:55 PM:

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;

wdtr2 wrote on Fri, Aug 16 12:38 AM UTC in reply to Daniel Zacharias from Sat Jul 20 02:55 PM:

@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.


🕸Fergus Duniho wrote on Fri, Aug 16 04:03 PM UTC in reply to wdtr2 from Sat Jul 20 09:48 AM:

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

Earlier Reverse Order Later

Permalink to the exact comments currently displayed.