PageRenderTime 41ms CodeModel.GetById 38ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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