/core-src/ApplyMove.h

http://github.com/Quuxplusone/Homeworlds · C Header · 48 lines · 19 code · 7 blank · 22 comment · 0 complexity · 248db374b8aaa4e7a8a397c6bdf52a28 MD5 · raw file

  1. #pragma once
  2. #include "SingleAction.h"
  3. #include "WholeMove.h"
  4. #include "state.h"
  5. /* Note that ApplyMove is a class rather than a namespace so that it can
  6. * be a "friend" of classes WholeMove and SingleAction. */
  7. struct ApplyMove {
  8. enum Result {
  9. SUCCESS,
  10. UNKNOWN_NAME,
  11. DUPLICATE_NAME,
  12. AMBIGUOUS,
  13. IMPOSSIBLE,
  14. SUICIDE,
  15. };
  16. /* If the given "action" is legal to perform from this state, perform it
  17. * and return success, updating "st" in place. If the given action is invalid,
  18. * then return the reason, leaving "st" in an inconsistent state.
  19. * Note that even a losing move (such as catastrophing your own homeworld)
  20. * is considered legal in this context.
  21. */
  22. static Result Single(GameState &st, int attacker, const SingleAction &action);
  23. /* If the given "move" is legal to perform from this state, perform it
  24. * and return success, updating "st" in place. If any part of the given move
  25. * is invalid, then return the reason, leaving "st" in an inconsistent state.
  26. * Note that even a losing move (such as catastrophing your own homeworld)
  27. * is considered legal in this context.
  28. */
  29. static Result Whole(GameState &st, int attacker, const WholeMove &move);
  30. /* Perform the given "move", updating "st" to reflect the new game state.
  31. * If "move" is not a valid move, assert failure.
  32. * Note that even a losing move (such as catastrophing your own homeworld)
  33. * is considered legal in this context.
  34. */
  35. static void or_die(GameState &st, int attacker, const SingleAction &action);
  36. static void or_die(GameState &st, int attacker, const WholeMove &move);
  37. /* Return true if the given "move" is a valid move for "player", starting from
  38. * the game state "st". Otherwise, return false.
  39. */
  40. static bool isValidMove(const GameState &st, int attacker, const WholeMove &move);
  41. };