Comments/Ratings for a Single Item
I'm changing the function to include flags, but for now I'm glad it works as far as it does. Trouble is that even with setconst I get that error. I had always written it correctly. I should double check though, maybe something else is wrong.
I think your problem stems from the overly complicated way you are writing your Apothecary_King function due to keeping track of whether the King has moved in a more complicated manner. It should clear up once you change how you keep track of whether the King has already moved and write a simpler function that uses flagged spaces.
While the simplest way of writing your Apothecary_King function will use flagged spaces, this should work using the method you're using now:
def Apothecary_King checkleap #0 #1 1 3 or checkleap #0 #1 1 2 and match rankname #1 1 10 and or var K1stmove == #0 f2 or var k1stmove == #0 f9 or checkleap #0 #1 1 0 or checkleap #0 #1 1 1;
Although the piece being moved will be found on a different space for actual moves and potential moves, the location of the original space remains the same whether the move is actual or potential. So, if the King is moving from its original space, and its 1st move variable is set, then it is on it's first move. Since the available Knight and Camel moves only allow the King to go to the back rank, this function also checks whether the move is to the back rank. This allows it to use checkleap instead of checkaleap, and that avoids the need to test which King is moving on each line.
Unfortuneatly the code you proposed does not work either. It gives false pozitives when displaying (shows all camel and knight moves) but on the other hand, the special 1st time moves are considered wrong when applied. My guess is that then it is a deeper problem as the king is not a ordinary piece and changing it's properties could impact other subroutines in less predictable ways.
I have not changed the code to use flags because yesterday I was a little busy with other things, but I doubt this impacted the overall result, althought a slower speed was to be expected. Thanks for your help Fergus, but it seems that apothecary chess is to difficult for me to program at this time, so I'm considerring taking a break from programming presets.
I was wondering about one line during the night. This should correct it. Note that if you had switched to flags earlier, this line wouldn't even be needed. Keeping things simple makes programming easier.
def Apothecary_King checkleap #0 #1 1 3 or checkleap #0 #1 1 2 and match rankname #1 1 10 and or and var K1stmove == #0 f2 and var k1stmove == #0 f9 or checkleap #0 #1 1 0 or checkleap #0 #1 1 1;
I see from you commenting it out that you've identified this line as the problem that's causing premature checkmate:
set Kpos space moved;
It should be changed to
set Kpos $dest;
The space operator returns the piece on the coordinate given to it, but you want to set Kpos to a coordinate, and $moved is a piece, not a coordinate.
Finally I tried to replace the code that was using a boolean variable with one using flags. I'm not sure how this will change what you provdeded earlier and worked fine while kpos and Kpos were used correctly.
The line "and or f2 f9" should be "and flag #0".
All right. Things are great! Thanks!...
The only thing is that the definition of king is used rather than an apothecary king and then an alias with king. Could this have any problems. Anyway big help for your Help!
Since King is an alias for Apothecary_King, it converts King to Apothecary_King before it searches for a function, subroutine, or description. If it can't find an Apothecary_King subroutine, for example, that's the end of the line, and it will not search for a King subroutine.
Except that your code is based on some earlier code with a bug in it. Compare your code for displaying descriptions with the code in the Chess preset, which is up-to-date and corrected.
I don't understand what you are trying to say.
But I verified checkmates and they work in both apothecary chess modern and apothecary chess classic as I copied the functions to the other game.
I don't understand what you are trying to say.
You said:
The only thing is that the definition of king is used rather than an apothecary king and then an alias with king.
That's a bug. It should show the description for the Apothecary_King. This bug is due to you using older code that is not bug-free. This buggy code is in your Post-Move sections. The Chess preset has up-to-date bugfree code in its Post-Move sections. The bug is in this line:
set desc join #name "-Desc";
This should be:
set desc join realname #name "-Desc";
Is not that post move section?
It is, I misread sorry!...
I have made tests for the all moves and then check and checkmate and things seem ok if we redefine (by overwritting) the king subroutine. These don't work properly if an Apothecary_king function is defined and then use of aliases is made. Is there a reason against leaving things as is, Fergus?
I see in your code that you started using the name King directly instead of as an alias for Apothecary_King. When you do it this way, it calls the King subroutine. This is working out for you, because the King subroutine calls the King function. The subroutine also includes some code for handling castling, but since you have not set wcastle and bcastle, it will recognize any attempt at castling as illegal without needing to call the castle subroutine. So, it basically just uses the function to check the move's legality, and it updates the value of kpos or Kpos to the space the King moved to. What the King subroutine is doing that your code was not doing before is updating kpos or Kpos BEFORE your code checks whether your King has moved into check. Presently, you have the code for updating kpos and Kpos at the very end of your Post-Move sections, but these variables need to be updated before checking whether you have moved into check. So, if you just changed the position of this part of your code, you could use King as an alias for Apothecary_King without any problem.
I had done that and the moves were displayed but I was not able to do them due to the error saying that a king cannot move there.
I have change the code in the setconst area to:
setconst k Apothecary_King;
setconst K Apothecary_King;
and now things work properly as far as I can see.
I don't see why that would make a difference. What move couldn't you make using King as an alias for Apothecary_King?
The 4 initial moves. The ones that the usual king does not have.
This is because you copied old code that was still buggy. When I made a fork and copied in the new code from Chess, it worked fine. The new code is described in detail on this page in the Aliases section.
After thinking about it, I think it makes more sense to assign constants to the names used in the code than it does to assign them to aliases. The alias can be calculated after the real name is returned by const. This allows the same alias to be used for a piece with different functions or subroutines for each side, such as Pawn as an alias for both White_Pawn and Black_Pawn. The way it is currently coded is suited only for using different aliases for different versions of the same piece definition, such as Minister and Elephant for Chinese_Elephant. But this is a bad example, because I have separate functions for the Elephant on each side anyway. So, I think there is more call for using one alias for multiple piece defintions than for using one piece definition with multiple aliases. I will update code and documentation tomorrow.
Using the fairychess-test include file, I updated Chess, Grand Chess, Gross Chess, and Chinese Chess to assign constants to the actual function and subroutine names instead of to aliases. They still make use of aliases for these names, but it is now only for display purposes. I am going to postpone copying the changes to the official fairychess include file to give Greg some time to update Opulent Chess without breaking it in the meantime. I haven't changed the documentation yet, but here is what you can do.
- Include fairychess-test instead of fairychess.
- Assign the constants to the actual function or subroutine names instead of the aliases.
- Add the Pawn alias for White_Pawn and Black_Pawn. (The main benefit of the change is that you can now do this.)
- Replace the if-elseif-else block for checking the legality of moves in each Post-Move section with the following code:
set codename const alias $moved; if sub #codename $origin $dest and issub #codename: elseif fn #codename $origin $dest and isfunc #codename and not issub #codename: else: set name alias #codename; set errmsg list "You may not move your" #name "from" $origin "to" join $dest ".<BR>"; set desc join #codename "-Desc"; set errmsg str_replace "_" " " join #errmsg str_replace "%s" #name var #desc; die #errmsg; endif;
Once I know Opulent Chess is updated, I will copy fairychess-test to fairychess and switch back to including fairychess in my games. Then I'll notify Greg, who can do the same. I'm not going to worry about breaking Apothecary Chess, because that's still a work in progress anyway, but Aurelian should be doing the same things for his games too. This is just a quick how-to. I will update the documentation later.
25 comments displayed
Permalink to the exact comments currently displayed.
Sorry, I made a couple typos. The last two lines should be:
setconst k King;
setconst K King;
Also, you still haven't followed my advice about keeping track of the King's first move the same way this is already done for Chess. If you did, your Apothecary_King function would be much simpler to write.