diff options
Diffstat (limited to 'board.cpp')
-rw-r--r-- | board.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/board.cpp b/board.cpp new file mode 100644 index 0000000..b11ecad --- /dev/null +++ b/board.cpp @@ -0,0 +1,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(); + } +}; |