-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
5,536 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2014 Ivailo Georgiev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CFLAGS=-c -Wall | ||
LDFLAGS= | ||
SOURCES= card.cpp iboard.cpp inotification.cpp abstract_player.cpp settings.cpp \ | ||
game.cpp console_board.cpp console_notification.cpp console_player.cpp \ | ||
computer_player.cpp santase.cpp | ||
OBJECTS=$(SOURCES:.cpp=.o) | ||
EXECUTABLE=csantase | ||
|
||
all: $(SOURCES) $(EXECUTABLE) | ||
|
||
$(EXECUTABLE): $(OBJECTS) | ||
$(CXX) $(LDFLAGS) $(OBJECTS) -o $@ | ||
|
||
.cpp.o: | ||
$(CXX) $(CFLAGS) $< -o $@ | ||
|
||
clean: | ||
rm -rf *.o $(EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include "abstract_player.h" | ||
#include "game.h" | ||
|
||
AbstractPlayer::AbstractPlayer(Game *game, string name) | ||
{ | ||
// cout << "Creating AbstractPlayer" << endl; | ||
this->game = game; | ||
this->name = name; | ||
isChoosing = false; | ||
clearCards(); | ||
} | ||
|
||
AbstractPlayer::~AbstractPlayer() | ||
{ | ||
clearCards(); | ||
// cout << "Destroying AbstractPlayer" << endl; | ||
} | ||
|
||
void AbstractPlayer::clearCards() | ||
{ | ||
cards.clear(); | ||
takenCards.clear(); | ||
pairs.clear(); | ||
} | ||
|
||
string AbstractPlayer::getName() | ||
{ | ||
return name; | ||
} | ||
|
||
void AbstractPlayer::setName(string name) | ||
{ | ||
this->name = name; | ||
} | ||
|
||
vector<Card *> & AbstractPlayer::getCards() | ||
{ | ||
return cards; | ||
} | ||
|
||
vector<Card *> & AbstractPlayer::getTakenCards() | ||
{ | ||
return takenCards; | ||
} | ||
|
||
void AbstractPlayer::setTakenCards(vector<Card *> & takenCards) | ||
{ | ||
this->takenCards = takenCards; | ||
} | ||
|
||
void AbstractPlayer::addCard(Card *card) | ||
{ | ||
cards.push_back(card); | ||
} | ||
|
||
void AbstractPlayer::removeCard(Card *card) | ||
{ | ||
removeItem(cards, card); | ||
} | ||
|
||
void AbstractPlayer::addTakenCard(Card *card) | ||
{ | ||
takenCards.push_back(card); | ||
} | ||
|
||
void AbstractPlayer::addPair(Suits pairSuit) | ||
{ | ||
pairs.push_back(pairSuit); | ||
} | ||
|
||
int AbstractPlayer::getScore() | ||
{ | ||
int score = 0; | ||
for (int i=0; i<takenCards.size(); i++) | ||
{ | ||
Card *card = takenCards.at(i); | ||
if (card) | ||
{ | ||
score += card->getCard(); | ||
} | ||
} | ||
Suits trump = game->getTrump(); | ||
for (int i=0; i<pairs.size(); i++) | ||
{ | ||
Suits suit = pairs.at(i); | ||
if (suit == trump) | ||
{ | ||
score += SCORE_TRUMP_PAIR; | ||
} | ||
else | ||
{ | ||
score += SCORE_PAIR; | ||
} | ||
} | ||
return score; | ||
} | ||
|
||
bool AbstractPlayer::getIsChoosing() | ||
{ | ||
return isChoosing; | ||
} | ||
|
||
void AbstractPlayer::play() | ||
{ | ||
// using current cards | ||
// call game.nextMove(PlayCard) | ||
sort(cards.begin(), cards.end(), cmpCard); | ||
stringstream ss; | ||
ss.str(""); | ||
ss << *this << " is in turn to play."; | ||
if (game) | ||
{ | ||
game->getNotification()->info(ss.str()); | ||
} | ||
if (game && game->getBoard()) | ||
{ | ||
game->getBoard()->print(); | ||
} | ||
} | ||
|
||
ostream & operator<<(ostream & os, AbstractPlayer & player) | ||
{ | ||
os << player.getName(); | ||
return os; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef _ABSTRACT_PLAYER_H | ||
#define _ABSTRACT_PLAYER_H | ||
|
||
#include "common.h" | ||
#include "card.h" | ||
|
||
class Game; | ||
class AbstractPlayer | ||
{ | ||
public: | ||
AbstractPlayer(Game *game, string name); | ||
virtual ~AbstractPlayer(); | ||
void clearCards(); | ||
string getName(); | ||
void setName(string name); | ||
vector <Card *> & getCards(); | ||
vector <Card *> & getTakenCards(); | ||
void setTakenCards(vector<Card *> & takenCards); | ||
void addCard(Card *card); | ||
void removeCard(Card *card); | ||
void addTakenCard(Card *takenCard); | ||
void addPair(Suits pairSuit); | ||
int getScore(); | ||
bool getIsChoosing(); | ||
virtual void play() = 0; | ||
protected: | ||
Game *game; | ||
string name; | ||
vector<Card *> cards; | ||
vector<Card *> takenCards; | ||
vector<Suits> pairs; | ||
bool isChoosing; | ||
}; | ||
ostream & operator<<(ostream & os, AbstractPlayer & player); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "card.h" | ||
|
||
Card::Card(Cards c, Suits s) | ||
{ | ||
// cout << "Constructing Card" << endl; | ||
this->c = c; | ||
this->s = s; | ||
} | ||
|
||
Card::~Card() | ||
{ | ||
// cout << "Destroying Card" << endl; | ||
} | ||
|
||
Cards Card::getCard() | ||
{ | ||
return c; | ||
} | ||
|
||
Suits Card::getSuit() | ||
{ | ||
return s; | ||
} | ||
|
||
ostream & operator<<(ostream & os, Card & card) | ||
{ | ||
Cards c = card.getCard(); | ||
Suits s = card.getSuit(); | ||
|
||
switch (c) | ||
{ | ||
case NINE: | ||
os << "9"; | ||
break; | ||
case JACK: | ||
os << "J"; | ||
break; | ||
case QUEEN: | ||
os << "Q"; | ||
break; | ||
case KING: | ||
os << "K"; | ||
break; | ||
case TEN: | ||
os << "10"; | ||
break; | ||
case ACE: | ||
os << "A"; | ||
break; | ||
default: | ||
os << "(unknown)"; | ||
} | ||
|
||
switch (s) | ||
{ | ||
case CLUB: | ||
os << "\u2663(sp)"; //"\u2667"; | ||
break; | ||
case DIAMOND: | ||
os << "\u2666(ka)"; //"\u2662"; | ||
break; | ||
case HEART: | ||
os << "\u2665(ku)"; //"\u2661"; | ||
break; | ||
case SPADE: | ||
os << "\u2660(pi)"; //"\u2664"; | ||
break; | ||
default: | ||
os << "(unknown)"; | ||
} | ||
|
||
return os; | ||
} | ||
|
||
bool cmpCard(Card *a, Card *b) | ||
{ | ||
Cards ca = a->getCard(); | ||
Suits sa = a->getSuit(); | ||
Cards cb = b->getCard(); | ||
Suits sb = b->getSuit(); | ||
|
||
if (sa == sb) | ||
{ | ||
return ca < cb; | ||
} | ||
else | ||
{ | ||
return sa < sb; | ||
} | ||
} | ||
|
||
bool cmpNoSuit(Card *a, Card *b) | ||
{ | ||
Cards ca = a->getCard(); | ||
Cards cb = b->getCard(); | ||
return ca < cb; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _CARD_H | ||
#define _CARD_H | ||
|
||
#include "common.h" | ||
|
||
class Card | ||
{ | ||
public: | ||
Card(Cards c, Suits s); | ||
virtual ~Card(); | ||
Cards getCard(); | ||
Suits getSuit(); | ||
|
||
private: | ||
Cards c; | ||
Suits s; | ||
}; | ||
ostream & operator<<(ostream & os, Card & card); | ||
|
||
bool cmpCard(Card *a, Card *b); | ||
bool cmpNoSuit(Card *a, Card *b); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef _COMMON_H | ||
#define _COMMON_H | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <algorithm> | ||
#include <sstream> | ||
|
||
#include <cstdlib> | ||
#include <ctime> | ||
|
||
using namespace std; | ||
|
||
#define CARDS_IN_HAND 6 | ||
|
||
#define SCORE_TRUMP_PAIR 40 | ||
#define SCORE_PAIR 20 | ||
#define HALF_SCORE 33 | ||
#define FINAL_SCORE 66 | ||
|
||
enum Suits { CLUB, DIAMOND, HEART, SPADE }; // spatia, karo, kupa, pika | ||
enum Cards { NINE = 0, JACK = 2, QUEEN = 3, KING = 4, TEN = 10, ACE = 11 }; // devet, vale, dama, pop, deset, aso | ||
|
||
// utility | ||
template <typename T> void removeItem(vector<T *> &vect, T *obj) | ||
{ | ||
typename vector<T *>::iterator newEnd = remove(vect.begin(), vect.end(), obj); | ||
vect.erase(newEnd, vect.end()); | ||
} | ||
|
||
template <typename T> void removePos(vector<T> & vect, int pos) | ||
{ | ||
vect.erase(vect.begin() + pos); | ||
} | ||
|
||
template <typename T> void removeAll(vector<T> & v1, vector<T> & v2) | ||
{ | ||
vector<T> diff; | ||
set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), inserter(diff, diff.begin()) ); | ||
v1 = diff; | ||
} | ||
|
||
template <typename T> bool vecContains(vector<T> & vect, T obj) | ||
{ | ||
typename vector<T>::iterator iter = find(vect.begin(), vect.end(), obj); | ||
return (iter != vect.end()); | ||
} | ||
|
||
#endif | ||
|
Oops, something went wrong.