new 33c0e9569b8825f53d773343cc90e4377118edca
[tagua/yd.git] / src / core / validator.h
blob1cb357b90e70edacdc21e5c0604085b32d6bda78
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef CORE__VALIDATOR_H
12 #define CORE__VALIDATOR_H
14 #include "piece.h"
15 #include "point.h"
17 class IState;
18 class Move;
20 /**
21 * @brief A component to check legality of moves.
23 class TAGUA_EXPORT IValidator {
24 public:
25 virtual ~IValidator();
27 /**
28 * A move is pseudolegal if it obeys all rules
29 * except those regarding king safety.
30 * @returns Whether the given move is pseudolegal.
32 virtual bool pseudolegal(const IState* state, Move& move) const = 0;
34 /**
35 * A move if legal if it obeys all the rules of the game.
36 * @returns Whether the given move is legal.
38 virtual bool legal(const IState* state, Move& move) const = 0;
40 /**
41 * Check if some piece of @a player attacks the piece @a target
42 * on the given square.
43 * If the @a target parameter is not given, whatever piece is in
44 * the specified square is considered the target.
45 * @param state The reference state of the game.
46 * @param player The attacking player.
47 * @param square The destination square of the attack.
48 * @param target An optional piece to be considered as the target for the attack.
50 virtual bool attacks(const IState* state, const IColor* player,
51 const Point& square, const Piece& target = Piece()) const = 0;
53 /**
54 * @return The owner of the moving piece.
56 virtual const IColor* mover(const IState* state, const Move& move) const = 0;
58 virtual void setDelegator(IValidator* delegator) = 0;
61 #endif // CORE__VALIDATOR_H