Check out Grant Acedrex, our featured variant for April, 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 ]

Single Comment

The Fairychess Include File Tutorial. How to use the fairychess include file to program games for Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Wed, Apr 1, 2020 01:02 PM UTC:

I see three problems with your code.

First, you're misspelling origin.

Second, it looks like you are using some operators incorrectly. Operators always take their operands on the right side. This is not like C or PHP, which lets you put operators between operands. To test for equality, put both values you want to compare on the right side of ==.

Third, try doing it backwards from how you're doing it, because it evaluates everything in reverse order. Place the normal King moves at the end. Just before that, include an and that checks a flag value. Before that, include the moves the King is allowed on its first move.

It's important to bear in mind how the logical operators are designed to break out of the function early if given only one operator instead of two. Compare these two lines:

def King or checkleap #0 #1 1 1 checkleap #0 #1 1 0 ;

def King checkleap #0 #1 1 1 or checkleap #0 #1 1 0;

The first one calls checkleap twice everytime, but the second calls checkleap a second time only if it was not a one space orthogonal move. As I mentioned above, operators always go on the right. The second is not an example of placing a logical operator between two operands. It is an example of a logical operator having a single operator on its right side. When or gets a single true value, it exits the function and returns true. This eliminates the need to evaluate checkleap #0 #1 1 1 when checkleap #0 #1 1 0 has already been evaluated as true.

Likewise, and will exit a function and return false if it gets a single false value. Use this to have your function evaluate the first move of a King only on its first move. Design your function so that it breaks out early if it is not a regular King move and the King has already moved. The way your function is currently designed, it does all the calculations for the King's first move everytime the King moves, and that is wasteful.