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
|
/*
* Copyright (C) 2016 Olivier Gayot <olivier.gayot@sigexec.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "board.h"
namespace cao {
board::board(const cards::deck &black_deck, const cards::deck &white_deck)
: _black_decks(black_deck, cards::deck()),
_white_decks(white_deck, cards::deck()),
_black_pick(&_black_decks.first), _white_pick(&_white_decks.first),
_black_recycl(&_black_decks.second), _white_recycl(&_white_decks.second),
_flop(), _current_black_card(NULL)
{
_black_pick->shuffle();
_white_pick->shuffle();
}
void board::reveal_black_card()
{
/*
* if we do not have enough cards in the pick, then we exchange the
* decks with the recycling deck.
*/
if (_black_pick->empty())
{
cards::deck *d = _black_pick;
_black_pick = _black_recycl;
_black_recycl = d;
_black_pick->shuffle();
}
_current_black_card = _black_pick->pick();
}
void board::recycle_black_card()
{
_black_recycl->push_front(_current_black_card);
_current_black_card = NULL;
}
const cards::card *board::pick_white_card()
{
if (_white_pick->empty())
{
cards::deck *d = _white_pick;
_white_pick = _white_recycl;
_white_recycl = d;
_white_pick->shuffle();
}
return _white_pick->pick();
}
void board::play_card(const cards::card *card, player *p)
{
std::pair<const cards::card *, player *> pair;
pair.first = card;
pair.second = p;
_flop.push_back(pair);
}
void board::shuffle_flop()
{
_flop.shuffle();
}
void board::recycle_flop()
{
for (cards::flop::const_iterator it = _flop.begin();
it != _flop.end(); ++it)
{
const cards::card *card = (*it).first;
_white_recycl->push_front(card);
}
_flop.clear();
}
};
|