SICStus Prolog - 避免重做

时间:2014-10-20 08:34:32

标签: prolog

我正试图在prolog中做一个修改版的跳棋。我的主要周期是:

run(Board, Player) :- write('RUNNING BOARD 1'),nl,
                  canStillPlay(Board, Player),
                 % printBoard(Board),
                  printPlayerTurn(Player),
                  getStartPositions(Player, Board, StartPositions),
                  write('Starting Positions'), nl,
                  write(StartPositions), nl,
                  write('Select Start Position'), nl, nl,
                  read(StartX-StartY),
                  checkValidStartPosition(StartX-StartY, StartPositions),
                 % getEndingPositions(Player, Board, EndingPositions).
                 % write('Ending Positions'), nl,
                 % write('Select Move Position'), nl,
                 % read(EndX-EndY),
                 % checkValidEndingPosition(EndX-EndY, EndingPositions)
                 % movePawn(Board, NewBoard, StartPosition, MovePosition, MovementType, Player),
                  nextTurn(Player, NewPlayer), nl,
                  run(Board, NewPlayer).

run(Board, Player) :- write('RUNNING BOARD 2'), nl,
                  canStillPlay(Board, Player),
                  write('Reselect a pawn'), nl,
                  run(Board, Player).

run(Board,Player) :- write('RUNNING BOARD 3'), nl,
                 Player, !,
                 printBoard(Board),
                 write('White WON').

run(Board,_Player) :- write('RUNNING BOARD 4'), nl,
                  printBoard(Board),
                  write('Black WON').

当我选择无效位置时,它会重做getStartPositions,而不是仅仅继续下一次运行(Board,Player)。我在这里读到另一个问题,它是“编译器优化,给定的编译器/版本组合可能有也可能没有。”

我怎样才能避免重做?如果我试图剪切它,它只是以no。

结束程序

0 个答案:

没有答案