Untitled

 avatar
unknown
plain_text
4 years ago
8.4 kB
8
Indexable
#include "function.h"
#include <cstdlib>

Player::Player(string name, int m, int ski) : Human(this->name, this->money, this->skill) // checked
{
    
}

Human::Human(string n, int m, int ski) // checked
{
    this->name = n;
    this->money = m;
    this->skill = ski;
}

void Human::Draw()
{ // checked
    this->cards = 0;
    string res = "";
    while (res.size() <= 0)
        getline(cin, res);
    stringstream ss(res);
    while (ss >> res)
    {
        int temp = 0;
        for (auto i : res)
            temp = temp * 10 + i - '0';
        this->cards += temp;
    }
    //    cout << cards << endl;
}

Banker::~Banker()
{
}

Human::~Human()
{
}
Casino::Casino() // checked
{
    int ind;

    this->banker = new Human("Banker", 0, 0);
    this->server = new Human("Server", 0, 0);
    this->guard = new Human("guard", 0, 0);
    this->player_num = 0;
    this->blacklist_num = 0;
    this->today_income = 0;
    this->total_income = 0;
/*    for (ind = 0; ind < 1009; ind++)
    {
        this->player[ind] = NULL;
    //    this->blacklist[ind] = "\0";
    }
    for (ind = 0; ind < 100009; ind++)
        this->blacklist[ind] = "\0";
*/
}

Casino::~Casino()
{
}

void Casino::Enterance(int f, int u) // checked
{
    this->today_income = 0;
    this->fee = f;
    this->U = u;
}

void Casino::Guest(string s, int m, int ski) // checked
{
    int i;

    for (i = 0; i < this->player_num; i++)
    {
        if (this->player[i]->name == s)
            return;
    }

    for (i = 0; i < this->blacklist_num; i++)
    {
        if (this->blacklist[i] == s)
            return;
    }

    if (m <= this->fee)
    {
        this->blacklist[this->blacklist_num++] = s;
        return;
    }
    else
    {
        this->player[this->player_num++] = new Human(s, m, ski);
        this->player[this->player_num - 1]->money -= this->fee;
        this->today_income += this->fee;
    }
}

Guard::Guard(int ski) : Human("Guard", 0, ski)
{
}

Banker::Banker(int ski) : Human("Banker", 0, ski)
{
}

Server::Server(int ski) : Human("Server", 0, ski)
{
}

void Player::Bet()
{
}

void Player::Pay(Human *human)
{
}

void Banker::Pay(Human *human)
{
}

int Banker::Win(Human *human)
{
    return 1;
}

void Casino::TwentyOne()    // checked
{
    int bank_ski, guard_ski, ser_ski;
    int num;
    int card_tmp;
    string name;
    Player* eat;
    int bet;
    int seq[100100];
    int ind = 0;
    int flag;
    int total = 0;

    cin >> bank_ski >> guard_ski >> ser_ski;

    this->banker = new Human("banker", 0, bank_ski);
    this->guard = new Human("guard", 0, guard_ski);
    this->server = new Human("server", 0, ser_ski);

    cin >> num;

    for (int i = 0; i < 100100; i++)
        seq[i] = 0;

    for (int i = 0; i < num; i++)
    {
        cin >> name;
        cin >> bet;
    //    std::cout << "Here\n";
        eat = new Player(name, 0, 0);

        eat->bets = bet;
        eat->Draw();
        flag = 0;
        for (int j = 0; j < this->blacklist_num; j++) // find whether player is blacklisted
        {
            if (blacklist[j] == name)
            {
                flag = 1;
                break;
            }
        }

        if (flag == 1) {
            continue;
        }

        for (int j = 0; j < this->player_num; j++)
        { 
            if (this->player[j]->name == name)    // if player is in casino
            {
                seq[j] = 1; 
                this->player[j]->bets = eat->bets;
                this->player[j]->cards = eat->cards;
                break;
            }
        }
    }

    this->banker->Draw();
  

   
    for (int ind = 0; ind < 100100; ind++)
    {
        if (seq[ind] == 1)
        {
            if ((this->player[ind]->cards <= 21 && this->banker->cards > 21) || (this->player[ind]->cards <= 21 && this->banker->cards < player[ind]->cards)) // player wins
            {
        //        std::cout << "player " << this->player[ind]->name << endl;
                int bonus = 0;

                if (this->player[ind]->skill < this->banker->skill)
                {
                    bonus = 10 * this->player[ind]->cards;

                    if (this->player[ind]->cards == 21)
                    {
                        this->banker->money -= 2 * (bonus + this->player[ind]->bets);
                        this->player[ind]->money += 2 * (bonus + this->player[ind]->bets);
                        total = 2 * (bonus + this->player[ind]->bets);
                    }
                    else
                    {
                        this->banker->money -= bonus;
                        this->player[ind]->money += bonus;
                        this->banker->money -= this->player[ind]->bets;
                        this->player[ind]->money += this->player[ind]->bets;
                        total = this->player[ind]->bets + bonus;
                    }
                }
                else
                {
                    if (this->player[ind]->cards == 21)
                    {
                        this->banker->money -= 2 * this->player[ind]->bets;
                        this->player[ind]->money += 2 * this->player[ind]->bets;
                        total = 2 * this->player[ind]->bets;
                    }
                    else
                    {
                        this->banker->money -= this->player[ind]->bets;
                        this->player[ind]->money += this->player[ind]->bets;
                        total = this->player[ind]->bets;
                    }
                }
                

                if (this->player[ind]->money > this->server->skill)
                {
                    this->banker->money += 2000;
                    this->server->money += 1000;
                    this->player[ind]->money -= 3000;
                }

                if (3 * this->player[ind]->skill < total)
                {
                    this->blacklist[this->blacklist_num++] = this->player[ind]->name;
                    this->banker->money -= 100;
                    this->guard->money += 100;

                    if (this->guard->skill < this->player[ind]->skill)
                    {
                        this->guard->money -= (this->player[ind]->skill - this->guard->skill);
                        this->player[ind]->money += (this->player[ind]->skill - this->guard->skill);
                    }
                }
            }
            else if ((this->banker->cards <= 21 && this->player[ind]->cards > 21) || (this->banker->cards <= 21 && this->player[ind]->cards <= this->banker->cards))
            {
                if (this->player[ind]->money <= this->player[ind]->bets)
                {
                    this->banker->money += this->player[ind]->money;
                    this->player[ind]->money = 0;
                    this->banker->money -= 100;
                    this->guard->money += 100;
                    this->blacklist[this->blacklist_num++] = this->player[ind]->name;
                }
                else
                {
                    this->banker->money += this->player[ind]->bets;
                    this->player[ind]->money -= this->player[ind]->bets;
                }
            }
        }
    }   

    cout << this->banker->money << ' ' << this->guard->money << ' ' << this->server->money << endl;

    this->today_income += this->banker->money;

    for (int i = 0; i < 100100; i++)
    {
        if (seq[i] == 1)
            cout << this->player[i]->name << ' ' << this->player[i]->money << endl;
    }
       
}

bool Player::Cheat(Human *human)
{
    return true;
}

void Casino::EndDay()
{
    this->total_income += this->today_income;
    if (this->today_income >= this->U)
    {
    //    for (int i = 0; i < blacklist_num; i++)
    //        this->blacklist[i] = "\0";
        this->blacklist_num = 0;
    }
/*    for (int i = 0; i < this->player_num; i++)
    {
        if (this->player[i] != NULL)
        {
            delete(this->player[i]);
            this->player[i] = NULL;
        }
    }
*/
    this->player_num = 0;
}

void Casino::Result()
{
    cout << this->total_income << endl;
    for (int i = 0; i < this->blacklist_num; i++)
    {
    //    if (this->blacklist[i] != "\0")
        cout << blacklist[i] << endl;
    }
}

void Player::Order(Human *banker, Human *server)
{
}

bool Player::Bankrupt()
{
    return true;
}

void Guard::Pay(Human *human)
{
}

Server::~Server()
{
}
Editor is loading...