OK, great. That means all all issues encountered so far are solved now, and we are ready to continue. First a summary of where we are, because I was too optimistic in declaring phase 0 finished. The code shown befor turned out only to work for simple moves; Game Courier does not like it when you try to evaluate a composit move by putting "MOVE:" in front of it, and will complain the move is malformed in that case. So it is necessary to explode composit moves into an array mvs of simple moves, and have Game Courier perform these one by one in a loop. This exploding of moves had to be done anyway for parsing the move, but it is now done before we call ParseMove, and mvs is made a global variable, so that it will also be available inside ParseMove:
sub HandleMove player:
set mvs explode chr 59 thismove; // split at semicolons
gosub ParseMove #player; // syntax check and interpretation
set k 0;
do while < var k count var mvs: // for all legs
eval join "MOVE: " trim elem var k var mvs; // apply the move
inc k;
loop;
endsub;
For phase 0 the call to Parsemove would not yet be there. The tested and debugged code for phase 1 is:
sub ParseMove player:
my i j parts sqrs;
set many suicide false freedrop false promo false;
set parts explode ws trim elem 0 var mvs; // split first move at space
set i count var parts;
if > var i 2: // too many parts
die "move must be piece ID plus board step";
endif;
set sqrs explode chr 45 trim elem dec var i var parts; // split last part at hyphen
if != 2 count var sqrs: // must give 2 squares
die "board step does not mention two squares";
endif;
set ori elem 0 var sqrs; // first is origin
set desti elem 1 var sqrs; // second is dest
if not onboard var ori or not onboard var desti: // check if these are valid
die "the board isn't that large";
endif;
set mover space var ori; // look what we move
if != var mover elem 0 var parts and == 1 var i: // input move mentioned another piece
die "there is another piece there";
endif;
if not cond #player islower var mover isupper var mover: // it is not our piece
die "no such piece there";
endif;
set j 1; // prepare to do side effects
do while < var j count var mvs: // for each of those
set parts explode chr 45 trim elem var j var mvs; // split them at hyphen
if != 2 count var parts: // must give 2 parts
die "malformed move " elem var j var mvs;
elseif not onboard elem 1 var parts: // second part must be valid square
die "second leg goes off board";
elseif onboard elem 0 var parts: // additional move for locust capture
if != var desti elem 0 var parts: // must start from destination of first move
die "you can only continue with same piece";
endif;
if #suicide: // for now only one side efect
die "cannot have more than one locust victim";
endif;
set suicide var desti; // old dest was actually locust square
set desti elem 1 var parts;
elseif == var desti elem 1 var parts: // drop on dest: promotion
set promo elem 0 var parts;
elseif == @ elem 0 var parts: // drop of empty: locust square
if #suicide:
die "cannot have more than one locust victim";
endif;
set suicide elem 1 var parts;
else: // drop of piece: unload
if #freedrop:
die "cannot kick more than one piece";
endif;
set dropped elem 0 var parts;
set freedrop elem 1 var parts;
endif;
inc j; // go on with next side effect
loop;
endsub;
This extracts values for ori, desti, mover, promo, suicide, freedrop and dropped from the move. The first three from the (mandatory) first move. The others describe the optionally following moves of the turn, and are set to 0 by default. These values are not yet used in phase 1; the only observable effect is that the preset will now enforce turn order, as it no longer accepts moving of opponent pieces. It still accepts capture of own pieces, as XBetza can allow that. So this must be left for move generator to check out.
Next step is to take care of implied side effects: it should be possible (even mandatory) to enter castling and e.p. capture as a simple move. In phase 2 we will do this for castling. Phase 3 will then address e.p. capture, which is more complex, because it also has to address the creation of e.p. rights.
OK, great. That means all all issues encountered so far are solved now, and we are ready to continue. First a summary of where we are, because I was too optimistic in declaring phase 0 finished. The code shown befor turned out only to work for simple moves; Game Courier does not like it when you try to evaluate a composit move by putting "MOVE:" in front of it, and will complain the move is malformed in that case. So it is necessary to explode composit moves into an array mvs of simple moves, and have Game Courier perform these one by one in a loop. This exploding of moves had to be done anyway for parsing the move, but it is now done before we call ParseMove, and mvs is made a global variable, so that it will also be available inside ParseMove:
For phase 0 the call to Parsemove would not yet be there. The tested and debugged code for phase 1 is:
This extracts values for ori, desti, mover, promo, suicide, freedrop and dropped from the move. The first three from the (mandatory) first move. The others describe the optionally following moves of the turn, and are set to 0 by default. These values are not yet used in phase 1; the only observable effect is that the preset will now enforce turn order, as it no longer accepts moving of opponent pieces. It still accepts capture of own pieces, as XBetza can allow that. So this must be left for move generator to check out.
Next step is to take care of implied side effects: it should be possible (even mandatory) to enter castling and e.p. capture as a simple move. In phase 2 we will do this for castling. Phase 3 will then address e.p. capture, which is more complex, because it also has to address the creation of e.p. rights.