summaryrefslogtreecommitdiff
path: root/heap.h
blob: 7aabfb0b79cb418c2a76074b27775339ae4b790f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Spider-Arachnid: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: heap.h 2 2005-05-14 22:25:56Z tom $
 */

#ifndef VDR_SPIDER_HEAP_H
#define VDR_SPIDER_HEAP_H

#include "spider.h"
class Card;
typedef Vector<Card> CardStack;
class Deck;
class Pile;
typedef Array<Pile*> Piles;


/** --- base class Heap ---------------------------------------------------- **/

class Heap
{
protected:
  CardStack allCards;
  unsigned int maxCount;
  bool emptyChanged;

  /** Constructor */
  Heap(unsigned int maxCards);

  /** Destructor */
  virtual ~Heap();

public:

  /** Current count of cards */
  int count() const;

  /** Card in heap */
  const Card& card(int position) const;

  /** Top card of the heap */
  const Card& top() const;

  /** Add a new card */
  virtual void add(const Card& card);

  /** Remove the top card */
  virtual void remove();

  /** Move some matching cards to an other heap */
  void moveTo(Heap* other, int countToMove);

  /** Is the heap empty? */
  bool empty() const;

  /** Is the heap changed? */
  bool changed() const;

  /** Reset changed property */
  void resetChanged();
};


/** --- class Pack --------------------------------------------------------- **/

class Pack : public Heap
{
public:

  /** Constructor */
  Pack(const Deck& deck);

  /** First initial deal of a game */
  void initialDeal(Piles& piles, int rows, Piles& extra);

  /** Deal one row to the piles */
  void deal(Piles& piles);

  /** Cancel the deal */
  void takeBackDeal(Piles& piles);
};


/** --- class Pile --------------------------------------------------------- **/

class Pile : public Heap
{
protected:
  int currentOpen;
  int currentMatching;
  int currentSelected;
  int currentChanged;

public:

  /** Constructor */
  Pile(const Deck& deck);

  /** Add a new card */
  void add(const Card& card);

  /** Remove top card from pile */
  void remove();

  /** Turn all open top cards or rather open the top card */
  void turn();

  /** Current count of open cards */
  int open() const;

  /** Current count of matching cards */
  int getMatching() const;

  /** The two open top cards are matching */
  bool topCardsMatches() const;

  /** Current count of selected cards */
  int selected() const;

  /** Select up to max matching cards on the end of this pile */
  void select(int max = 0);

  /** Unselect this pile */
  void unselect();

  /** Adapt the selection to match an other pile */
  void adaptSelectionTo(const Pile* other);

  /** Matches the selection to an other pile? */
  bool selectionMatchesTo(const Pile* other, bool matchSuit = false) const;

  /** Is the heap changed? */
  bool changed() const;

  /** Reset changed property */
  void resetChanged();

  /** How many cards are changed? */
  int cardsChanged() const;
};


/** --- class FinalHeap ---------------------------------------------------- **/

class FinalHeap : public Heap
{
private:
  bool bonus;

public:

  /** Constructor */
  FinalHeap(const Deck& deck);

  /** Set bonus of the final heap */
  void setBonus(bool newBonus);

  /** Has this final heap bonus? */
  bool getBonus() const;
};

#endif // VDR_SPIDER_HEAP_H