Initial porting to the new component API.
[tagua/yd.git] / src / core / move.cpp
blob0eb7f7b78f0a598d5cb2c7134c75154c6b118ff7
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 #include "move.h"
13 Move::Move()
14 : m_src(Point::invalid())
15 , m_dst(Point::invalid())
16 , m_promotion(0)
17 , m_pool(0)
18 , m_index(-1) { }
20 Move::Move(const Point& src, const Point& dst, IType* promotion)
21 : m_src(src)
22 , m_dst(dst)
23 , m_promotion(promotion)
24 , m_pool(0)
25 , m_index(-1) { }
27 Move::Move(const IColor* pool, int index, const Point& dst)
28 : m_src(Point::invalid())
29 , m_dst(dst)
30 , m_promotion(0)
31 , m_pool(pool)
32 , m_index(index) { }
34 Point Move::src() const { return m_src; }
36 Point Move::dst() const { return m_dst; }
38 Point Move::delta() const { return dst() - src(); }
40 Piece Move::drop() const { return m_drop; }
42 void Move::setDrop(const Piece& piece) { m_drop = piece; }
44 bool Move::isDrop() const { return m_pool != 0 && m_index != -1; }
46 const IColor* Move::pool() const { return m_pool; }
48 int Move::index() const { return m_index; }
50 QString Move::type() const { return m_type; }
52 void Move::setType(const QString& type) { m_type = type; }
54 const IType* Move::promotion() const { return m_promotion; }
56 void Move::setPromotion(const IType* prom) { m_promotion = prom; }
58 bool Move::operator==(const Move& mv) const {
59 if (!TaguaObject::operator==(mv)) return false;
60 if (m_type != mv.m_type) return false;
62 if (m_pool) {
63 return m_pool == mv.m_pool &&
64 m_index == mv.m_index &&
65 m_dst == mv.m_dst &&
66 m_promotion == mv.m_promotion;
68 else {
69 return m_src == mv.m_src &&
70 m_dst == mv.m_dst &&
71 m_promotion == mv.m_promotion;
75 bool Move::operator!=(const Move& mv) const {
76 return !(operator==(mv));